diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index f5b887936814b4d0614c9cb2ded71235e5863904..d2fb5d6a47a80a62fc68f3e9271d5fa7c8df0370 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -3362,13 +3362,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col tVariantDump(pVariant, val, TSDB_DATA_TYPE_BIGINT, true); if(functionId == TSDB_FUNC_UNIQUE){ // consider of memory size - if(pSchema->bytes < 10){ - GET_INT64_VAL(val) = MAX_UNIQUE_RESULT_ROWS * 100; - }else if(pSchema->bytes < 100){ - GET_INT64_VAL(val) = MAX_UNIQUE_RESULT_ROWS * 10; - }else{ - GET_INT64_VAL(val) = MAX_UNIQUE_RESULT_ROWS; - } + GET_INT64_VAL(val) = MAX_UNIQUE_RESULT_ROWS; } int64_t numRowsSelected = GET_INT64_VAL(val); diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 099f01e9a708377b076895d3d472d653b977fc56..47efc29031b972818fbc540150613b61c0b199c5 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -1528,6 +1528,11 @@ void handleDownstreamOperator(SSqlObj** pSqlObjList, int32_t numOfUpstream, SQue tscDebug("0x%"PRIx64" create QInfo 0x%"PRIx64" to execute the main query while all nest queries are ready", pSql->self, pSql->self); px->pQInfo = createQInfoFromQueryNode(px, &tableGroupInfo, pSourceOperator, NULL, NULL, MASTER_SCAN, pSql->self); + if (px->pQInfo == NULL) { + tscAsyncResultOnError(pSql); + pOutput->code = TSDB_CODE_QRY_OUT_OF_MEMORY; + return; + } px->pQInfo->runtimeEnv.udfIsCopy = true; px->pQInfo->runtimeEnv.pUdfInfo = pUdfInfo; diff --git a/src/query/inc/qResultbuf.h b/src/query/inc/qResultbuf.h index 5191ddab46411032e25f4663122b04931281b132..7c33f729acca052b6123b5139c235195231bb9f2 100644 --- a/src/query/inc/qResultbuf.h +++ b/src/query/inc/qResultbuf.h @@ -79,9 +79,9 @@ typedef struct SDiskbasedResultBuf { #define DEFAULT_INTERN_BUF_PAGE_SIZE (1024L) // in bytes #define PAGE_INFO_INITIALIZER (SPageDiskInfo){-1, -1} #define MAX_UNIQUE_RESULT_ROWS (10000) -#define MAX_UNIQUE_RESULT_SIZE (1024*1024*10) -#define MAX_MODE_INNER_RESULT_ROWS (1000000) -#define MAX_MODE_INNER_RESULT_SIZE (1024*1024*10) +#define MAX_UNIQUE_RESULT_SIZE (1024*1024) +#define MAX_MODE_INNER_RESULT_ROWS (10000) +#define MAX_MODE_INNER_RESULT_SIZE (1024*1024) /** * create disk-based result buffer * @param pResultBuf diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 5e035463f835102ff444466fdcc65e5e02b5425a..1facab0b34e271394c37486ee2b900ec89c8f71c 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -330,11 +330,11 @@ SSDataBlock* createOutputBuf(SExprInfo* pExpr, int32_t numOfOutput, int32_t numO int64_t tmp = idata.info.bytes; tmp *= numOfRows; - if (tmp >= 1024*1024*1024) { // 1G - qError("size is too large, failed to allocate column buffer for output buffer"); + if (tmp >= INT32_MAX) { + qError("size is too large, failed to allocate column buffer for output buffer:%" PRId64, tmp); tmp = 128*1024*1024; } - int32_t size = (int32_t)MAX(tmp, minSize); + size_t size = (size_t)MAX(tmp, minSize); idata.pData = calloc(1, size); // at least to hold a pointer on x64 platform if (idata.pData == NULL) { qError("failed to allocate column buffer for output buffer"); @@ -2131,7 +2131,7 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOf pRuntimeEnv->sasArray = calloc(pQueryAttr->numOfOutput, sizeof(SScalarExprSupport)); if (pRuntimeEnv->sasArray == NULL || pRuntimeEnv->pResultRowHashTable == NULL || pRuntimeEnv->keyBuf == NULL || - pRuntimeEnv->prevRow == NULL || pRuntimeEnv->tagVal == NULL) { + pRuntimeEnv->prevRow == NULL || pRuntimeEnv->tagVal == NULL || pRuntimeEnv->pool == NULL) { goto _clean; } diff --git a/src/query/src/qUtil.c b/src/query/src/qUtil.c index 67dfc130ed58d416500d278c60945114ef8a3fe4..1628c2d5111268111ca88cbe511095e8334453ed 100644 --- a/src/query/src/qUtil.c +++ b/src/query/src/qUtil.c @@ -204,9 +204,9 @@ SResultRowPool* initResultRowPool(size_t size) { p->elemSize = (int32_t) size; int64_t tmp = p->elemSize; tmp *= p->numOfElemPerBlock; - if (tmp > 1024*1024*1024){ + if (tmp > INT32_MAX){ qError("ResultRow blockSize is too large:%" PRId64, tmp); - tmp = 128*1024*1024; + return NULL; } p->blockSize = (int32_t)tmp; p->position.pos = 0; @@ -223,6 +223,7 @@ SResultRow* getNewResultRow(SResultRowPool* p) { void* ptr = NULL; if (p->position.pos == 0) { ptr = calloc(1, p->blockSize); + if(ptr == NULL) return NULL; taosArrayPush(p->pData, &ptr); } else {