diff --git a/src/query/inc/qExtbuffer.h b/src/query/inc/qExtbuffer.h index 9938f599ed2f3a5844b386b13cd95da5951a45f0..509549ba22842a200f5efbb69ff0f73237b31737 100644 --- a/src/query/inc/qExtbuffer.h +++ b/src/query/inc/qExtbuffer.h @@ -227,8 +227,6 @@ tOrderDescriptor *tOrderDesCreate(const int32_t *orderColIdx, int32_t numOfOrder void tOrderDescDestroy(tOrderDescriptor *pDesc); -void taoscQSort(void** pCols, SSchema* pSchema, int32_t numOfCols, int32_t numOfRows, int32_t index, __compar_fn_t compareFn); - void tColModelAppend(SColumnModel *dstModel, tFilePage *dstPage, void *srcData, int32_t srcStartRows, int32_t numOfRowsToWrite, int32_t srcCapacity); @@ -239,7 +237,7 @@ void tColDataQSort(tOrderDescriptor *, int32_t numOfRows, int32_t start, int32_t 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); +int32_t taoscQSort(void** pCols, SSchema* pSchema, int32_t numOfCols, int32_t numOfRows, int32_t index, __compar_fn_t compareFn); int32_t compare_sa(tOrderDescriptor *, int32_t numOfRows, int32_t idx1, int32_t idx2, char *data); diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 9424200840f4599bc6bb67e80396c5587bb7d811..dc2837869f5da82129d5c64cd9595d88c4d81e03 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -5959,7 +5959,13 @@ static SSDataBlock* doSort(void* param, bool* newgroup) { __compar_fn_t comp = getKeyComparFunc(pSchema[pInfo->colIndex].type, pInfo->order); if (pInfo->pDataBlock->info.rows) { - taoscQSort(pCols, pSchema, numOfCols, pInfo->pDataBlock->info.rows, pInfo->colIndex, comp); + int32_t code = taoscQSort(pCols, pSchema, numOfCols, pInfo->pDataBlock->info.rows, pInfo->colIndex, comp); + if (code != TSDB_CODE_SUCCESS) { + qError("QInfo:0x%"PRIx64 " can not sort since %s", GET_QID(pOperator->pRuntimeEnv), tstrerror(code)); + tfree(pCols); + tfree(pSchema); + longjmp(pOperator->pRuntimeEnv->env, code); + } } tfree(pCols); diff --git a/src/query/src/qExtbuffer.c b/src/query/src/qExtbuffer.c index d49d6ecf0b582ba60674d8a3e7a482bf8d969238..f3fcab9ff73c9365a70d82d02ab5ccc973700472 100644 --- a/src/query/src/qExtbuffer.c +++ b/src/query/src/qExtbuffer.c @@ -1246,7 +1246,7 @@ void tOrderDescDestroy(tOrderDescriptor *pDesc) { tfree(pDesc); } -void taoscQSort(void** pCols, SSchema* pSchema, int32_t numOfCols, int32_t numOfRows, int32_t idx, __compar_fn_t compareFn) { +int32_t taoscQSort(void** pCols, SSchema* pSchema, int32_t numOfCols, int32_t numOfRows, int32_t idx, __compar_fn_t compareFn) { assert(numOfRows > 0 && numOfCols > 0 && idx >= 0 && idx < numOfCols); int32_t bytes = pSchema[idx].bytes; @@ -1278,7 +1278,12 @@ void taoscQSort(void** pCols, SSchema* pSchema, int32_t numOfCols, int32_t numOf // make sure memory buffer is enough if (prevLength < bytes1) { char *tmp = realloc(p, bytes1 * numOfRows); - assert(tmp); + if (tmp == NULL) { + qError("can not allocated memory. bytes:%d", bytes*numOfRows); + tfree(p); + tfree(buf); + return TSDB_CODE_QRY_OUT_OF_MEMORY; + } p = tmp; prevLength = bytes1; @@ -1298,4 +1303,5 @@ void taoscQSort(void** pCols, SSchema* pSchema, int32_t numOfCols, int32_t numOf tfree(buf); tfree(p); + return TSDB_CODE_SUCCESS; }