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 tableStartIdx = pInfo->tableStartIndex;
|
||||||
int32_t tableEndIdx = pInfo->tableEndIndex;
|
int32_t tableEndIdx = pInfo->tableEndIndex;
|
||||||
|
|
||||||
pInfo->sortBufSize = 2048 * pInfo->bufPageSize;
|
bool hasLimit = pInfo->limitInfo.limit.limit != -1 || pInfo->limitInfo.limit.offset != -1;
|
||||||
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;
|
int64_t mergeLimit = -1;
|
||||||
if (pInfo->limitInfo.limit.limit != -1 || pInfo->limitInfo.limit.offset != -1) {
|
if (hasLimit) {
|
||||||
mergeLimit = pInfo->limitInfo.limit.limit + pInfo->limitInfo.limit.offset;
|
mergeLimit = pInfo->limitInfo.limit.limit + pInfo->limitInfo.limit.offset;
|
||||||
}
|
}
|
||||||
tsortSetMergeLimit(pInfo->pSortHandle, mergeLimit);
|
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);
|
||||||
|
|
||||||
|
tsortSetMergeLimit(pInfo->pSortHandle, mergeLimit);
|
||||||
|
}
|
||||||
tsortSetFetchRawDataFp(pInfo->pSortHandle, getTableDataBlockImpl, NULL, NULL);
|
tsortSetFetchRawDataFp(pInfo->pSortHandle, getTableDataBlockImpl, NULL, NULL);
|
||||||
|
|
||||||
// one table has one data block
|
// one table has one data block
|
||||||
|
|
|
@ -54,19 +54,19 @@ SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSortPhysiNode*
|
||||||
int32_t numOfCols = 0;
|
int32_t numOfCols = 0;
|
||||||
pOperator->exprSupp.pExprInfo = createExprInfo(pSortNode->pExprs, NULL, &numOfCols);
|
pOperator->exprSupp.pExprInfo = createExprInfo(pSortNode->pExprs, NULL, &numOfCols);
|
||||||
pOperator->exprSupp.numOfExprs = 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 numOfOutputCols = 0;
|
||||||
int32_t code =
|
int32_t code =
|
||||||
extractColMatchInfo(pSortNode->pTargets, pDescNode, &numOfOutputCols, COL_MATCH_FROM_SLOT_ID, &pInfo->matchInfo);
|
extractColMatchInfo(pSortNode->pTargets, pDescNode, &numOfOutputCols, COL_MATCH_FROM_SLOT_ID, &pInfo->matchInfo);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
goto _error;
|
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 =
|
pOperator->exprSupp.pCtx =
|
||||||
createSqlFunctionCtx(pOperator->exprSupp.pExprInfo, numOfCols, &pOperator->exprSupp.rowEntryInfoOffset, &pTaskInfo->storageAPI.functionStore);
|
createSqlFunctionCtx(pOperator->exprSupp.pExprInfo, numOfCols, &pOperator->exprSupp.rowEntryInfoOffset, &pTaskInfo->storageAPI.functionStore);
|
||||||
|
|
Loading…
Reference in New Issue