fix: choose heap sort for table merge scan when row size is big and has limit
This commit is contained in:
		
							parent
							
								
									1d24b96e82
								
							
						
					
					
						commit
						a205eba2ab
					
				| 
						 | 
				
			
			@ -2837,15 +2837,23 @@ int32_t startGroupTableMergeScan(SOperatorInfo* pOperator) {
 | 
			
		|||
  int32_t tableStartIdx = pInfo->tableStartIndex;
 | 
			
		||||
  int32_t tableEndIdx = pInfo->tableEndIndex;
 | 
			
		||||
 | 
			
		||||
  bool hasLimit = pInfo->limitInfo.limit.limit != -1 || pInfo->limitInfo.limit.offset != -1;
 | 
			
		||||
  int64_t mergeLimit = -1;
 | 
			
		||||
  if (hasLimit) {
 | 
			
		||||
      mergeLimit = pInfo->limitInfo.limit.limit + pInfo->limitInfo.limit.offset;
 | 
			
		||||
  }
 | 
			
		||||
  size_t szRow = blockDataGetRowSize(pInfo->pResBlock);   
 | 
			
		||||
  if (szRow > 1024 && hasLimit) {
 | 
			
		||||
    pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, SORT_SINGLESOURCE_SORT, -1, -1,
 | 
			
		||||
                                              NULL, pTaskInfo->id.str, mergeLimit, szRow+8, tsPQSortMemThreshold * 1024* 1024);
 | 
			
		||||
  } else {
 | 
			
		||||
    pInfo->sortBufSize = 2048 * pInfo->bufPageSize;
 | 
			
		||||
    int32_t numOfBufPage = pInfo->sortBufSize / pInfo->bufPageSize;
 | 
			
		||||
    pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, SORT_BLOCK_TS_MERGE, pInfo->bufPageSize, numOfBufPage,
 | 
			
		||||
                                              pInfo->pSortInputBlock, pTaskInfo->id.str, 0, 0, 0);
 | 
			
		||||
  int64_t mergeLimit = -1;
 | 
			
		||||
  if (pInfo->limitInfo.limit.limit != -1 || pInfo->limitInfo.limit.offset != -1) {
 | 
			
		||||
    mergeLimit = pInfo->limitInfo.limit.limit + pInfo->limitInfo.limit.offset;
 | 
			
		||||
  }                                             
 | 
			
		||||
                                          
 | 
			
		||||
    tsortSetMergeLimit(pInfo->pSortHandle, mergeLimit);
 | 
			
		||||
  }
 | 
			
		||||
  tsortSetFetchRawDataFp(pInfo->pSortHandle, getTableDataBlockImpl, NULL, NULL);
 | 
			
		||||
 | 
			
		||||
  // one table has one data block
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -54,13 +54,6 @@ SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSortPhysiNode*
 | 
			
		|||
  int32_t numOfCols = 0;
 | 
			
		||||
  pOperator->exprSupp.pExprInfo = createExprInfo(pSortNode->pExprs, NULL, &numOfCols);
 | 
			
		||||
  pOperator->exprSupp.numOfExprs = numOfCols;
 | 
			
		||||
  calcSortOperMaxTupleLength(pInfo, pSortNode->pSortKeys);
 | 
			
		||||
  pInfo->maxRows = -1;
 | 
			
		||||
  if (pSortNode->node.pLimit) {
 | 
			
		||||
    SLimitNode* pLimit = (SLimitNode*)pSortNode->node.pLimit;
 | 
			
		||||
    if (pLimit->limit > 0) pInfo->maxRows = pLimit->limit;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  int32_t numOfOutputCols = 0;
 | 
			
		||||
  int32_t code =
 | 
			
		||||
      extractColMatchInfo(pSortNode->pTargets, pDescNode, &numOfOutputCols, COL_MATCH_FROM_SLOT_ID, &pInfo->matchInfo);
 | 
			
		||||
| 
						 | 
				
			
			@ -68,6 +61,13 @@ SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSortPhysiNode*
 | 
			
		|||
    goto _error;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  calcSortOperMaxTupleLength(pInfo, pSortNode->pSortKeys);
 | 
			
		||||
  pInfo->maxRows = -1;
 | 
			
		||||
  if (pSortNode->node.pLimit) {
 | 
			
		||||
    SLimitNode* pLimit = (SLimitNode*)pSortNode->node.pLimit;
 | 
			
		||||
    if (pLimit->limit > 0) pInfo->maxRows = pLimit->limit + pLimit->offset;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  pOperator->exprSupp.pCtx =
 | 
			
		||||
      createSqlFunctionCtx(pOperator->exprSupp.pExprInfo, numOfCols, &pOperator->exprSupp.rowEntryInfoOffset, &pTaskInfo->storageAPI.functionStore);
 | 
			
		||||
  initResultSizeInfo(&pOperator->resultInfo, 1024);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue