/////////////////////////////////////////////////////////////////////////
//
//  TCB procedures
//
/////////////////////////////////////////////////////////////////////////
ExTupleFlowTcb::ExTupleFlowTcb(const ExTupleFlowTdb &  tuple_flow_tdb, 
			       const ex_tcb & src_tcb,    // src queue pair
			       const ex_tcb & tgt_tcb,    // tgt queue pair
			       ex_globals *glob
                         ) : ex_tcb( tuple_flow_tdb, 1, glob)
{
  CollHeap * space = glob->getSpace();
  
  // LCOV_EXCL_START
  // Allocate the buffer pool, if tgtExpr_ is present
  if (tuple_flow_tdb.tgtExpr_)
#pragma nowarn(1506)   // warning elimination 
    pool_ = new(glob->getSpace()) sql_buffer_pool(tuple_flow_tdb.numBuffers_,
						  tuple_flow_tdb.bufferSize_,
						  glob->getSpace());
#pragma warn(1506)  // warning elimination 
  // LCOV_EXCL_STOP
  
  tcbSrc_ = &src_tcb;
  tcbTgt_ = &tgt_tcb;

  // get the queues that src and tgt use to communicate with me
  qSrc_  = src_tcb.getParentQueue();
  qTgt_  = tgt_tcb.getParentQueue();

  ex_cri_desc * from_parent_cri = tuple_flow_tdb.criDescDown_;  
  ex_cri_desc * to_parent_cri   = tuple_flow_tdb.criDescUp_;

  // Allocate the queue to communicate with parent
  qParent_.down = new(space) ex_queue(ex_queue::DOWN_QUEUE,
				      tuple_flow_tdb.queueSizeDown_,
				      from_parent_cri,
				      space);

  // source atps will be copied to target atps. Allocate
  // target atps.
  qTgt_.down->allocateAtps(space);
  
  // Allocate the private state in each entry of the down queue
  ExTupleFlowPrivateState *p =
    new(space) ExTupleFlowPrivateState(this);
  qParent_.down->allocatePstate(p, this);
  delete p;

  qParent_.up = new(space) ex_queue(ex_queue::UP_QUEUE,
				    tuple_flow_tdb.queueSizeUp_,
				    to_parent_cri,
				    space);

  // LCOV_EXCL_START  
  // fixup expressions
  if (tflowTdb().tgtExpr_)
    (void) tflowTdb().tgtExpr_->fixup(0, getExpressionMode(), this,
  				      glob->getSpace(), glob->getDefaultHeap(), FALSE, glob);
  // LCOV_EXCL_STOP
    
}
示例#2
0
//
// Constructor for sort_grby_tcb
//
ex_sort_grby_tcb::ex_sort_grby_tcb(const ex_sort_grby_tdb &  sort_grby_tdb, 
				   const ex_tcb &    child_tcb,   // child queue pair
				   ex_globals * glob
				    ) : 
    ex_tcb( sort_grby_tdb, 1, glob),
    pool_(NULL)
{
  Space * space = (glob ? glob->getSpace() : 0);
  CollHeap * heap = (glob ? glob->getDefaultHeap() : 0);
  
  childTcb_ = &child_tcb;

  // Allocate the buffer pool
#pragma nowarn(1506)   // warning elimination 
  pool_ = new(space) ExSimpleSQLBuffer(sort_grby_tdb.numBuffers_,
				       sort_grby_tdb.bufferSize_,
		                       recLen(),
				       space);
#pragma warn(1506)  // warning elimination 

  // get the child queue pair
  qchild_  = child_tcb.getParentQueue(); 

  // Allocate the queue to communicate with parent
  allocateParentQueues(qparent_);

  // Intialize processedInputs_ to the next request to process
  processedInputs_ = qparent_.down->getTailIndex();

  // allocate work atp
  workAtp_ = allocateAtp(sort_grby_tdb.criDescUp_,getSpace());

  // fixup aggr expression
  if (aggrExpr())
    (void) aggrExpr()->fixup(0, getExpressionMode(), this, space, heap,
			     glob->computeSpace());

  // fixup move expression
  if (moveExpr())
    (void) moveExpr()->fixup(0, getExpressionMode(), this, space, heap,
			     glob->computeSpace());

  // fixup grby expression
  if (grbyExpr())
    (void) grbyExpr()->fixup(0, getExpressionMode(), this, space, heap,
			     glob->computeSpace());

  // fixup having expression
  if (havingExpr())
    (void) havingExpr()->fixup(0, getExpressionMode(), this, space, heap,
			       glob->computeSpace());

}
//
// Constructor for firstn_tcb
//
ExFirstNTcb::ExFirstNTcb(const ExFirstNTdb & firstn_tdb, 
			 const ex_tcb & child_tcb,    // child queue pair
			 ex_globals *glob
			 ) : ex_tcb( firstn_tdb, 1, glob),
                             step_(INITIAL_)
{
  childTcb_ = &child_tcb;
  
  Space * space = glob->getSpace();
  CollHeap * heap = (glob ? glob->getDefaultHeap() : NULL);
  
  // Allocate the buffer pool
#pragma nowarn(1506)   // warning elimination 
  pool_ = new(space) sql_buffer_pool(firstn_tdb.numBuffers_,
				     firstn_tdb.bufferSize_,
				     space);
#pragma warn(1506)  // warning elimination 
  
  // get the queue that child use to communicate with me
  qchild_  = child_tcb.getParentQueue(); 
  
  // Allocate the queue to communicate with parent
  qparent_.down = new(space) ex_queue(ex_queue::DOWN_QUEUE,
				      firstn_tdb.queueSizeDown_,
				      firstn_tdb.criDescDown_,
				      space);
  
  // Allocate the private state in each entry of the down queue
  ExFirstNPrivateState p(this);
  qparent_.down->allocatePstate(&p, this);

  qparent_.up = new(space) ex_queue(ex_queue::UP_QUEUE,
				    firstn_tdb.queueSizeUp_,
				    firstn_tdb.criDescUp_,
				    space);

  workAtp_ = NULL;
  firstNParamVal_ = 0;
  if (firstn_tdb.workCriDesc_)
    {
      workAtp_ = allocateAtp(firstn_tdb.workCriDesc_, space);
      pool_->get_free_tuple(workAtp_->getTupp(firstn_tdb.workCriDesc_->noTuples()-1), 0);
      workAtp_->getTupp(firstn_tdb.workCriDesc_->noTuples()-1).
        setDataPointer((char*)&firstNParamVal_);
    }

  if (firstn_tdb.firstNRowsExpr_)
    {
      firstn_tdb.firstNRowsExpr_->fixup(0, getExpressionMode(), this,  space, heap, 
                                        FALSE, glob);
     }
};
示例#4
0
// ExSampleTcb constructor
//
// 1. Allocate buffer pool.
// 2. Allocate parent queues and initialize private state.
// 3. Fixup expressions.
//
ExSampleTcb::ExSampleTcb
(const ExSampleTdb &  myTdb, 
 const ex_tcb &    child_tcb,
 ex_globals * glob
 ) : 
  ex_tcb(myTdb, 1, glob)
{
  Space * space = (glob ? glob->getSpace() : 0);
  CollHeap * heap = (glob ? glob->getDefaultHeap() : 0);
  
  childTcb_ = &child_tcb;

   // get the queue that child use to communicate with me
  qchild_  = child_tcb.getParentQueue(); 

  // Allocate the queue to communicate with parent
  qparent_.down = new(space) ex_queue(ex_queue::DOWN_QUEUE,
							myTdb.queueSizeDown_,
				     myTdb.criDescDown_,
				     space);
  
  // Allocate the private state in each entry of the down queue
  ExSamplePrivateState *p 
    = new(space) ExSamplePrivateState(this);
  qparent_.down->allocatePstate(p, this);
  delete p;


  qparent_.up = new(space) ex_queue(ex_queue::UP_QUEUE,
				    myTdb.queueSizeUp_,
				    myTdb.criDescUp_,
				    space);

  // Intialized processedInputs_ to the next request to process
  processedInputs_ = qparent_.down->getTailIndex();

  // Fixup the sample expression
  //
  if (initExpr())
    initExpr()->fixup(0, getExpressionMode(), this, space, heap, FALSE, glob);

  if (balanceExpr())
    balanceExpr()->fixup(0, getExpressionMode(), this, space, heap, FALSE, glob);

  if (postPred())
    postPred()->fixup(0, getExpressionMode(), this, space, heap, FALSE, glob);
}
// ExSequenceTcb constructor
//
// 1. Allocate buffer pool.
// 2. Allocate parent queues and initialize private state.
// 3. Fixup expressions.
//
ExSequenceTcb::ExSequenceTcb (const ExSequenceTdb &  myTdb, 
                              const ex_tcb &    child_tcb,
                              ex_globals * glob) : 
  ex_tcb(myTdb, 1, glob),
  lastRow_(NULL),
  clusterDb_(NULL),
  cluster_(NULL),
  ioEventHandler_(NULL),
  OLAPBuffersFlushed_(FALSE),
  firstOLAPBuffer_(NULL),
  lastOLAPBuffer_(NULL),
  rc_(EXE_OK),
  olapBufferSize_(0),
  maxNumberOfOLAPBuffers_(0),
  numberOfOLAPBuffers_(0),
  minNumberOfOLAPBuffers_(0),
  memoryPressureDetected_(FALSE)
{

  Space * space = (glob ? glob->getSpace() : 0);
  CollHeap * heap = (glob ? glob->getDefaultHeap() : 0);
  heap_ = heap;

  childTcb_ = &child_tcb;

  // Allocate the buffer pool
#pragma nowarn(1506)   // warning elimination 
  pool_ = new(space) sql_buffer_pool(myTdb.numBuffers_,
    myTdb.bufferSize_,
    space);

  allocRowLength_ = ROUND8(myTdb.recLen_);

#pragma warn(1506)  // warning elimination 

  // Initialize the machinery for maintaining the row history for
  // computing sequence functions.
  //

  maxNumberHistoryRows_ = myTdb.maxHistoryRows_;
  minFollowing_ = myTdb.minFollowing_;
  unboundedFollowing_ = myTdb.isUnboundedFollowing();
  maxNumberOfOLAPBuffers_ = myTdb.maxNumberOfOLAPBuffers_;//testing
  olapBufferSize_ = myTdb.OLAPBufferSize_ ;
  maxRowsInOLAPBuffer_ = myTdb.maxRowsInOLAPBuffer_;
  minNumberOfOLAPBuffers_ = myTdb.minNumberOfOLAPBuffers_;
  numberOfWinOLAPBuffers_ = myTdb.numberOfWinOLAPBuffers_;
  overflowEnabled_ = ! myTdb.isNoOverflow();

  ex_assert( maxNumberOfOLAPBuffers_ >= minNumberOfOLAPBuffers_ ,
	     "maxNumberOfOLAPBuffers is too small");

  // Initialize history parameters
  // For unbounded following -- also create/initialize clusterDb, cluster
  initializeHistory();

  // get the queue that child use to communicate with me
  qchild_  = child_tcb.getParentQueue(); 

  // Allocate the queue to communicate with parent
  qparent_.down = new(space) ex_queue(ex_queue::DOWN_QUEUE,
    myTdb.initialQueueSizeDown_,
    myTdb.criDescDown_,
    space);

  // Allocate the private state in each entry of the down queue
  ExSequencePrivateState *p 
    = new(space) ExSequencePrivateState(this);
  qparent_.down->allocatePstate(p, this);
  delete p;

  qparent_.up = new(space) ex_queue(ex_queue::UP_QUEUE,
    myTdb.initialQueueSizeUp_,
    myTdb.criDescUp_,
    space);

  // Intialized processedInputs_ to the next request to process
  processedInputs_ = qparent_.down->getTailIndex();


  workAtp_ = allocateAtp(myTdb.criDescUp_, space);

  // Fixup the sequence function expression. This requires the standard
  // expression fixup plus initializing the GetRow method for the sequence
  // clauses.
  //
  if (sequenceExpr())
  {
    ((ExpSequenceExpression*)sequenceExpr())->seqFixup
      ((void*)this, GetHistoryRow, GetHistoryRowOLAP);
    sequenceExpr()->fixup(0, getExpressionMode(), this, space, heap_, FALSE, glob);
  }

  if (returnExpr())
  {
    ((ExpSequenceExpression*)returnExpr())->seqFixup
      ((void*)this, GetHistoryRow, GetHistoryRowFollowingOLAP);
    returnExpr()->fixup(0, getExpressionMode(), this, space, heap_, FALSE, glob);
  }

  if (postPred())
    postPred()->fixup(0, getExpressionMode(), this, space, heap_, FALSE, glob);


  if (cancelExpr())
    cancelExpr()->fixup(0, getExpressionMode(), this, space, heap_, FALSE, glob);

  if (checkPartitionChangeExpr())
  {
    ((ExpSequenceExpression*)checkPartitionChangeExpr())->seqFixup
      ((void*)this, GetHistoryRow, GetHistoryRowOLAP);
    checkPartitionChangeExpr()->fixup(0, getExpressionMode(), this, space, heap_, FALSE, glob);
  }
}
ExFastExtractTcb::ExFastExtractTcb(
    const ExFastExtractTdb &fteTdb,
    const ex_tcb & childTcb,
    ex_globals *glob)
  : ex_tcb(fteTdb, 1, glob),
    workAtp_(NULL),
    outputPool_(NULL),
    inputPool_(NULL),
    childTcb_(&childTcb)
  , inSqlBuffer_(NULL)
  , childOutputTD_(NULL)
  , sourceFieldsConvIndex_(NULL)
  , currBuffer_(NULL)
  , bufferAllocFailuresCount_(0)
  , modTS_(-1)
{
  
  ex_globals *stmtGlobals = getGlobals();

  Space *globSpace = getSpace();
  CollHeap *globHeap = getHeap();

  heap_ = globHeap;

  //convert to non constant to access the members.
  ExFastExtractTdb *mytdb = (ExFastExtractTdb*)&fteTdb;
  numBuffers_ = mytdb->getNumIOBuffers();

  // Allocate queues to communicate with parent
  allocateParentQueues(qParent_);

  // get the queue that child use to communicate with me
  qChild_  = childTcb.getParentQueue();
    
  // Allocate the work ATP
  if (myTdb().getWorkCriDesc())
    workAtp_ = allocateAtp(myTdb().getWorkCriDesc(), globSpace);

  // Fixup expressions
  // NOT USED in M9
  /*
  if (myTdb().getInputExpression())
    myTdb().getInputExpression()->fixup(0, getExpressionMode(), this,
                                       globSpace, globHeap);

  if (myTdb().getOutputExpression())
    myTdb().getOutputExpression()->fixup(0, getExpressionMode(), this,
                                        globSpace, globHeap);
  */

  if (myTdb().getChildDataExpr())
    myTdb().getChildDataExpr()->fixup(0,getExpressionMode(),this,
                                       globSpace, globHeap, FALSE, glob);


  //maybe we can move the below few line to the init section od work methods??
  UInt32 numAttrs = myTdb().getChildTuple()->numAttrs();

   sourceFieldsConvIndex_ = (int *)((NAHeap *)heap_)->allocateAlignedHeapMemory((UInt32)(sizeof(int) * numAttrs), 512, FALSE);

  maxExtractRowLength_ = ROUND8(myTdb().getChildDataRowLen()) ;

  const ULng32 sqlBufferSize = maxExtractRowLength_ +
                               ROUND8(sizeof(SqlBufferNormal)) +
                               sizeof(tupp_descriptor) +
                               16 ;//just in case

  inSqlBuffer_ = (SqlBuffer *) new (heap_) char[sqlBufferSize];
  inSqlBuffer_->driveInit(sqlBufferSize, TRUE, SqlBuffer::NORMAL_);
  childOutputTD_ = inSqlBuffer_->add_tuple_desc(maxExtractRowLength_);

  endOfData_ = FALSE;

} // ExFastExtractTcb::ExFastExtractTcb
ExProbeCacheTcb::ExProbeCacheTcb(const ExProbeCacheTdb &probeCacheTdb, 
				   const ex_tcb &child_tcb,
				   ex_globals * glob
				    ) : 
    ex_tcb( probeCacheTdb, 1, glob),
    childTcb_(NULL),
    workAtp_(NULL),
    probeBytes_(NULL),
    pool_(NULL),
    pcm_(NULL),
    workUpTask_(NULL)
{
  Space * space = (glob ? glob->getSpace() : 0);
  CollHeap * heap = (glob ? glob->getDefaultHeap() : 0);

  qparent_.up = qparent_.down = NULL;
  
  childTcb_ = &child_tcb;

  // Allocate the buffer pool
  pool_ = new(space) ExSimpleSQLBuffer( probeCacheTdb.numInnerTuples_,
                                        probeCacheTdb.recLen_,
                                        space);

  // get the child queue pair
  qchild_  = child_tcb.getParentQueue(); 

  // Allocate the queue to communicate with parent
  allocateParentQueues(qparent_);

  // Intialize nextRequest_ to the next request to process
  nextRequest_ = qparent_.down->getTailIndex();

  // Allocate buffer for probeBytes_.
  probeBytes_ = new(space) char[ probeCacheTdb.probeLen_ ];

  // allocate work atp and initialize the two tupps.
  workAtp_ = allocateAtp(probeCacheTdb.criDescUp_,getSpace());

  probeHashTupp_.init(sizeof(probeHashVal_),
		    NULL,
		    (char *) (&probeHashVal_));
  workAtp_->getTupp(probeCacheTdb.hashValIdx_) = &probeHashTupp_;

  hashProbeExpr()->fixup(0, getExpressionMode(), this, space, heap,
                glob->computeSpace(), glob);

  probeEncodeTupp_.init(probeCacheTdb.probeLen_,
		    NULL,
		    (char *) (probeBytes_));
  workAtp_->getTupp(probeCacheTdb.encodedProbeDataIdx_) = &probeEncodeTupp_;

  encodeProbeExpr()->fixup(0, getExpressionMode(), this, space, heap,
                glob->computeSpace(), glob);

  if (moveInnerExpr())
    moveInnerExpr()->fixup(0, getExpressionMode(), this, space, heap,
                glob->computeSpace(), glob);

  if (selectPred())
    selectPred()->fixup(0, getExpressionMode(), this, space, heap,
                glob->computeSpace(), glob);

  pcm_ = new(space) ExPCMgr(space, 
                probeCacheTdb.cacheSize_, probeCacheTdb.probeLen_, this);

}