From 5341a6eeac510289bd1d9e0bacfed15cbc84f388 Mon Sep 17 00:00:00 2001 From: jtcheng Date: Fri, 2 Jul 2021 17:01:49 +0800 Subject: [PATCH 01/13] [TD-6536]: Fix memory leak during alter database --- src/query/src/qSqlParser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/query/src/qSqlParser.c b/src/query/src/qSqlParser.c index a2cb7aee00..2021bc41c0 100644 --- a/src/query/src/qSqlParser.c +++ b/src/query/src/qSqlParser.c @@ -938,7 +938,7 @@ void SqlInfoDestroy(SSqlInfo *pInfo) { taosArrayDestroy(pInfo->pMiscInfo->a); } - if (pInfo->pMiscInfo != NULL && pInfo->type == TSDB_SQL_CREATE_DB) { + if (pInfo->pMiscInfo != NULL && (pInfo->type == TSDB_SQL_CREATE_DB || pInfo->type == TSDB_SQL_ALTER_DB)) { taosArrayDestroyEx(pInfo->pMiscInfo->dbOpt.keep, freeVariant); } From 95bc9aa96f10ff86ad3b96703220960060a883fe Mon Sep 17 00:00:00 2001 From: jtcheng Date: Mon, 5 Jul 2021 10:10:40 +0800 Subject: [PATCH 02/13] [self-assign]: Fix self-assignment --- src/client/src/tscServer.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 029fa853ac..fdd748b693 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -2005,7 +2005,6 @@ static SVgroupsInfo* createVgroupInfoFromMsg(char* pMsg, int32_t* size, uint64_t SVgroupMsg *vmsg = &pVgroupMsg->vgroups[j]; vmsg->vgId = htonl(vmsg->vgId); - vmsg->numOfEps = vmsg->numOfEps; for (int32_t k = 0; k < vmsg->numOfEps; ++k) { vmsg->epAddr[k].port = htons(vmsg->epAddr[k].port); } From a49c706bee4edf1df8958997a8057d5df98ad5e6 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 7 Jul 2021 08:56:58 +0800 Subject: [PATCH 03/13] [TD-5035] fix empty pointer --- src/client/src/tscUtil.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index d653489e29..b42724a2ec 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -634,7 +634,9 @@ static void setResRawPtrImpl(SSqlRes* pRes, SInternalField* pInfo, int32_t i, bo void tscSetResRawPtr(SSqlRes* pRes, SQueryInfo* pQueryInfo) { assert(pRes->numOfCols > 0); - + if (pRes->numOfRows == 0) { + return; + } int32_t offset = 0; for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) { SInternalField* pInfo = (SInternalField*)TARRAY_GET_ELEM(pQueryInfo->fieldsInfo.internalField, i); From 1caaab48eef593f5df7dcd68a6af65ff350bc3e4 Mon Sep 17 00:00:00 2001 From: wpan Date: Wed, 7 Jul 2021 10:06:16 +0800 Subject: [PATCH 04/13] fix nchar filter issue --- src/client/src/tscUtil.c | 36 ++++++++++++++++++++++++++++++++++++ src/query/inc/qExecutor.h | 1 + 2 files changed, 37 insertions(+) diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 838416fa2e..7b010677c3 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -746,6 +746,37 @@ typedef struct SJoinOperatorInfo { SRspResultInfo resultInfo; // todo refactor, add this info for each operator } SJoinOperatorInfo; +static void converNcharFilterColumn(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFilterCols, int32_t rows, bool *gotNchar) { + for (int32_t i = 0; i < numOfFilterCols; ++i) { + if (pFilterInfo[i].info.type == TSDB_DATA_TYPE_NCHAR) { + pFilterInfo[i].pData2 = pFilterInfo[i].pData; + pFilterInfo[i].pData = malloc(rows * pFilterInfo[i].info.bytes); + int32_t bufSize = pFilterInfo[i].info.bytes - VARSTR_HEADER_SIZE; + for (int32_t j = 0; j < rows; ++j) { + char* dst = pFilterInfo[i].pData + j * pFilterInfo[i].info.bytes; + char* src = pFilterInfo[i].pData2 + j * pFilterInfo[i].info.bytes; + int32_t len = 0; + taosMbsToUcs4(varDataVal(src), varDataLen(src), varDataVal(dst), bufSize, &len); + varDataLen(dst) = len; + } + *gotNchar = true; + } + } +} + +static void freeNcharFilterColumn(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFilterCols) { + for (int32_t i = 0; i < numOfFilterCols; ++i) { + if (pFilterInfo[i].info.type == TSDB_DATA_TYPE_NCHAR) { + if (pFilterInfo[i].pData2) { + tfree(pFilterInfo[i].pData); + pFilterInfo[i].pData = pFilterInfo[i].pData2; + pFilterInfo[i].pData2 = NULL; + } + } + } +} + + static void doSetupSDataBlock(SSqlRes* pRes, SSDataBlock* pBlock, SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFilterCols) { int32_t offset = 0; char* pData = pRes->data; @@ -764,8 +795,13 @@ static void doSetupSDataBlock(SSqlRes* pRes, SSDataBlock* pBlock, SSingleColumnF // filter data if needed if (numOfFilterCols > 0) { doSetFilterColumnInfo(pFilterInfo, numOfFilterCols, pBlock); + bool gotNchar = false; + converNcharFilterColumn(pFilterInfo, numOfFilterCols, pBlock->info.rows, &gotNchar); int8_t* p = calloc(pBlock->info.rows, sizeof(int8_t)); bool all = doFilterDataBlock(pFilterInfo, numOfFilterCols, pBlock->info.rows, p); + if (gotNchar) { + freeNcharFilterColumn(pFilterInfo, numOfFilterCols); + } if (!all) { doCompactSDataBlock(pBlock, pBlock->info.rows, p); } diff --git a/src/query/inc/qExecutor.h b/src/query/inc/qExecutor.h index bc934647ec..1d26d292fa 100644 --- a/src/query/inc/qExecutor.h +++ b/src/query/inc/qExecutor.h @@ -118,6 +118,7 @@ typedef struct SColumnFilterElem { typedef struct SSingleColumnFilterInfo { void* pData; + void* pData2; //used for nchar column int32_t numOfFilters; SColumnInfo info; SColumnFilterElem* pFilters; From 7f25afc8311989fd9de2085e1e427037202d6421 Mon Sep 17 00:00:00 2001 From: wpan Date: Wed, 7 Jul 2021 11:12:37 +0800 Subject: [PATCH 05/13] fix windows compile error --- src/client/src/tscUtil.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 7b010677c3..adb7e33902 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -753,8 +753,8 @@ static void converNcharFilterColumn(SSingleColumnFilterInfo* pFilterInfo, int32_ pFilterInfo[i].pData = malloc(rows * pFilterInfo[i].info.bytes); int32_t bufSize = pFilterInfo[i].info.bytes - VARSTR_HEADER_SIZE; for (int32_t j = 0; j < rows; ++j) { - char* dst = pFilterInfo[i].pData + j * pFilterInfo[i].info.bytes; - char* src = pFilterInfo[i].pData2 + j * pFilterInfo[i].info.bytes; + char* dst = (char *)pFilterInfo[i].pData + j * pFilterInfo[i].info.bytes; + char* src = (char *)pFilterInfo[i].pData2 + j * pFilterInfo[i].info.bytes; int32_t len = 0; taosMbsToUcs4(varDataVal(src), varDataLen(src), varDataVal(dst), bufSize, &len); varDataLen(dst) = len; From 7f3654bdfc60a15f9a93666bb3b2fe9b36c5e5eb Mon Sep 17 00:00:00 2001 From: plum-lihui Date: Wed, 7 Jul 2021 16:41:04 +0800 Subject: [PATCH 06/13] [TD-5056] fix input exception --- src/kit/shell/inc/shellCommand.h | 2 +- src/kit/shell/src/shellCommand.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/kit/shell/inc/shellCommand.h b/src/kit/shell/inc/shellCommand.h index 3094bdb9dd..a08c1f48d1 100644 --- a/src/kit/shell/inc/shellCommand.h +++ b/src/kit/shell/inc/shellCommand.h @@ -45,7 +45,7 @@ extern void updateBuffer(Command *cmd); extern int isReadyGo(Command *cmd); extern void resetCommand(Command *cmd, const char s[]); -int countPrefixOnes(char c); +int countPrefixOnes(unsigned char c); void clearScreen(int ecmd_pos, int cursor_pos); void printChar(char c, int times); void positionCursor(int step, int direction); diff --git a/src/kit/shell/src/shellCommand.c b/src/kit/shell/src/shellCommand.c index 9173ab0efd..e1a3dfe102 100644 --- a/src/kit/shell/src/shellCommand.c +++ b/src/kit/shell/src/shellCommand.c @@ -26,7 +26,7 @@ typedef struct { char widthOnScreen; } UTFCodeInfo; -int countPrefixOnes(char c) { +int countPrefixOnes(unsigned char c) { unsigned char mask = 127; mask = ~mask; int ret = 0; @@ -48,7 +48,7 @@ void getPrevCharSize(const char *str, int pos, int *size, int *width) { while (--pos >= 0) { *size += 1; - if (str[pos] > 0 || countPrefixOnes(str[pos]) > 1) break; + if (str[pos] > 0 || countPrefixOnes((unsigned char )str[pos]) > 1) break; } int rc = mbtowc(&wc, str + pos, MB_CUR_MAX); From c5ee2fd58d1a5bac94194214f4c8a3c0e747ed7f Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 7 Jul 2021 17:02:33 +0800 Subject: [PATCH 07/13] [td-225] refactor. --- src/query/src/qExecutor.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 6bd5e03377..e98c7830f3 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -1265,8 +1265,7 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul for (int32_t j = prevIndex; j < curIndex; ++j) { // previous time window may be all closed already. SResultRow* pRes = pResultRowInfo->pResult[j]; if (pRes->closed) { - assert(resultRowInterpolated(pRes, RESULT_ROW_START_INTERP) && - resultRowInterpolated(pRes, RESULT_ROW_END_INTERP)); + assert(resultRowInterpolated(pRes, RESULT_ROW_START_INTERP) && resultRowInterpolated(pRes, RESULT_ROW_END_INTERP)); continue; } @@ -5327,9 +5326,16 @@ static SSDataBlock* doIntervalAgg(void* param, bool* newgroup) { SOperatorInfo* upstream = pOperator->upstream[0]; + int64_t ss = taosGetTimestampMs(); + printf("=-=============%ld\n", ss); while(1) { publishOperatorProfEvent(upstream, QUERY_PROF_BEFORE_OPERATOR_EXEC); + int64_t s = taosGetTimestampMs(); + printf("start: %ld\n", s); SSDataBlock* pBlock = upstream->exec(upstream, newgroup); + + int64_t end = taosGetTimestampMs(); + printf("end: %ld, el:%ld \n", end, end - s); publishOperatorProfEvent(upstream, QUERY_PROF_AFTER_OPERATOR_EXEC); if (pBlock == NULL) { @@ -5338,9 +5344,16 @@ static SSDataBlock* doIntervalAgg(void* param, bool* newgroup) { // the pDataBlock are always the same one, no need to call this again setInputDataBlock(pOperator, pIntervalInfo->pCtx, pBlock, pQueryAttr->order.order); + + int64_t x1 = taosGetTimestampMs(); hashIntervalAgg(pOperator, &pIntervalInfo->resultRowInfo, pBlock, 0); + int64_t x2 = taosGetTimestampMs(); + printf("-------------------------inter:%ld\n", x2-x1); } + int64_t s1 = taosGetTimestampMs(); + printf("=-=============%ld, el:%ld\n", s1, s1-ss); + // restore the value pQueryAttr->order.order = order; pQueryAttr->window = win; From 52cef5f97a6b76dc048b36a397ca91358349d7f0 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 8 Jul 2021 10:58:46 +0800 Subject: [PATCH 08/13] [td-5126]: optimize the outer query performance when handling the time window query. --- src/query/inc/qExecutor.h | 8 ++--- src/query/src/qExecutor.c | 70 +++++++++++++++++++++++---------------- src/query/src/qUtil.c | 8 ++--- 3 files changed, 50 insertions(+), 36 deletions(-) diff --git a/src/query/inc/qExecutor.h b/src/query/inc/qExecutor.h index bc934647ec..83214d293e 100644 --- a/src/query/inc/qExecutor.h +++ b/src/query/inc/qExecutor.h @@ -73,14 +73,14 @@ typedef struct SResultRowPool { typedef struct SResultRow { int32_t pageId; // pageId & rowId is the position of current result in disk-based output buffer - int32_t offset:29; // row index in buffer page + int32_t offset:29; // row index in buffer page bool startInterp; // the time window start timestamp has done the interpolation already. bool endInterp; // the time window end timestamp has done the interpolation already. bool closed; // this result status: closed or opened uint32_t numOfRows; // number of rows of current time window SResultRowCellInfo* pCellInfo; // For each result column, there is a resultInfo - STimeWindow win; - char* key; // start key of current result row + STimeWindow win; + char *key; // start key of current result row } SResultRow; typedef struct SGroupResInfo { @@ -105,7 +105,7 @@ typedef struct SResultRowInfo { int16_t type:8; // data type for hash key int32_t size:24; // number of result set int32_t capacity; // max capacity - int32_t curIndex; // current start active index + SResultRow* current; // current start active index int64_t prevSKey; // previous (not completed) sliding window start key } SResultRowInfo; diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index e98c7830f3..7089760e35 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -426,13 +426,8 @@ static SResultRow *doPrepareResultRowFromKey(SQueryRuntimeEnv *pRuntimeEnv, SRes } if (p1 != NULL) { - for(int32_t i = pResultRowInfo->size - 1; i >= 0; --i) { - if (pResultRowInfo->pResult[i] == (*p1)) { - pResultRowInfo->curIndex = i; - existed = true; - break; - } - } + pResultRowInfo->current = (*p1); + existed = true; } } else { if (p1 != NULL) { // group by column query @@ -457,8 +452,8 @@ static SResultRow *doPrepareResultRowFromKey(SQueryRuntimeEnv *pRuntimeEnv, SRes pResult = *p1; } - pResultRowInfo->pResult[pResultRowInfo->size] = pResult; - pResultRowInfo->curIndex = pResultRowInfo->size++; + pResultRowInfo->pResult[pResultRowInfo->size++] = pResult; + pResultRowInfo->current = pResult; } // too many time window in query @@ -466,7 +461,7 @@ static SResultRow *doPrepareResultRowFromKey(SQueryRuntimeEnv *pRuntimeEnv, SRes longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW); } - return getResultRow(pResultRowInfo, pResultRowInfo->curIndex); + return pResultRowInfo->current; } static void getInitialStartTimeWindow(SQueryAttr* pQueryAttr, TSKEY ts, STimeWindow* w) { @@ -497,7 +492,7 @@ static void getInitialStartTimeWindow(SQueryAttr* pQueryAttr, TSKEY ts, STimeWin static STimeWindow getActiveTimeWindow(SResultRowInfo * pResultRowInfo, int64_t ts, SQueryAttr *pQueryAttr) { STimeWindow w = {0}; - if (pResultRowInfo->curIndex == -1) { // the first window, from the previous stored value + if (pResultRowInfo->current == NULL) { // the first window, from the previous stored value if (pResultRowInfo->prevSKey == TSKEY_INITIAL_VAL) { getInitialStartTimeWindow(pQueryAttr, ts, &w); pResultRowInfo->prevSKey = w.skey; @@ -511,8 +506,9 @@ static STimeWindow getActiveTimeWindow(SResultRowInfo * pResultRowInfo, int64_t w.ekey = w.skey + pQueryAttr->interval.interval - 1; } } else { - int32_t slot = curTimeWindowIndex(pResultRowInfo); - SResultRow* pWindowRes = getResultRow(pResultRowInfo, slot); +// int32_t slot = curTimeWindowIndex(pResultRowInfo); +// SResultRow* pWindowRes = getResultRow(pResultRowInfo, slot); + SResultRow* pWindowRes = pResultRowInfo->current; w = pWindowRes->win; } @@ -698,7 +694,12 @@ static void doUpdateResultRowIndex(SResultRowInfo*pResultRowInfo, TSKEY lastKey, // all result rows are closed, set the last one to be the skey if (skey == TSKEY_INITIAL_VAL) { - pResultRowInfo->curIndex = pResultRowInfo->size - 1; + if (pResultRowInfo->size == 0) { +// assert(pResultRowInfo->current == NULL); + pResultRowInfo->current = NULL; + } else { + pResultRowInfo->current = pResultRowInfo->pResult[pResultRowInfo->size - 1]; + } } else { for (i = pResultRowInfo->size - 1; i >= 0; --i) { @@ -709,12 +710,12 @@ static void doUpdateResultRowIndex(SResultRowInfo*pResultRowInfo, TSKEY lastKey, } if (i == pResultRowInfo->size - 1) { - pResultRowInfo->curIndex = i; + pResultRowInfo->current = pResultRowInfo->pResult[i]; } else { - pResultRowInfo->curIndex = i + 1; // current not closed result object + pResultRowInfo->current = pResultRowInfo->pResult[i + 1]; // current not closed result object } - pResultRowInfo->prevSKey = pResultRowInfo->pResult[pResultRowInfo->curIndex]->win.skey; + pResultRowInfo->prevSKey = pResultRowInfo->current->win.skey; } } @@ -722,7 +723,7 @@ static void updateResultRowInfoActiveIndex(SResultRowInfo* pResultRowInfo, SQuer bool ascQuery = QUERY_IS_ASC_QUERY(pQueryAttr); if ((lastKey > pQueryAttr->window.ekey && ascQuery) || (lastKey < pQueryAttr->window.ekey && (!ascQuery))) { closeAllResultRows(pResultRowInfo); - pResultRowInfo->curIndex = pResultRowInfo->size - 1; + pResultRowInfo->current = pResultRowInfo->pResult[pResultRowInfo->size - 1]; } else { int32_t step = ascQuery ? 1 : -1; doUpdateResultRowIndex(pResultRowInfo, lastKey - step, ascQuery, pQueryAttr->timeWindowInterpo); @@ -1231,7 +1232,8 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQueryAttr->order.order); bool ascQuery = QUERY_IS_ASC_QUERY(pQueryAttr); - int32_t prevIndex = curTimeWindowIndex(pResultRowInfo); + SResultRow* prevRow = pResultRowInfo->current; +// int32_t prevIndex = curTimeWindowIndex(pResultRowInfo); TSKEY* tsCols = NULL; if (pSDataBlock->pDataBlock != NULL) { @@ -1260,9 +1262,16 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul getNumOfRowsInTimeWindow(pRuntimeEnv, &pSDataBlock->info, tsCols, startPos, ekey, binarySearchForKey, true); // prev time window not interpolation yet. - int32_t curIndex = curTimeWindowIndex(pResultRowInfo); - if (prevIndex != -1 && prevIndex < curIndex && pQueryAttr->timeWindowInterpo) { - for (int32_t j = prevIndex; j < curIndex; ++j) { // previous time window may be all closed already. +// int32_t curIndex = curTimeWindowIndex(pResultRowInfo); +// if (prevIndex != -1 && prevIndex < curIndex && pQueryAttr->timeWindowInterpo) { +// for (int32_t j = prevIndex; j < curIndex; ++j) { // previous time window may be all closed already. + if (prevRow != NULL && prevRow != pResultRowInfo->current && pQueryAttr->timeWindowInterpo) { + int32_t j = 0; + while(pResultRowInfo->pResult[j] != prevRow) { + j++; + } + + for(; pResultRowInfo->pResult[j] != pResultRowInfo->current; ++j) { SResultRow* pRes = pResultRowInfo->pResult[j]; if (pRes->closed) { assert(resultRowInterpolated(pRes, RESULT_ROW_START_INTERP) && resultRowInterpolated(pRes, RESULT_ROW_END_INTERP)); @@ -3146,7 +3155,7 @@ void copyToSDataBlock(SQueryRuntimeEnv* pRuntimeEnv, int32_t threshold, SSDataBl } -static void updateTableQueryInfoForReverseScan(SQueryAttr *pQueryAttr, STableQueryInfo *pTableQueryInfo) { +static void updateTableQueryInfoForReverseScan(STableQueryInfo *pTableQueryInfo) { if (pTableQueryInfo == NULL) { return; } @@ -3158,7 +3167,12 @@ static void updateTableQueryInfoForReverseScan(SQueryAttr *pQueryAttr, STableQue pTableQueryInfo->cur.vgroupIndex = -1; // set the index to be the end slot of result rows array - pTableQueryInfo->resInfo.curIndex = pTableQueryInfo->resInfo.size - 1; + SResultRowInfo* pResRowInfo = &pTableQueryInfo->resInfo; + if (pResRowInfo->size > 0) { + pResRowInfo->current = pResRowInfo->pResult[pResRowInfo->size - 1]; + } else { + pResRowInfo->current = NULL; + } } static void setupQueryRangeForReverseScan(SQueryRuntimeEnv* pRuntimeEnv) { @@ -3172,7 +3186,7 @@ static void setupQueryRangeForReverseScan(SQueryRuntimeEnv* pRuntimeEnv) { size_t t = taosArrayGetSize(group); for (int32_t j = 0; j < t; ++j) { STableQueryInfo *pCheckInfo = taosArrayGetP(group, j); - updateTableQueryInfoForReverseScan(pQueryAttr, pCheckInfo); + updateTableQueryInfoForReverseScan(pCheckInfo); // update the last key in tableKeyInfo list, the tableKeyInfo is used to build the tsdbQueryHandle and decide // the start check timestamp of tsdbQueryHandle @@ -4571,7 +4585,7 @@ static SSDataBlock* doTableScan(void* param, bool *newgroup) { } if (pResultRowInfo->size > 0) { - pResultRowInfo->curIndex = 0; + pResultRowInfo->current = pResultRowInfo->pResult[0]; pResultRowInfo->prevSKey = pResultRowInfo->pResult[0]->win.skey; } @@ -4597,8 +4611,8 @@ static SSDataBlock* doTableScan(void* param, bool *newgroup) { pTableScanInfo->order = cond.order; if (pResultRowInfo->size > 0) { - pResultRowInfo->curIndex = pResultRowInfo->size-1; - pResultRowInfo->prevSKey = pResultRowInfo->pResult[pResultRowInfo->size-1]->win.skey; + pResultRowInfo->current = pResultRowInfo->pResult[pResultRowInfo->size - 1]; + pResultRowInfo->prevSKey = pResultRowInfo->current->win.skey; } p = doTableScanImpl(pOperator, newgroup); diff --git a/src/query/src/qUtil.c b/src/query/src/qUtil.c index 7b08450d3b..7c5a95312e 100644 --- a/src/query/src/qUtil.c +++ b/src/query/src/qUtil.c @@ -45,7 +45,7 @@ int32_t initResultRowInfo(SResultRowInfo *pResultRowInfo, int32_t size, int16_t pResultRowInfo->type = type; pResultRowInfo->size = 0; pResultRowInfo->prevSKey = TSKEY_INITIAL_VAL; - pResultRowInfo->curIndex = -1; + pResultRowInfo->current = NULL; pResultRowInfo->capacity = size; pResultRowInfo->pResult = calloc(pResultRowInfo->capacity, POINTER_BYTES); @@ -90,9 +90,9 @@ void resetResultRowInfo(SQueryRuntimeEnv *pRuntimeEnv, SResultRowInfo *pResultRo SET_RES_WINDOW_KEY(pRuntimeEnv->keyBuf, &groupIndex, sizeof(groupIndex), uid); taosHashRemove(pRuntimeEnv->pResultRowHashTable, (const char *)pRuntimeEnv->keyBuf, GET_RES_WINDOW_KEY_LEN(sizeof(groupIndex))); } - - pResultRowInfo->curIndex = -1; - pResultRowInfo->size = 0; + + pResultRowInfo->size = 0; + pResultRowInfo->current = NULL; pResultRowInfo->prevSKey = TSKEY_INITIAL_VAL; } From 82998b12ba0a122925cc590a7e31a4f7d4773e07 Mon Sep 17 00:00:00 2001 From: wpan Date: Thu, 8 Jul 2021 13:26:58 +0800 Subject: [PATCH 09/13] fix bool hash issue --- src/util/src/thashutil.c | 41 +++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/src/util/src/thashutil.c b/src/util/src/thashutil.c index ffe167977b..4a0208a3d0 100644 --- a/src/util/src/thashutil.c +++ b/src/util/src/thashutil.c @@ -126,15 +126,38 @@ _hash_fn_t taosGetDefaultHashFunction(int32_t type) { _hash_fn_t fn = NULL; switch(type) { case TSDB_DATA_TYPE_TIMESTAMP: - case TSDB_DATA_TYPE_BIGINT: fn = taosIntHash_64;break; - case TSDB_DATA_TYPE_BINARY: fn = MurmurHash3_32;break; - case TSDB_DATA_TYPE_NCHAR: fn = MurmurHash3_32;break; - case TSDB_DATA_TYPE_INT: fn = taosIntHash_32; break; - case TSDB_DATA_TYPE_SMALLINT: fn = taosIntHash_16; break; - case TSDB_DATA_TYPE_TINYINT: fn = taosIntHash_8; break; - case TSDB_DATA_TYPE_FLOAT: fn = taosFloatHash; break; - case TSDB_DATA_TYPE_DOUBLE: fn = taosDoubleHash; break; - default: fn = taosIntHash_32;break; + case TSDB_DATA_TYPE_UBIGINT: + case TSDB_DATA_TYPE_BIGINT: + fn = taosIntHash_64; + break; + case TSDB_DATA_TYPE_BINARY: + fn = MurmurHash3_32; + break; + case TSDB_DATA_TYPE_NCHAR: + fn = MurmurHash3_32; + break; + case TSDB_DATA_TYPE_UINT: + case TSDB_DATA_TYPE_INT: + fn = taosIntHash_32; + break; + case TSDB_DATA_TYPE_SMALLINT: + case TSDB_DATA_TYPE_USMALLINT: + fn = taosIntHash_16; + break; + case TSDB_DATA_TYPE_BOOL: + case TSDB_DATA_TYPE_UTINYINT: + case TSDB_DATA_TYPE_TINYINT: + fn = taosIntHash_8; + break; + case TSDB_DATA_TYPE_FLOAT: + fn = taosFloatHash; + break; + case TSDB_DATA_TYPE_DOUBLE: + fn = taosDoubleHash; + break; + default: + fn = taosIntHash_32; + break; } return fn; From f40ebe0e407f70e4919a37eacf2e1a8fd8b2c84f Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 8 Jul 2021 14:05:56 +0800 Subject: [PATCH 10/13] [td-225] fix bug caused by code refactor. --- src/query/src/qExecutor.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 7089760e35..76ee5c3860 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -411,6 +411,21 @@ static void prepareResultListBuffer(SResultRowInfo* pResultRowInfo, SQueryRuntim pResultRowInfo->capacity = (int32_t)newCapacity; } +static int32_t ascResultRowCompareFn(const void* p1, const void* p2) { + SResultRow* pRow1 = *(SResultRow**)p1; + SResultRow* pRow2 = *(SResultRow**)p2; + + if (pRow1 == pRow2) { + return 0; + } else { + return pRow1->win.skey < pRow2->win.skey? -1:1; + } +} + +static int32_t descResultRowCompareFn(const void* p1, const void* p2) { + return -ascResultRowCompareFn(p1, p2); +} + static SResultRow *doPrepareResultRowFromKey(SQueryRuntimeEnv *pRuntimeEnv, SResultRowInfo *pResultRowInfo, char *pData, int16_t bytes, bool masterscan, uint64_t uid) { bool existed = false; @@ -427,7 +442,18 @@ static SResultRow *doPrepareResultRowFromKey(SQueryRuntimeEnv *pRuntimeEnv, SRes if (p1 != NULL) { pResultRowInfo->current = (*p1); - existed = true; + + if (pResultRowInfo->size == 0) { + existed = false; + } else if (pResultRowInfo->size == 1) { + existed = (pResultRowInfo->pResult[0] == (*p1)); + } else { + __compar_fn_t fn = QUERY_IS_ASC_QUERY(pRuntimeEnv->pQueryAttr)? ascResultRowCompareFn:descResultRowCompareFn; + void* ptr = taosbsearch(p1, pResultRowInfo->pResult, pResultRowInfo->size, POINTER_BYTES, fn, TD_EQ); + if (ptr != NULL) { + existed = true; + } + } } } else { if (p1 != NULL) { // group by column query From 7fdffa08d2ff37f9682006956e7f9d46feadfc43 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Thu, 8 Jul 2021 15:21:20 +0800 Subject: [PATCH 11/13] [TD-5128]: odbc compile failed. (#6804) --- src/connector/odbc/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/connector/odbc/CMakeLists.txt b/src/connector/odbc/CMakeLists.txt index 5a93ac3f7e..dd10fff1b7 100644 --- a/src/connector/odbc/CMakeLists.txt +++ b/src/connector/odbc/CMakeLists.txt @@ -20,8 +20,8 @@ IF (TD_LINUX_64) if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS 5.0.0) message(WARNING "gcc 4.8.0 will complain too much about flex-generated code, we just bypass building ODBC driver in such case") else () - SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wconversion") - SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wconversion") + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ") + SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ") ADD_SUBDIRECTORY(src) ADD_SUBDIRECTORY(tools) ADD_SUBDIRECTORY(examples) From 3d7b4e431efa081a7c729cfb0b81a45ed3c1b908 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Thu, 8 Jul 2021 15:32:17 +0800 Subject: [PATCH 12/13] [td-225]fix compiler error. --- src/query/src/qExecutor.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 76ee5c3860..c8834a1574 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -5366,16 +5366,9 @@ static SSDataBlock* doIntervalAgg(void* param, bool* newgroup) { SOperatorInfo* upstream = pOperator->upstream[0]; - int64_t ss = taosGetTimestampMs(); - printf("=-=============%ld\n", ss); while(1) { publishOperatorProfEvent(upstream, QUERY_PROF_BEFORE_OPERATOR_EXEC); - int64_t s = taosGetTimestampMs(); - printf("start: %ld\n", s); SSDataBlock* pBlock = upstream->exec(upstream, newgroup); - - int64_t end = taosGetTimestampMs(); - printf("end: %ld, el:%ld \n", end, end - s); publishOperatorProfEvent(upstream, QUERY_PROF_AFTER_OPERATOR_EXEC); if (pBlock == NULL) { @@ -5384,16 +5377,9 @@ static SSDataBlock* doIntervalAgg(void* param, bool* newgroup) { // the pDataBlock are always the same one, no need to call this again setInputDataBlock(pOperator, pIntervalInfo->pCtx, pBlock, pQueryAttr->order.order); - - int64_t x1 = taosGetTimestampMs(); hashIntervalAgg(pOperator, &pIntervalInfo->resultRowInfo, pBlock, 0); - int64_t x2 = taosGetTimestampMs(); - printf("-------------------------inter:%ld\n", x2-x1); } - int64_t s1 = taosGetTimestampMs(); - printf("=-=============%ld, el:%ld\n", s1, s1-ss); - // restore the value pQueryAttr->order.order = order; pQueryAttr->window = win; From 1e63299aeb9e6bc77b1caaf9c9eed860cc871b86 Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Thu, 8 Jul 2021 15:59:26 +0800 Subject: [PATCH 13/13] Revert "[TD-5108]: CI support lua (#6798)" (#6807) This reverts commit ad23a6979fe11ea76eadf85f197c51d41d1f38d3. --- .appveyor.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 83ef67c352..e7802b3d0d 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -22,7 +22,6 @@ for: - call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" %ARCH% before_build: - - choco install lua - cd c:\dev\TDengine - md build @@ -36,9 +35,6 @@ for: - image: macos clone_depth: 1 - before_build: - - brew install lua - build_script: - mkdir debug - cd debug