diff --git a/src/query/inc/qExtbuffer.h b/src/query/inc/qExtbuffer.h index e8533add9054a6e1e3ade394fdd26fe4ff5462f4..c1cb4664147d80628e26d4f401673a2775b94c56 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 d3e38cf365272781ecd3b7727d1f9809f50897af..82f4d9aff90b8028705dafcab7a35bae81c3713f 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -6311,7 +6311,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 e2c649e99c01d5c8b9f6497eddbaf126e644ce09..9e5aa7632f2bffcc12161cf685504e1c32de9eff 100644 --- a/src/query/src/qExtbuffer.c +++ b/src/query/src/qExtbuffer.c @@ -1257,7 +1257,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; @@ -1289,7 +1289,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; @@ -1309,4 +1314,5 @@ void taoscQSort(void** pCols, SSchema* pSchema, int32_t numOfCols, int32_t numOf tfree(buf); tfree(p); + return TSDB_CODE_SUCCESS; }