diff --git a/src/client/src/tscGlobalmerge.c b/src/client/src/tscGlobalmerge.c index f84ed0af9ba0979dad42b17958a715790214df13..6974e8e868021faf89bbbd1da2e39235aaa67d3c 100644 --- a/src/client/src/tscGlobalmerge.c +++ b/src/client/src/tscGlobalmerge.c @@ -233,7 +233,7 @@ static int32_t tscFlushTmpBufferImpl(tExtMemBuffer *pMemoryBuf, tOrderDescriptor // sort before flush to disk, the data must be consecutively put on tFilePage. if (pDesc->orderInfo.numOfCols > 0) { - tColDataSort(pDesc, (int32_t)pPage->num, 0, (int32_t)pPage->num - 1, pPage->data, orderType, true); + tColDataMergeSort(pDesc, (int32_t)pPage->num, 0, (int32_t)pPage->num - 1, pPage->data, orderType); } #ifdef _DEBUG_VIEW diff --git a/src/query/inc/qExtbuffer.h b/src/query/inc/qExtbuffer.h index bce90ae732a0501f8525fa6826d4213e801cb7e8..ceda7f98b3981b174a275467438b72d7541d14f7 100644 --- a/src/query/inc/qExtbuffer.h +++ b/src/query/inc/qExtbuffer.h @@ -227,7 +227,10 @@ void tColModelAppend(SColumnModel *dstModel, tFilePage *dstPage, void *srcData, typedef int (*__col_compar_fn_t)(tOrderDescriptor *, int32_t numOfRows, int32_t idx1, int32_t idx2, char *data); -void tColDataSort(tOrderDescriptor *, int32_t numOfRows, int32_t start, int32_t end, char *data, int32_t orderType, bool stableSort); +void tColDataQSort(tOrderDescriptor *, int32_t numOfRows, int32_t start, int32_t end, char *data, int32_t orderType); + +void tColDataMergeSort(tOrderDescriptor *, int32_t numOfRows, int32_t start, int32_t end, char *data, int32_t orderType); + void taoscQSort(void** pCols, SSchema* pSchema, int32_t numOfCols, int32_t numOfRows, int32_t index, __compar_fn_t compareFn); diff --git a/src/query/src/qExtbuffer.c b/src/query/src/qExtbuffer.c index b8ca3f18b47e4edb3269b81c974c775f59537601..a004e0a60da9cdfd90ec450a9fba9d83b159a625 100644 --- a/src/query/src/qExtbuffer.c +++ b/src/query/src/qExtbuffer.c @@ -825,7 +825,7 @@ static void columnwiseQSortImpl(tOrderDescriptor *pDescriptor, int32_t numOfRows } } -void tColDataSort(tOrderDescriptor *pDescriptor, int32_t numOfRows, int32_t start, int32_t end, char *data, int32_t orderType, bool stableSort) { +void tColDataQSort(tOrderDescriptor *pDescriptor, int32_t numOfRows, int32_t start, int32_t end, char *data, int32_t orderType) { // short array sort, incur another sort procedure instead of quick sort process __col_compar_fn_t compareFn = (orderType == TSDB_ORDER_ASC) ? compare_sa : compare_sd; @@ -844,8 +844,6 @@ void tColDataSort(tOrderDescriptor *pDescriptor, int32_t numOfRows, int32_t star if (end - start + 1 <= 8) { tColDataInsertSort(pDescriptor, numOfRows, start, end, data, compareFn, buf); - } else if (stableSort) { - columnwiseMergeSortImpl(pDescriptor, numOfRows, start, end, data, orderType, compareFn); } else { columnwiseQSortImpl(pDescriptor, numOfRows, start, end, data, orderType, compareFn, buf); } @@ -853,6 +851,34 @@ void tColDataSort(tOrderDescriptor *pDescriptor, int32_t numOfRows, int32_t star free(buf); } +void tColDataMergeSort(tOrderDescriptor *pDescriptor, int32_t numOfRows, int32_t start, int32_t end, char *data, int32_t orderType) { + // short array sort, incur another sort procedure instead of quick sort process + __col_compar_fn_t compareFn = (orderType == TSDB_ORDER_ASC) ? compare_sa : compare_sd; + + SColumnModel* pModel = pDescriptor->pColumnModel; + + size_t width = 0; + for(int32_t i = 0; i < pModel->numOfCols; ++i) { + SSchema* pSchema = &pModel->pFields[i].field; + if (width < pSchema->bytes) { + width = pSchema->bytes; + } + } + + char* buf = malloc(width); + assert(width > 0 && buf != NULL); + + if (end - start + 1 <= 8) { + tColDataInsertSort(pDescriptor, numOfRows, start, end, data, compareFn, buf); + } else { + columnwiseMergeSortImpl(pDescriptor, numOfRows, start, end, data, orderType, compareFn); + } + + free(buf); +} + + + /* * deep copy of sschema */