diff --git a/src/client/src/tscFunctionImpl.c b/src/client/src/tscFunctionImpl.c index c1944e96c94372f19e9fc499630cd94083ac30fa..6fb8df24441907fde789748bfeeaa6a6eb67fac3 100644 --- a/src/client/src/tscFunctionImpl.c +++ b/src/client/src/tscFunctionImpl.c @@ -1691,10 +1691,7 @@ static void last_function(SQLFunctionCtx *pCtx) { } static void last_function_f(SQLFunctionCtx *pCtx, int32_t index) { - if (pCtx->order == TSDB_ORDER_ASC) { - return; - } - + assert(pCtx->order != TSDB_ORDER_ASC); void *pData = GET_INPUT_CHAR_INDEX(pCtx, index); if (pCtx->hasNull && isNull(pData, pCtx->inputType)) { return; @@ -2912,7 +2909,7 @@ static void leastsquares_finalizer(SQLFunctionCtx *pCtx) { } static void date_col_output_function(SQLFunctionCtx *pCtx) { - if (pCtx->scanFlag == SUPPLEMENTARY_SCAN) { + if (pCtx->scanFlag == REVERSE_SCAN) { return; } @@ -2969,11 +2966,12 @@ static void tag_project_function(SQLFunctionCtx *pCtx) { char* output = pCtx->aOutputBuf; if (pCtx->tag.nType == TSDB_DATA_TYPE_BINARY || pCtx->tag.nType == TSDB_DATA_TYPE_NCHAR) { - *(int16_t*) output = pCtx->tag.nLen; - output += VARSTR_HEADER_SIZE; + varDataSetLen(output, pCtx->tag.nLen); + tVariantDump(&pCtx->tag, varDataVal(output), pCtx->outputType); + } else { + tVariantDump(&pCtx->tag, output, pCtx->outputType); } - tVariantDump(&pCtx->tag, output, pCtx->outputType); pCtx->aOutputBuf += pCtx->outputBytes; } } diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 4cc03f7ad9d04c4bd48c44d2f0563edecdc394cf..4ef24e7335e55ad205c7aba3c7ccd05bb9e1d6ee 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -5911,7 +5911,7 @@ int32_t exprTreeFromSqlExpr(tExprNode **pExpr, const tSQLExpr* pSqlExpr, SArray* } if (pSqlExpr->pLeft == NULL) { - if (pSqlExpr->nSQLOptr >= TK_TINYINT && pSqlExpr->nSQLOptr <= TK_DOUBLE) { + if (pSqlExpr->nSQLOptr >= TK_BOOL && pSqlExpr->nSQLOptr <= TK_STRING) { *pExpr = calloc(1, sizeof(tExprNode)); (*pExpr)->nodeType = TSQL_NODE_VALUE; (*pExpr)->pVal = calloc(1, sizeof(tVariant)); diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 119a84e964f70bfa061d1b245e483eaf2210dd25..8efe89d28ab497ea7a442b412845d9b54172dce6 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -492,13 +492,15 @@ int tscBuildFetchMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pMsg += sizeof(pQueryInfo->type); // todo valid the vgroupId at the client side - if (UTIL_TABLE_IS_SUPERTABLE(pQueryInfo->pTableMetaInfo[0])) { - SVgroupsInfo* pVgroupInfo = pQueryInfo->pTableMetaInfo[0]->vgroupList; - assert(pVgroupInfo->numOfVgroups == 1); // todo fix me + STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); + + if (UTIL_TABLE_IS_SUPERTABLE(pTableMetaInfo)) { + int32_t vgIndex = pTableMetaInfo->vgroupIndex; - pRetrieveMsg->header.vgId = htonl(pVgroupInfo->vgroups[0].vgId); + SVgroupsInfo* pVgroupInfo = pTableMetaInfo->vgroupList; + pRetrieveMsg->header.vgId = htonl(pVgroupInfo->vgroups[vgIndex].vgId); } else { - STableMeta* pTableMeta = pQueryInfo->pTableMetaInfo[0]->pTableMeta; + STableMeta* pTableMeta = pTableMetaInfo->pTableMeta; pRetrieveMsg->header.vgId = htonl(pTableMeta->vgroupInfo.vgId); } diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index d3a81adca6dc8fa48dcbbff8d95960f43e0caa1d..7a1c08d0563ecabd9d4a3cbd00ea622d8e5fe02b 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -1436,8 +1436,8 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO return; } else { // reach the maximum retry count, abort atomic_val_compare_exchange_32(&pState->code, TSDB_CODE_SUCCESS, numOfRows); - tscError("%p sub:%p retrieve failed,code:%d,orderOfSub:%d failed.no more retry,set global code:%d", pPObj, pSql, - numOfRows, subqueryIndex, tstrerror(pState->code)); + tscError("%p sub:%p retrieve failed,code:%s,orderOfSub:%d failed.no more retry,set global code:%s", pPObj, pSql, + tstrerror(numOfRows), subqueryIndex, tstrerror(pState->code)); } } @@ -1450,7 +1450,7 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO } // all subqueries are failed - tscError("%p retrieve from %d vnode(s) completed,code:%d.FAILED.", pPObj, pState->numOfTotal, pState->code); + tscError("%p retrieve from %d vnode(s) completed,code:%s.FAILED.", pPObj, pState->numOfTotal, tstrerror(pState->code)); pPObj->res.code = pState->code; // release allocated resource diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index dd3cb76cbf40876718786dae14dbb5a7b263d8c7..00afb977fd9390e9f063a0dd72a9ac74073d3c9f 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -1675,10 +1675,7 @@ STableMetaInfo* tscAddTableMetaInfo(SQueryInfo* pQueryInfo, const char* name, ST pTableMetaInfo->pTableMeta = pTableMeta; if (vgroupList != NULL) { - assert(vgroupList->numOfVgroups == 1); // todo fix me - size_t size = sizeof(SVgroupsInfo) + sizeof(SCMVgroupInfo) * vgroupList->numOfVgroups; - pTableMetaInfo->vgroupList = malloc(size); memcpy(pTableMetaInfo->vgroupList, vgroupList, size); } diff --git a/src/common/inc/tdataformat.h b/src/common/inc/tdataformat.h index ec52bcd2ae34acf04806727fddf5a24dfcb260ef..51a5dad4869f3d464d83397157d9fda4482dc6a9 100644 --- a/src/common/inc/tdataformat.h +++ b/src/common/inc/tdataformat.h @@ -115,10 +115,8 @@ static FORCE_INLINE void *tdGetRowDataOfCol(SDataRow row, int8_t type, int32_t o case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_NCHAR: return POINTER_SHIFT(row, *(VarDataOffsetT *)POINTER_SHIFT(row, offset)); - break; default: return POINTER_SHIFT(row, offset); - break; } } diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h index 571b551368c8139a7527965deb1549ac479866a4..33a0e4f2c6e12b7e67e6ba58fb833846f05e9044 100644 --- a/src/inc/taosdef.h +++ b/src/inc/taosdef.h @@ -36,6 +36,11 @@ extern "C" { typedef int32_t VarDataOffsetT; typedef int16_t VarDataLenT; +typedef struct tstr { + VarDataLenT len; + char data[]; +} tstr; + #define VARSTR_HEADER_SIZE sizeof(VarDataLenT) #define varDataLen(v) ((VarDataLenT *)(v))[0] @@ -74,10 +79,10 @@ extern const int32_t TYPE_BYTES[11]; #define TSDB_DATA_NULL_STR "NULL" #define TSDB_DATA_NULL_STR_L "null" -#define TSDB_TRUE 1 -#define TSDB_FALSE 0 -#define TSDB_OK 0 -#define TSDB_ERR -1 +#define TSDB_TRUE 1 +#define TSDB_FALSE 0 +#define TSDB_OK 0 +#define TSDB_ERR -1 #define TS_PATH_DELIMITER "." diff --git a/src/inc/tsdb.h b/src/inc/tsdb.h index f4242fbe1fbb72fbbf1e189100c6d9e0fd3d4676..77a0e23af9400efc601badc974998ec83232e4ad 100644 --- a/src/inc/tsdb.h +++ b/src/inc/tsdb.h @@ -102,7 +102,7 @@ int tsdbTableSetSName(STableCfg *config, char *sname, bool dup); void tsdbClearTableCfg(STableCfg *config); int32_t tsdbGetTableTagVal(TsdbRepoT *repo, STableId* id, int32_t colId, int16_t *type, int16_t *bytes, char **val); -int32_t tsdbGetTableName(TsdbRepoT *repo, STableId* id, char** name); +char* tsdbGetTableName(TsdbRepoT *repo, const STableId* id, int16_t* bytes); int tsdbCreateTable(TsdbRepoT *repo, STableCfg *pCfg); int tsdbDropTable(TsdbRepoT *pRepo, STableId tableId); diff --git a/src/query/inc/queryExecutor.h b/src/query/inc/queryExecutor.h index 906dadb31798b2a48b0ebb142c613511a49dee65..2088e5a49ddd4d249effdc915234c70efff961cc 100644 --- a/src/query/inc/queryExecutor.h +++ b/src/query/inc/queryExecutor.h @@ -110,6 +110,14 @@ typedef struct STableQueryInfo { // todo merge with the STableQueryInfo struct SWindowResInfo windowResInfo; } STableQueryInfo; +typedef struct SQueryCostSummary { +} SQueryCostSummary; + +typedef struct SGroupItem { + STableId id; + STableQueryInfo* info; +} SGroupItem; + typedef struct SQuery { int16_t numOfCols; int16_t numOfTags; @@ -131,17 +139,15 @@ typedef struct SQuery { SColumnInfo* tagColList; int32_t numOfFilterCols; int64_t* defaultVal; - TSKEY lastKey; +// TSKEY lastKey; uint32_t status; // query status SResultRec rec; int32_t pos; SData** sdata; + STableQueryInfo* current; SSingleColumnFilterInfo* pFilterInfo; } SQuery; -typedef struct SQueryCostSummary { -} SQueryCostSummary; - typedef struct SQueryRuntimeEnv { SResultInfo* resultInfo; // todo refactor to merge with SWindowResInfo SQuery* pQuery; diff --git a/src/query/inc/tsqlfunction.h b/src/query/inc/tsqlfunction.h index a92f401323ad4d63cf9141d9fb7c0cdb569f6628..a11c03f2c0da8db902d6f24ba70fea56b37385f2 100644 --- a/src/query/inc/tsqlfunction.h +++ b/src/query/inc/tsqlfunction.h @@ -104,7 +104,7 @@ extern "C" { enum { MASTER_SCAN = 0x0u, - SUPPLEMENTARY_SCAN = 0x1u, + REVERSE_SCAN = 0x1u, REPEAT_SCAN = 0x2u, //repeat scan belongs to the master scan FIRST_STAGE_MERGE = 0x10u, SECONDARY_STAGE_MERGE = 0x20u, diff --git a/src/query/src/qast.c b/src/query/src/qast.c index 98682ce778976a1472317d8e8adf1c289411f862..01099b2c3bbc430403eecdcc706984ced76659db 100644 --- a/src/query/src/qast.c +++ b/src/query/src/qast.c @@ -552,18 +552,18 @@ static void tQueryIndexColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, SArr if (cond.start != NULL) { int32_t optr = cond.start->optr; - if (optr == TSDB_RELATION_EQUAL) { + if (optr == TSDB_RELATION_EQUAL) { // equals while(tSkipListIterNext(iter)) { SSkipListNode* pNode = tSkipListIterGet(iter); int32_t ret = pQueryInfo->compare(SL_GET_NODE_KEY(pSkipList, pNode), cond.start->v); - if (ret == 0) { - taosArrayPush(result, SL_GET_NODE_DATA(pNode)); - } else { + if (ret != 0) { break; } + + taosArrayPush(result, SL_GET_NODE_DATA(pNode)); } - } else if (optr == TSDB_RELATION_GREATER || optr == TSDB_RELATION_GREATER_EQUAL) { + } else if (optr == TSDB_RELATION_GREATER || optr == TSDB_RELATION_GREATER_EQUAL) { // greater equal bool comp = true; int32_t ret = 0; @@ -582,8 +582,33 @@ static void tQueryIndexColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, SArr comp = false; } } - } else if (optr == TSDB_RELATION_NOT_EQUAL) { - assert(0); + } else if (optr == TSDB_RELATION_NOT_EQUAL) { // not equal + bool comp = true; + + while(tSkipListIterNext(iter)) { + SSkipListNode* pNode = tSkipListIterGet(iter); + comp = comp && (pQueryInfo->compare(SL_GET_NODE_KEY(pSkipList, pNode), cond.start->v) == 0); + if (comp) { + continue; + } + + taosArrayPush(result, SL_GET_NODE_DATA(pNode)); + } + + tSkipListDestroyIter(iter); + + comp = true; + iter = tSkipListCreateIterFromVal(pSkipList, (char*) cond.start->v, pSkipList->keyInfo.type, TSDB_ORDER_DESC); + while(tSkipListIterNext(iter)) { + SSkipListNode* pNode = tSkipListIterGet(iter); + comp = comp && (pQueryInfo->compare(SL_GET_NODE_KEY(pSkipList, pNode), cond.start->v) == 0); + if (comp) { + continue; + } + + taosArrayPush(result, SL_GET_NODE_DATA(pNode)); + } + } else { assert(0); } @@ -773,8 +798,6 @@ static void tSQLBinaryTraverseOnSkipList(tExprNode *pExpr, SArray *pResult, SSki tSkipListDestroyIter(iter); } - - static void tQueryIndexlessColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, SArray* result) { SSkipListIterator* iter = tSkipListCreateIter(pSkipList); @@ -785,7 +808,7 @@ static void tQueryIndexlessColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, char* pTable = SL_GET_NODE_DATA(pNode); //todo refactor: - char* name = (*(STable**) pTable)->name; + tstr* name = ((STableIndexElem*) pTable)->pTable->name; // char* name = NULL; // tsdbGetTableName(tsdb, pTable, &name); diff --git a/src/query/src/queryExecutor.c b/src/query/src/queryExecutor.c index 0ffc665e553c6f19046057d0a79a7be1678ef693..52cfa582d080fed6816fd32f3d9457f5a946e851 100644 --- a/src/query/src/queryExecutor.c +++ b/src/query/src/queryExecutor.c @@ -40,9 +40,9 @@ #define QUERY_IS_ASC_QUERY(q) (GET_FORWARD_DIRECTION_FACTOR((q)->order.order) == QUERY_ASC_FORWARD_STEP) #define IS_MASTER_SCAN(runtime) ((runtime)->scanFlag == MASTER_SCAN) -#define IS_REVERSE_SCAN(runtime) ((runtime)->scanFlag == SUPPLEMENTARY_SCAN) +#define IS_REVERSE_SCAN(runtime) ((runtime)->scanFlag == REVERSE_SCAN) #define SET_MASTER_SCAN_FLAG(runtime) ((runtime)->scanFlag = MASTER_SCAN) -#define SET_REVERSE_SCAN_FLAG(runtime) ((runtime)->scanFlag = SUPPLEMENTARY_SCAN) +#define SET_REVERSE_SCAN_FLAG(runtime) ((runtime)->scanFlag = REVERSE_SCAN) #define GET_QINFO_ADDR(x) ((void *)((char *)(x)-offsetof(SQInfo, runtimeEnv))) @@ -96,11 +96,6 @@ typedef struct { STSCursor cur; } SQueryStatusInfo; -typedef struct SGroupItem { - STableId id; - STableQueryInfo* info; -} SGroupItem; - static void setQueryStatus(SQuery *pQuery, int8_t status); static bool isIntervalQuery(SQuery *pQuery) { return pQuery->intervalTime > 0; } @@ -121,7 +116,7 @@ static bool hasMainOutput(SQuery *pQuery); static void createTableQueryInfo(SQInfo *pQInfo); static void buildTagQueryResult(SQInfo *pQInfo); -static int32_t setAdditionalInfo(SQInfo *pQInfo, STableId *pTaleId, STableQueryInfo *pTableQueryInfo); +static int32_t setAdditionalInfo(SQInfo *pQInfo, STableId *pTableId, STableQueryInfo *pTableQueryInfo); static int32_t flushFromResultBuf(SQInfo *pQInfo); bool getNeighborPoints(SQInfo *pQInfo, void *pMeterObj, SPointInterpoSupporter *pPointInterpSupporter) { @@ -428,9 +423,10 @@ static bool hasNullValue(SQuery *pQuery, int32_t col, SDataBlockInfo *pDataBlock return false; } - *pColStatis = NULL; if (pStatis != NULL) { *pColStatis = getStatisInfo(pQuery, pStatis, pDataBlockInfo, col); + } else { + *pColStatis = NULL; } if ((*pColStatis) != NULL && (*pColStatis)->numOfNull == 0) { @@ -620,8 +616,8 @@ static void doCheckQueryCompleted(SQueryRuntimeEnv *pRuntimeEnv, TSKEY lastKey, } // query completed - if ((lastKey >= pQuery->window.ekey && QUERY_IS_ASC_QUERY(pQuery)) || - (lastKey <= pQuery->window.ekey && !QUERY_IS_ASC_QUERY(pQuery))) { + if ((lastKey >= pQuery->current->win.ekey && QUERY_IS_ASC_QUERY(pQuery)) || + (lastKey <= pQuery->current->win.ekey && !QUERY_IS_ASC_QUERY(pQuery))) { closeAllTimeWindow(pWindowResInfo); pWindowResInfo->curIndex = pWindowResInfo->size - 1; @@ -661,22 +657,22 @@ static void doCheckQueryCompleted(SQueryRuntimeEnv *pRuntimeEnv, TSKEY lastKey, setQueryStatus(pQuery, QUERY_RESBUF_FULL); } - qTrace("QInfo:%p total window:%d, closed:%d", GET_QINFO_ADDR(pQuery), pWindowResInfo->size, n); + qTrace("QInfo:%p total window:%d, closed:%d", GET_QINFO_ADDR(pRuntimeEnv), pWindowResInfo->size, n); } assert(pWindowResInfo->prevSKey != 0); } static int32_t getNumOfRowsInTimeWindow(SQuery *pQuery, SDataBlockInfo *pDataBlockInfo, TSKEY *pPrimaryColumn, - int32_t startPos, TSKEY ekey, __block_search_fn_t searchFn, - bool updateLastKey) { + int32_t startPos, TSKEY ekey, __block_search_fn_t searchFn, bool updateLastKey) { assert(startPos >= 0 && startPos < pDataBlockInfo->rows); int32_t num = -1; int32_t order = pQuery->order.order; - int32_t step = GET_FORWARD_DIRECTION_FACTOR(order); + STableQueryInfo* item = pQuery->current; + if (QUERY_IS_ASC_QUERY(pQuery)) { if (ekey < pDataBlockInfo->window.ekey) { num = getForwardStepsInBlock(pDataBlockInfo->rows, searchFn, ekey, startPos, order, pPrimaryColumn); @@ -684,13 +680,13 @@ static int32_t getNumOfRowsInTimeWindow(SQuery *pQuery, SDataBlockInfo *pDataBlo assert(ekey < pPrimaryColumn[startPos]); } else { if (updateLastKey) { - pQuery->lastKey = pPrimaryColumn[startPos + (num - 1)] + step; + item->lastKey = pPrimaryColumn[startPos + (num - 1)] + step; } } } else { num = pDataBlockInfo->rows - startPos; if (updateLastKey) { - pQuery->lastKey = pDataBlockInfo->window.ekey + step; + item->lastKey = pDataBlockInfo->window.ekey + step; } } } else { // desc @@ -700,13 +696,13 @@ static int32_t getNumOfRowsInTimeWindow(SQuery *pQuery, SDataBlockInfo *pDataBlo assert(ekey > pPrimaryColumn[startPos]); } else { if (updateLastKey) { - pQuery->lastKey = pPrimaryColumn[startPos - (num - 1)] + step; + item->lastKey = pPrimaryColumn[startPos - (num - 1)] + step; } } } else { num = startPos + 1; if (updateLastKey) { - pQuery->lastKey = pDataBlockInfo->window.skey + step; + item->lastKey = pDataBlockInfo->window.skey + step; } } } @@ -820,7 +816,21 @@ static TSKEY reviseWindowEkey(SQuery *pQuery, STimeWindow *pWindow) { return ekey; } -char *getDataBlocks(SQueryRuntimeEnv *pRuntimeEnv, SArithmeticSupport *sas, int32_t col, int32_t size, +//todo binary search +static void* getDataBlockImpl(SArray* pDataBlock, int32_t colId) { + int32_t numOfCols = taosArrayGetSize(pDataBlock); + + for (int32_t i = 0; i < numOfCols; ++i) { + SColumnInfoData *p = taosArrayGet(pDataBlock, i); + if (colId == p->info.colId) { + return p->pData; + } + } + + return NULL; +} + +static char *getDataBlock(SQueryRuntimeEnv *pRuntimeEnv, SArithmeticSupport *sas, int32_t col, int32_t size, SArray *pDataBlock) { char *dataBlock = NULL; SQuery *pQuery = pRuntimeEnv->pQuery; @@ -867,20 +877,7 @@ char *getDataBlocks(SQueryRuntimeEnv *pRuntimeEnv, SArithmeticSupport *sas, int3 if (TSDB_COL_IS_TAG(pCol->flag) || pDataBlock == NULL) { dataBlock = NULL; } else { - /* - * the colIndex is acquired from the first meter of all qualified meters in this vnode during query prepare - * stage, the remain meter may not have the required column in cache actually. So, the validation of required - * column in cache with the corresponding meter schema is reinforced. - */ - int32_t numOfCols = taosArrayGetSize(pDataBlock); - - for (int32_t i = 0; i < numOfCols; ++i) { - SColumnInfoData *p = taosArrayGet(pDataBlock, i); - if (pCol->colId == p->info.colId) { - dataBlock = p->pData; - break; - } - } + dataBlock = getDataBlockImpl(pDataBlock, pCol->colId); } } @@ -904,8 +901,8 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis * SQuery * pQuery = pRuntimeEnv->pQuery; SColumnInfoData *pColInfo = NULL; - TSKEY * primaryKeyCol = NULL; - + + TSKEY *primaryKeyCol = NULL; if (pDataBlock != NULL) { pColInfo = taosArrayGet(pDataBlock, 0); primaryKeyCol = (TSKEY *)(pColInfo->pData); @@ -919,7 +916,7 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis * SDataStatis *tpField = NULL; bool hasNull = hasNullValue(pQuery, k, pDataBlockInfo, pStatis, &tpField); - char *dataBlock = getDataBlocks(pRuntimeEnv, &sasArray[k], k, pDataBlockInfo->rows, pDataBlock); + char *dataBlock = getDataBlock(pRuntimeEnv, &sasArray[k], k, pDataBlockInfo->rows, pDataBlock); setExecParams(pQuery, &pCtx[k], dataBlock, primaryKeyCol, pDataBlockInfo->rows, functionId, tpField, hasNull, &sasArray[k], pRuntimeEnv->scanFlag); @@ -1095,15 +1092,20 @@ static int32_t doTSJoinFilter(SQueryRuntimeEnv *pRuntimeEnv, int32_t offset) { static bool functionNeedToExecute(SQueryRuntimeEnv *pRuntimeEnv, SQLFunctionCtx *pCtx, int32_t functionId) { SResultInfo *pResInfo = GET_RES_INFO(pCtx); - + SQuery* pQuery = pRuntimeEnv->pQuery; + if (pResInfo->complete || functionId == TSDB_FUNC_TAG_DUMMY || functionId == TSDB_FUNC_TS_DUMMY) { return false; } + if (functionId == TSDB_FUNC_LAST_DST || functionId == TSDB_FUNC_LAST) { + return !QUERY_IS_ASC_QUERY(pQuery); + } else if (functionId == TSDB_FUNC_FIRST_DST || functionId == TSDB_FUNC_FIRST) { + return QUERY_IS_ASC_QUERY(pQuery); + } + // in the supplementary scan, only the following functions need to be executed - if (IS_REVERSE_SCAN(pRuntimeEnv) && - !(functionId == TSDB_FUNC_LAST_DST || functionId == TSDB_FUNC_FIRST_DST || functionId == TSDB_FUNC_FIRST || - functionId == TSDB_FUNC_LAST || functionId == TSDB_FUNC_TAG || functionId == TSDB_FUNC_TS)) { + if (IS_REVERSE_SCAN(pRuntimeEnv)) {// && (functionId == TSDB_FUNC_TAG || functionId == TSDB_FUNC_TS)) { return false; } @@ -1115,9 +1117,10 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS SQLFunctionCtx *pCtx = pRuntimeEnv->pCtx; SQuery *pQuery = pRuntimeEnv->pQuery; + STableQueryInfo* item = pQuery->current; + TSKEY *primaryKeyCol = (TSKEY*) ((SColumnInfoData *)taosArrayGet(pDataBlock, 0))->pData; - - bool groupbyStateValue = isGroupbyNormalCol(pQuery->pGroupbyExpr); + bool groupbyStateValue = isGroupbyNormalCol(pQuery->pGroupbyExpr); SArithmeticSupport *sasArray = calloc((size_t)pQuery->numOfOutput, sizeof(SArithmeticSupport)); int16_t type = 0; @@ -1134,7 +1137,7 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS SDataStatis *pColStatis = NULL; bool hasNull = hasNullValue(pQuery, k, pDataBlockInfo, pStatis, &pColStatis); - char *dataBlock = getDataBlocks(pRuntimeEnv, &sasArray[k], k, pDataBlockInfo->rows, pDataBlock); + char *dataBlock = getDataBlock(pRuntimeEnv, &sasArray[k], k, pDataBlockInfo->rows, pDataBlock); setExecParams(pQuery, &pCtx[k], dataBlock, primaryKeyCol, pDataBlockInfo->rows, functionId, pColStatis, hasNull, &sasArray[k], pRuntimeEnv->scanFlag); @@ -1143,7 +1146,8 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS // set the input column data for (int32_t k = 0; k < pQuery->numOfFilterCols; ++k) { SSingleColumnFilterInfo *pFilterInfo = &pQuery->pFilterInfo[k]; - pFilterInfo->pData = getDataBlocks(pRuntimeEnv, &sasArray[k], pFilterInfo->info.colId, pDataBlockInfo->rows, pDataBlock); + pFilterInfo->pData = getDataBlockImpl(pDataBlock, pFilterInfo->info.colId); + assert(pFilterInfo->pData != NULL); } int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQuery->order.order); @@ -1157,10 +1161,10 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS } int32_t j = 0; - TSKEY lastKey = -1; - + int32_t offset = -1; + for (j = 0; j < pDataBlockInfo->rows; ++j) { - int32_t offset = GET_COL_DATA_POS(pQuery, j, step); + offset = GET_COL_DATA_POS(pQuery, j, step); if (pRuntimeEnv->pTSBuf != NULL) { int32_t r = doTSJoinFilter(pRuntimeEnv, offset); @@ -1194,7 +1198,6 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS SWindowStatus *pStatus = getTimeWindowResStatus(pWindowResInfo, curTimeWindow(pWindowResInfo)); doRowwiseApplyFunctions(pRuntimeEnv, pStatus, &win, offset); - lastKey = ts; STimeWindow nextWin = win; int32_t index = pWindowResInfo->curIndex; @@ -1223,17 +1226,14 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS } else { // other queries // decide which group this rows belongs to according to current state value if (groupbyStateValue) { - char *stateVal = groupbyColumnData + bytes * offset; + char *val = groupbyColumnData + bytes * offset; - int32_t ret = setGroupResultOutputBuf(pRuntimeEnv, stateVal, type, bytes); + int32_t ret = setGroupResultOutputBuf(pRuntimeEnv, val, type, bytes); if (ret != TSDB_CODE_SUCCESS) { // null data, too many state code continue; } } - // update the lastKey - lastKey = primaryKeyCol[offset]; - // all startOffset are identical offset -= pCtx[0].startOffset; @@ -1254,7 +1254,7 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS } } - pQuery->lastKey = lastKey + step; + item->lastKey = primaryKeyCol[offset] + step; // todo refactor: extract method for(int32_t i = 0; i < pQuery->numOfOutput; ++i) { @@ -1269,10 +1269,12 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS } static int32_t tableApplyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, SDataBlockInfo *pDataBlockInfo, - SDataStatis *pStatis, __block_search_fn_t searchFn, - SWindowResInfo *pWindowResInfo, SArray *pDataBlock) { + SDataStatis *pStatis, __block_search_fn_t searchFn, SArray *pDataBlock) { SQuery *pQuery = pRuntimeEnv->pQuery; - + + STableQueryInfo* pTableQInfo = pQuery->current; + SWindowResInfo* pWindowResInfo = &pRuntimeEnv->windowResInfo; + if (pQuery->numOfFilterCols > 0 || pRuntimeEnv->pTSBuf != NULL || isGroupbyNormalCol(pQuery->pGroupbyExpr)) { rowwiseApplyFunctions(pRuntimeEnv, pStatis, pDataBlockInfo, pWindowResInfo, pDataBlock); } else { @@ -1280,7 +1282,7 @@ static int32_t tableApplyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, SDataBl } TSKEY lastKey = QUERY_IS_ASC_QUERY(pQuery) ? pDataBlockInfo->window.ekey : pDataBlockInfo->window.skey; - pQuery->lastKey = lastKey + GET_FORWARD_DIRECTION_FACTOR(pQuery->order.order); + pTableQInfo->lastKey = lastKey + GET_FORWARD_DIRECTION_FACTOR(pQuery->order.order); doCheckQueryCompleted(pRuntimeEnv, lastKey, pWindowResInfo); @@ -1746,73 +1748,6 @@ static UNUSED_FUNC bool doSetDataInfo(SQInfo *pQInfo, SPointInterpoSupporter *pP } } -// TODO refactor code, the best way to implement the last_row is utilizing the iterator -bool normalizeUnBoundLastRowQuery(SQInfo *pQInfo, SPointInterpoSupporter *pPointInterpSupporter) { -#if 0 - SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv; - - SQuery * pQuery = pRuntimeEnv->pQuery; - SMeterObj *pMeterObj = pRuntimeEnv->pTabObj; - - assert(!QUERY_IS_ASC_QUERY(pQuery) && notHasQueryTimeRange(pQuery)); - __block_search_fn_t searchFn = vnodeSearchKeyFunc[pMeterObj->searchAlgorithm]; - - TSKEY lastKey = -1; - - pQuery->fileId = -1; - vnodeFreeFieldsEx(pRuntimeEnv); - - // keep in-memory cache status in local variables in case that it may be changed by write operation - getBasicCacheInfoSnapshot(pQuery, pMeterObj->pCache, pMeterObj->vnode); - - SCacheInfo *pCacheInfo = (SCacheInfo *)pMeterObj->pCache; - if (pCacheInfo != NULL && pCacheInfo->cacheBlocks != NULL && pQuery->numOfBlocks > 0) { - pQuery->fileId = -1; - TSKEY key = pMeterObj->lastKey; - - pQuery->window.skey = key; - pQuery->window.ekey = key; - pQuery->lastKey = pQuery->window.skey; - - /* - * cache block may have been flushed to disk, and no data in cache anymore. - * So, copy cache block to local buffer is required. - */ - lastKey = getQueryStartPositionInCache(pRuntimeEnv, &pQuery->slot, &pQuery->pos, false); - if (lastKey < 0) { // data has been flushed to disk, try again search in file - lastKey = getQueryPositionForCacheInvalid(pRuntimeEnv, searchFn); - - if (Q_STATUS_EQUAL(pQuery->status, QUERY_NO_DATA_TO_CHECK | QUERY_COMPLETED)) { - return false; - } - } - } else { // no data in cache, try file - TSKEY key = pMeterObj->lastKeyOnFile; - - pQuery->window.skey = key; - pQuery->window.ekey = key; - pQuery->lastKey = pQuery->window.skey; - - bool ret = getQualifiedDataBlock(pMeterObj, pRuntimeEnv, QUERY_RANGE_LESS_EQUAL, searchFn); - if (!ret) { // no data in file, return false; - return false; - } - - lastKey = getTimestampInDiskBlock(pRuntimeEnv, pQuery->pos); - } - - assert(lastKey <= pQuery->window.skey); - - pQuery->window.skey = lastKey; - pQuery->window.ekey = lastKey; - pQuery->lastKey = pQuery->window.skey; - - return getNeighborPoints(pQInfo, pMeterObj, pPointInterpSupporter); -#endif - - return true; -} - static void setScanLimitationByResultBuffer(SQuery *pQuery) { if (isTopBottomQuery(pQuery)) { pQuery->checkBuffer = 0; @@ -2327,7 +2262,7 @@ static void getNextTimeWindow(SQuery *pQuery, STimeWindow *pTimeWindow) { pTimeWindow->ekey = pTimeWindow->skey + (pQuery->intervalTime - 1); } -SArray *loadDataBlockOnDemand(SQueryRuntimeEnv *pRuntimeEnv, SDataBlockInfo *pBlockInfo, SDataStatis **pStatis) { +SArray *loadDataBlockOnDemand(SQueryRuntimeEnv *pRuntimeEnv, void* pQueryHandle, SDataBlockInfo* pBlockInfo, SDataStatis **pStatis) { SQuery *pQuery = pRuntimeEnv->pQuery; uint32_t r = 0; @@ -2351,16 +2286,16 @@ SArray *loadDataBlockOnDemand(SQueryRuntimeEnv *pRuntimeEnv, SDataBlockInfo *pBl qTrace("QInfo:%p data block ignored, brange:%" PRId64 "-%" PRId64 ", rows:%d", GET_QINFO_ADDR(pRuntimeEnv), pBlockInfo->window.skey, pBlockInfo->window.ekey, pBlockInfo->rows); } else if (r == BLK_DATA_FILEDS_NEEDED) { - if (tsdbRetrieveDataBlockStatisInfo(pRuntimeEnv->pQueryHandle, pStatis) != TSDB_CODE_SUCCESS) { + if (tsdbRetrieveDataBlockStatisInfo(pQueryHandle, pStatis) != TSDB_CODE_SUCCESS) { // return DISK_DATA_LOAD_FAILED; } if (*pStatis == NULL) { - pDataBlock = tsdbRetrieveDataBlock(pRuntimeEnv->pQueryHandle, NULL); + pDataBlock = tsdbRetrieveDataBlock(pQueryHandle, NULL); } } else { assert(r == BLK_DATA_ALL_NEEDED); - if (tsdbRetrieveDataBlockStatisInfo(pRuntimeEnv->pQueryHandle, pStatis) != TSDB_CODE_SUCCESS) { + if (tsdbRetrieveDataBlockStatisInfo(pQueryHandle, pStatis) != TSDB_CODE_SUCCESS) { // return DISK_DATA_LOAD_FAILED; } @@ -2376,7 +2311,7 @@ SArray *loadDataBlockOnDemand(SQueryRuntimeEnv *pRuntimeEnv, SDataBlockInfo *pBl // return DISK_DATA_DISCARDED; } - pDataBlock = tsdbRetrieveDataBlock(pRuntimeEnv->pQueryHandle, NULL); + pDataBlock = tsdbRetrieveDataBlock(pQueryHandle, NULL); } return pDataBlock; @@ -2447,8 +2382,11 @@ int32_t binarySearchForKey(char *pValue, int num, TSKEY key, int order) { static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) { SQuery *pQuery = pRuntimeEnv->pQuery; + STableQueryInfo* pTableQueryInfo = pQuery->current; + qTrace("QInfo:%p query start, qrange:%" PRId64 "-%" PRId64 ", lastkey:%" PRId64 ", order:%d", - GET_QINFO_ADDR(pRuntimeEnv), pQuery->window.skey, pQuery->window.ekey, pQuery->lastKey, pQuery->order.order); + GET_QINFO_ADDR(pRuntimeEnv), pTableQueryInfo->win.skey, pTableQueryInfo->win.ekey, pTableQueryInfo->lastKey, + pQuery->order.order); TsdbQueryHandleT pQueryHandle = IS_MASTER_SCAN(pRuntimeEnv)? pRuntimeEnv->pQueryHandle : pRuntimeEnv->pSecQueryHandle; while (tsdbNextDataBlock(pQueryHandle)) { @@ -2479,7 +2417,7 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) { } } - // in case of prj/diff query, ensure the output buffer is sufficient to accomodate the results of current block + // in case of prj/diff query, ensure the output buffer is sufficient to accommodate the results of current block if (!isIntervalQuery(pQuery) && !isGroupbyNormalCol(pQuery->pGroupbyExpr) && !isFixedOutputQuery(pQuery)) { SResultRec *pRec = &pQuery->rec; @@ -2505,11 +2443,10 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) { } SDataStatis *pStatis = NULL; - SArray * pDataBlock = loadDataBlockOnDemand(pRuntimeEnv, &blockInfo, &pStatis); + SArray * pDataBlock = loadDataBlockOnDemand(pRuntimeEnv, pQueryHandle, &blockInfo, &pStatis); pQuery->pos = QUERY_IS_ASC_QUERY(pQuery) ? 0 : blockInfo.rows - 1; - int32_t numOfRes = tableApplyFunctionsOnBlock(pRuntimeEnv, &blockInfo, pStatis, binarySearchForKey, - &pRuntimeEnv->windowResInfo, pDataBlock); + int32_t numOfRes = tableApplyFunctionsOnBlock(pRuntimeEnv, &blockInfo, pStatis, binarySearchForKey, pDataBlock); qTrace("QInfo:%p check data block, brange:%" PRId64 "-%" PRId64 ", rows:%d, res:%d", GET_QINFO_ADDR(pRuntimeEnv), blockInfo.window.skey, blockInfo.window.ekey, blockInfo.rows, numOfRes); @@ -2520,7 +2457,7 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) { } } - // if the result buffer is not full, set the query completed flag + // if the result buffer is not full, set the query complete if (!Q_STATUS_EQUAL(pQuery->status, QUERY_RESBUF_FULL)) { setQueryStatus(pQuery, QUERY_COMPLETED); } @@ -2530,8 +2467,8 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) { int32_t step = QUERY_IS_ASC_QUERY(pQuery) ? QUERY_ASC_FORWARD_STEP : QUERY_DESC_FORWARD_STEP; closeAllTimeWindow(&pRuntimeEnv->windowResInfo); - removeRedundantWindow(&pRuntimeEnv->windowResInfo, pQuery->lastKey - step, step); - pRuntimeEnv->windowResInfo.curIndex = pRuntimeEnv->windowResInfo.size - 1; + removeRedundantWindow(&pRuntimeEnv->windowResInfo, pTableQueryInfo->lastKey - step, step); + pRuntimeEnv->windowResInfo.curIndex = pRuntimeEnv->windowResInfo.size - 1; // point to the last time window } else { assert(Q_STATUS_EQUAL(pQuery->status, QUERY_RESBUF_FULL)); } @@ -2540,8 +2477,6 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) { return 0; } -static void updatelastkey(SQuery *pQuery, STableQueryInfo *pTableQInfo) { pTableQInfo->lastKey = pQuery->lastKey; } - /* * set tag value in SQLFunctionCtx * e.g.,tag information into input buffer @@ -2554,17 +2489,17 @@ static void doSetTagValueInParam(void *tsdb, STableId* pTableId, int32_t tagColI int16_t type = 0; if (tagColId == TSDB_TBNAME_COLUMN_INDEX) { - tsdbGetTableName(tsdb, pTableId, &val); - bytes = strnlen(val, TSDB_TABLE_NAME_LEN); + val = tsdbGetTableName(tsdb, pTableId, &bytes); type = TSDB_DATA_TYPE_BINARY; + tVariantCreateFromBinary(param, varDataVal(val), varDataLen(val), type); } else { tsdbGetTableTagVal(tsdb, pTableId, tagColId, &type, &bytes, &val); - } - - tVariantCreateFromBinary(param, val, bytes, type); - - if (tagColId == TSDB_TBNAME_COLUMN_INDEX) { - tfree(val); + + if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) { + tVariantCreateFromBinary(param, varDataVal(val), varDataLen(val), type); + } else { + tVariantCreateFromBinary(param, val, bytes, type); + } } } @@ -3082,11 +3017,6 @@ void resetMergeResultBuf(SQuery *pQuery, SQLFunctionCtx *pCtx, SResultInfo *pRes } } -void setTableDataInfo(STableQueryInfo *pTableQueryInfo, int32_t tableIndex, int32_t groupId) { - pTableQueryInfo->groupIdx = groupId; - pTableQueryInfo->tableIndex = tableIndex; -} - static void updateTableQueryInfoForReverseScan(SQuery *pQuery, STableQueryInfo *pTableQueryInfo) { if (pTableQueryInfo == NULL) { return; @@ -3132,19 +3062,6 @@ static void disableFuncInReverseScanImpl(SQInfo* pQInfo, SWindowResInfo *pWindow } } } - - int32_t numOfGroups = taosArrayGetSize(pQInfo->groupInfo.pGroupList); - - for(int32_t i = 0; i < numOfGroups; ++i) { - SArray *group = taosArrayGetP(pQInfo->groupInfo.pGroupList, i); - qTrace("QInfo:%p no result in group %d, continue", pQInfo, pQInfo->groupIndex - 1); - - size_t t = taosArrayGetSize(group); - for (int32_t j = 0; j < t; ++j) { - SGroupItem *item = taosArrayGet(group, j); - updateTableQueryInfoForReverseScan(pQuery, item->info); - } - } } void disableFuncInReverseScan(SQInfo *pQInfo) { @@ -3170,6 +3087,18 @@ void disableFuncInReverseScan(SQInfo *pQInfo) { } } } + + int32_t numOfGroups = taosArrayGetSize(pQInfo->groupInfo.pGroupList); + + for(int32_t i = 0; i < numOfGroups; ++i) { + SArray *group = taosArrayGetP(pQInfo->groupInfo.pGroupList, i); + + size_t t = taosArrayGetSize(group); + for (int32_t j = 0; j < t; ++j) { + SGroupItem *item = taosArrayGet(group, j); + updateTableQueryInfoForReverseScan(pQuery, item->info); + } + } } void switchCtxOrder(SQueryRuntimeEnv *pRuntimeEnv) { @@ -3345,13 +3274,14 @@ bool needScanDataBlocksAgain(SQueryRuntimeEnv *pRuntimeEnv) { static SQueryStatusInfo getQueryStatusInfo(SQueryRuntimeEnv *pRuntimeEnv) { SQuery *pQuery = pRuntimeEnv->pQuery; - + STableQueryInfo* pTableQueryInfo = pQuery->current; + SQueryStatusInfo info = { - .status = pQuery->status, + .status = pQuery->status, .windowIndex = pRuntimeEnv->windowResInfo.curIndex, - .lastKey = pQuery->lastKey, - .w = pQuery->window, - .curWindow = {.skey = pQuery->lastKey, .ekey = pQuery->window.ekey}, + .lastKey = pTableQueryInfo->lastKey, + .w = pQuery->window, + .curWindow = {.skey = pTableQueryInfo->lastKey, .ekey = pTableQueryInfo->win.ekey}, }; return info; @@ -3376,7 +3306,7 @@ static void setEnvBeforeReverseScan(SQueryRuntimeEnv *pRuntimeEnv, SQueryStatusI STsdbQueryCond cond = { .twindow = pQuery->window, - .order = pQuery->order.order, + .order = pQuery->order.order, .colList = pQuery->colList, .numOfCols = pQuery->numOfCols, }; @@ -3395,6 +3325,7 @@ static void setEnvBeforeReverseScan(SQueryRuntimeEnv *pRuntimeEnv, SQueryStatusI static void clearEnvAfterReverseScan(SQueryRuntimeEnv *pRuntimeEnv, SQueryStatusInfo *pStatus) { SQuery *pQuery = pRuntimeEnv->pQuery; + STableQueryInfo* pTableQueryInfo = pQuery->current; SWITCH_ORDER(pQuery->order.order); switchCtxOrder(pRuntimeEnv); @@ -3408,17 +3339,19 @@ static void clearEnvAfterReverseScan(SQueryRuntimeEnv *pRuntimeEnv, SQueryStatus // update the pQuery->window.skey and pQuery->window.ekey to limit the scan scope of sliding query // during reverse scan - pQuery->lastKey = pStatus->lastKey; + pTableQueryInfo->lastKey = pStatus->lastKey; pQuery->status = pStatus->status; - pQuery->window = pStatus->w; + pTableQueryInfo->win = pStatus->w; } void scanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) { + SQInfo *pQInfo = (SQInfo *) GET_QINFO_ADDR(pRuntimeEnv); SQuery *pQuery = pRuntimeEnv->pQuery; + STableQueryInfo *pTableQueryInfo = pQuery->current; + setQueryStatus(pQuery, QUERY_NOT_COMPLETED); // store the start query position - SQInfo * pQInfo = (SQInfo *)GET_QINFO_ADDR(pRuntimeEnv); SQueryStatusInfo qstatus = getQueryStatusInfo(pRuntimeEnv); SET_MASTER_SCAN_FLAG(pRuntimeEnv); @@ -3429,7 +3362,7 @@ void scanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) { if (pRuntimeEnv->scanFlag == MASTER_SCAN) { qstatus.status = pQuery->status; - qstatus.curWindow.ekey = pQuery->lastKey - step; + qstatus.curWindow.ekey = pTableQueryInfo->lastKey - step; } if (!needScanDataBlocksAgain(pRuntimeEnv)) { @@ -3443,7 +3376,7 @@ void scanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) { STsdbQueryCond cond = { .twindow = qstatus.curWindow, - .order = pQuery->order.order, + .order = pQuery->order.order, .colList = pQuery->colList, .numOfCols = pQuery->numOfCols, }; @@ -3549,12 +3482,10 @@ void destroyTableQueryInfo(STableQueryInfo *pTableQueryInfo, int32_t numOfCols) void restoreIntervalQueryRange(SQueryRuntimeEnv *pRuntimeEnv, STableQueryInfo *pTableQueryInfo) { SQuery *pQuery = pRuntimeEnv->pQuery; - - pQuery->window = pTableQueryInfo->win; - pQuery->lastKey = pTableQueryInfo->lastKey; - - assert(((pQuery->lastKey >= pQuery->window.skey) && QUERY_IS_ASC_QUERY(pQuery)) || - ((pQuery->lastKey <= pQuery->window.skey) && !QUERY_IS_ASC_QUERY(pQuery))); + pQuery->current = pTableQueryInfo; + + assert(((pTableQueryInfo->lastKey >= pTableQueryInfo->win.skey) && QUERY_IS_ASC_QUERY(pQuery)) || + ((pTableQueryInfo->lastKey <= pTableQueryInfo->win.skey) && !QUERY_IS_ASC_QUERY(pQuery))); } /** @@ -3562,8 +3493,10 @@ void restoreIntervalQueryRange(SQueryRuntimeEnv *pRuntimeEnv, STableQueryInfo *p * @param pRuntimeEnv * @param pDataBlockInfo */ -void setExecutionContext(SQInfo *pQInfo, STableQueryInfo *pTableQueryInfo, STableId* pTableId, int32_t groupIdx, TSKEY nextKey) { +void setExecutionContext(SQInfo *pQInfo, STableId* pTableId, int32_t groupIdx, TSKEY nextKey) { SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv; + STableQueryInfo *pTableQueryInfo = pRuntimeEnv->pQuery->current; + SWindowResInfo * pWindowResInfo = &pRuntimeEnv->windowResInfo; int32_t GROUPRESULTID = 1; @@ -3647,12 +3580,12 @@ int32_t setAdditionalInfo(SQInfo *pQInfo, STableId* pTableId, STableQueryInfo *p * merged during merge stage. In this case, we need the pTableQueryInfo->lastResRows to decide if there * is a previous result generated or not. */ -void setIntervalQueryRange(STableQueryInfo *pTableQueryInfo, SQInfo *pQInfo, TSKEY key) { +void setIntervalQueryRange(SQInfo *pQInfo, TSKEY key) { SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv; SQuery * pQuery = pRuntimeEnv->pQuery; - + STableQueryInfo *pTableQueryInfo = pQuery->current; + if (pTableQueryInfo->queryRangeSet) { - pQuery->lastKey = key; pTableQueryInfo->lastKey = key; } else { pQuery->window.skey = key; @@ -3689,8 +3622,6 @@ void setIntervalQueryRange(STableQueryInfo *pTableQueryInfo, SQInfo *pQInfo, TSK pTableQueryInfo->queryRangeSet = 1; pTableQueryInfo->lastKey = pQuery->window.skey; pTableQueryInfo->win.skey = pQuery->window.skey; - - pQuery->lastKey = pQuery->window.skey; } } @@ -3710,7 +3641,9 @@ bool needPrimaryTimestampCol(SQuery *pQuery, SDataBlockInfo *pDataBlockInfo) { * 2. if there are top/bottom, first_dst/last_dst functions, we need to load timestamp column in any cases; */ STimeWindow *w = &pDataBlockInfo->window; - bool loadPrimaryTS = (pQuery->lastKey >= w->skey && pQuery->lastKey <= w->ekey) || + STableQueryInfo* pTableQueryInfo = pQuery->current; + + bool loadPrimaryTS = (pTableQueryInfo->lastKey >= w->skey && pTableQueryInfo->lastKey <= w->ekey) || (pQuery->window.ekey >= w->skey && pQuery->window.ekey <= w->ekey) || requireTimestamp(pQuery); return loadPrimaryTS; @@ -3847,7 +3780,6 @@ void stableApplyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, STableQueryInfo } updateWindowResNumOfRes(pRuntimeEnv, pTableQueryInfo); - updatelastkey(pQuery, pTableQueryInfo); } bool vnodeHasRemainResults(void *handle) { @@ -4041,10 +3973,12 @@ void vnodePrintQueryStatistics(SQInfo *pQInfo) { static void updateOffsetVal(SQueryRuntimeEnv *pRuntimeEnv, SDataBlockInfo *pBlockInfo) { SQuery *pQuery = pRuntimeEnv->pQuery; + STableQueryInfo* pTableQueryInfo = pQuery->current; + int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQuery->order.order); if (pQuery->limit.offset == pBlockInfo->rows) { // current block will ignore completed - pQuery->lastKey = QUERY_IS_ASC_QUERY(pQuery) ? pBlockInfo->window.ekey + step : pBlockInfo->window.skey + step; + pTableQueryInfo->lastKey = QUERY_IS_ASC_QUERY(pQuery) ? pBlockInfo->window.ekey + step : pBlockInfo->window.skey + step; pQuery->limit.offset = 0; return; } @@ -4064,11 +3998,10 @@ static void updateOffsetVal(SQueryRuntimeEnv *pRuntimeEnv, SDataBlockInfo *pBloc TSKEY *keys = (TSKEY *)pColInfoData->pData; // update the offset value - pQuery->lastKey = keys[pQuery->pos]; + pTableQueryInfo->lastKey = keys[pQuery->pos]; pQuery->limit.offset = 0; - int32_t numOfRes = tableApplyFunctionsOnBlock(pRuntimeEnv, pBlockInfo, NULL, binarySearchForKey, - &pRuntimeEnv->windowResInfo, pDataBlock); + int32_t numOfRes = tableApplyFunctionsOnBlock(pRuntimeEnv, pBlockInfo, NULL, binarySearchForKey, pDataBlock); qTrace("QInfo:%p check data block, brange:%" PRId64 "-%" PRId64 ", rows:%d, res:%d", GET_QINFO_ADDR(pRuntimeEnv), pBlockInfo->window.skey, pBlockInfo->window.ekey, pBlockInfo->rows, numOfRes); @@ -4084,6 +4017,7 @@ void skipBlocks(SQueryRuntimeEnv *pRuntimeEnv) { pQuery->pos = 0; int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQuery->order.order); + STableQueryInfo* pTableQueryInfo = pQuery->current; TsdbQueryHandleT pQueryHandle = pRuntimeEnv->pQueryHandle; while (tsdbNextDataBlock(pQueryHandle)) { @@ -4095,8 +4029,8 @@ void skipBlocks(SQueryRuntimeEnv *pRuntimeEnv) { if (pQuery->limit.offset > blockInfo.rows) { pQuery->limit.offset -= blockInfo.rows; - pQuery->lastKey = (QUERY_IS_ASC_QUERY(pQuery)) ? blockInfo.window.ekey : blockInfo.window.skey; - pQuery->lastKey += step; + pTableQueryInfo->lastKey = (QUERY_IS_ASC_QUERY(pQuery)) ? blockInfo.window.ekey : blockInfo.window.skey; + pTableQueryInfo->lastKey += step; qTrace("QInfo:%p skip rows:%d, offset:%" PRId64 "", GET_QINFO_ADDR(pRuntimeEnv), blockInfo.rows, pQuery->limit.offset); @@ -4125,6 +4059,7 @@ static bool skipTimeInterval(SQueryRuntimeEnv *pRuntimeEnv) { TSKEY skey1, ekey1; STimeWindow w = {0}; SWindowResInfo *pWindowResInfo = &pRuntimeEnv->windowResInfo; + STableQueryInfo *pTableQueryInfo = pQuery->current; while (tsdbNextDataBlock(pRuntimeEnv->pQueryHandle)) { SDataBlockInfo blockInfo = tsdbRetrieveDataBlockInfo(pRuntimeEnv->pQueryHandle); @@ -4170,11 +4105,10 @@ static bool skipTimeInterval(SQueryRuntimeEnv *pRuntimeEnv) { // set the abort info pQuery->pos = startPos; - pQuery->lastKey = ((TSKEY *)pColInfoData->pData)[startPos]; + pTableQueryInfo->lastKey = ((TSKEY *)pColInfoData->pData)[startPos]; pWindowResInfo->prevSKey = tw.skey; - int32_t numOfRes = tableApplyFunctionsOnBlock(pRuntimeEnv, &blockInfo, NULL, binarySearchForKey, - &pRuntimeEnv->windowResInfo, pDataBlock); + int32_t numOfRes = tableApplyFunctionsOnBlock(pRuntimeEnv, &blockInfo, NULL, binarySearchForKey, pDataBlock); qTrace("QInfo:%p check data block, brange:%" PRId64 "-%" PRId64 ", rows:%d, res:%d", GET_QINFO_ADDR(pRuntimeEnv), blockInfo.window.skey, blockInfo.window.ekey, blockInfo.rows, numOfRes); @@ -4199,7 +4133,7 @@ static bool skipTimeInterval(SQueryRuntimeEnv *pRuntimeEnv) { // set the abort info pQuery->pos = startPos; - pQuery->lastKey = ((TSKEY *)pColInfoData->pData)[startPos]; + pTableQueryInfo->lastKey = ((TSKEY *)pColInfoData->pData)[startPos]; pWindowResInfo->prevSKey = tw.skey; win = tw; } else { @@ -4220,12 +4154,9 @@ int32_t doInitQInfo(SQInfo *pQInfo, void *param, void *tsdb, int32_t vgId, bool setScanLimitationByResultBuffer(pQuery); changeExecuteScanOrder(pQuery, false); - // dataInCache requires lastKey value - pQuery->lastKey = pQuery->window.skey; - STsdbQueryCond cond = { .twindow = pQuery->window, - .order = pQuery->order.order, + .order = pQuery->order.order, .colList = pQuery->colList, .numOfCols = pQuery->numOfCols, }; @@ -4238,6 +4169,9 @@ int32_t doInitQInfo(SQInfo *pQInfo, void *param, void *tsdb, int32_t vgId, bool } else if (!isSTableQuery || isIntervalQuery(pQuery) || isFixedOutputQuery(pQuery)) { pRuntimeEnv->pQueryHandle = tsdbQueryTables(tsdb, &cond, &pQInfo->tableIdGroupInfo); } + + // create the table query support structures + createTableQueryInfo(pQInfo); } pQInfo->tsdb = tsdb; @@ -4331,7 +4265,6 @@ int32_t doInitQInfo(SQInfo *pQInfo, void *param, void *tsdb, int32_t vgId, bool // } // the pQuery->window.skey is changed during normalizedFirstQueryRange, so set the newest lastkey value - pQuery->lastKey = pQuery->window.skey; return TSDB_CODE_SUCCESS; } @@ -4399,18 +4332,19 @@ static int64_t queryOnDataBlocks(SQInfo *pQInfo) { break; } } - + assert(pTableQueryInfo != NULL); restoreIntervalQueryRange(pRuntimeEnv, pTableQueryInfo); SDataStatis *pStatis = NULL; - SArray * pDataBlock = loadDataBlockOnDemand(pRuntimeEnv, &blockInfo, &pStatis); + + SArray *pDataBlock = loadDataBlockOnDemand(pRuntimeEnv, pQueryHandle, &blockInfo, &pStatis); TSKEY nextKey = blockInfo.window.skey; if (!isIntervalQuery(pQuery)) { - setExecutionContext(pQInfo, pTableQueryInfo, &pTableQueryInfo->id, pTableQueryInfo->groupIdx, nextKey); + setExecutionContext(pQInfo, &pTableQueryInfo->id, pTableQueryInfo->groupIdx, nextKey); } else { // interval query - setIntervalQueryRange(pTableQueryInfo, pQInfo, nextKey); + setIntervalQueryRange(pQInfo, nextKey); int32_t ret = setAdditionalInfo(pQInfo, &pTableQueryInfo->id, pTableQueryInfo); if (ret != TSDB_CODE_SUCCESS) { @@ -4446,6 +4380,7 @@ static bool multiTableMultioutputHelper(SQInfo *pQInfo, int32_t index) { .numOfCols = pQuery->numOfCols, }; + // todo refactor SArray *g1 = taosArrayInit(1, POINTER_BYTES); SArray *tx = taosArrayInit(1, sizeof(STableId)); @@ -4564,6 +4499,9 @@ static void sequentialTableProcess(SQInfo *pQInfo) { initCtxOutputBuf(pRuntimeEnv); setTagVal(pRuntimeEnv, (STableId*) taosArrayGet(tx, 0), pQInfo->tsdb); + + // here we simply set the first table as current table + pRuntimeEnv->pQuery->current = ((SGroupItem*) taosArrayGet(group, 0))->info; scanAllDataBlocks(pRuntimeEnv); int64_t numOfRes = getNumOfResult(pRuntimeEnv); @@ -4580,8 +4518,6 @@ static void sequentialTableProcess(SQInfo *pQInfo) { } } } else { - createTableQueryInfo(pQInfo); - /* * 1. super table projection query, 2. group-by on normal columns query, 3. ts-comp query * if the subgroup index is larger than 0, results generated by group by tbname,k is existed. @@ -4614,12 +4550,8 @@ static void sequentialTableProcess(SQInfo *pQInfo) { } SGroupItem *item = taosArrayGet(group, pQInfo->tableIndex); + pQuery->current = item->info; - STableQueryInfo *pInfo = item->info; - if (pInfo->lastKey > 0) { - pQuery->window.skey = pInfo->lastKey; - } - if (!multiTableMultioutputHelper(pQInfo, pQInfo->tableIndex)) { pQInfo->tableIndex++; continue; @@ -4627,7 +4559,7 @@ static void sequentialTableProcess(SQInfo *pQInfo) { // SPointInterpoSupporter pointInterpSupporter = {0}; - // TODO handle the limit problem + // TODO handle the limit offset problem if (pQuery->numOfFilterCols == 0 && pQuery->limit.offset > 0) { // skipBlocks(pRuntimeEnv); @@ -4659,8 +4591,6 @@ static void sequentialTableProcess(SQInfo *pQInfo) { * to ensure that, we can reset the query range once query on a meter is completed. */ pQInfo->tableIndex++; - pInfo->lastKey = pQuery->lastKey; - // if the buffer is full or group by each table, we need to jump out of the loop if (Q_STATUS_EQUAL(pQuery->status, QUERY_RESBUF_FULL) /*|| isGroupbyEachTable(pQuery->pGroupbyExpr, pSupporter->pSidSet)*/) { @@ -4668,7 +4598,7 @@ static void sequentialTableProcess(SQInfo *pQInfo) { } } else { // forward query range - pQuery->window.skey = pQuery->lastKey; + pQuery->window.skey = pQuery->current->lastKey; // all data in the result buffer are skipped due to the offset, continue to retrieve data from current meter if (pQuery->rec.rows == 0) { @@ -4853,12 +4783,9 @@ static void multiTableQueryProcess(SQInfo *pQInfo) { qTrace("QInfo:%p query start, qrange:%" PRId64 "-%" PRId64 ", order:%d, forward scan start", pQInfo, pQuery->window.skey, pQuery->window.ekey, pQuery->order.order); - // create the query support structures - createTableQueryInfo(pQInfo); - // do check all qualified data blocks int64_t el = queryOnDataBlocks(pQInfo); - qTrace("QInfo:%p forward scan completed, elapsed time: %lldms, reversed scan start", pQInfo, el); + qTrace("QInfo:%p master scan completed, elapsed time: %lldms, reverse scan start", pQInfo, el); // query error occurred or query is killed, abort current execution if (pQInfo->code != TSDB_CODE_SUCCESS || isQueryKilled(pQInfo)) { @@ -4909,10 +4836,12 @@ static void multiTableQueryProcess(SQInfo *pQInfo) { * select count(*)/top(field,k)/avg(field name) from table_name [where ts>now-1a]; * select count(*) from table_name group by status_column; */ -static void tableFixedOutputProcess(SQInfo *pQInfo) { +static void tableFixedOutputProcess(SQInfo *pQInfo, STableQueryInfo* pTableInfo) { SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv; - SQuery * pQuery = pRuntimeEnv->pQuery; - + + SQuery *pQuery = pRuntimeEnv->pQuery; + pQuery->current = pTableInfo; // set current query table info + scanAllDataBlocks(pRuntimeEnv); finalizeQueryResult(pRuntimeEnv); @@ -4932,10 +4861,12 @@ static void tableFixedOutputProcess(SQInfo *pQInfo) { limitResults(pQInfo); } -static void tableMultiOutputProcess(SQInfo *pQInfo) { +static void tableMultiOutputProcess(SQInfo *pQInfo, STableQueryInfo* pTableInfo) { SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv; - SQuery * pQuery = pRuntimeEnv->pQuery; - + + SQuery *pQuery = pRuntimeEnv->pQuery; + pQuery->current = pTableInfo; + // for ts_comp query, re-initialized is not allowed if (!isTSCompQuery(pQuery)) { resetCtxOutputBuf(pRuntimeEnv); @@ -4970,15 +4901,15 @@ static void tableMultiOutputProcess(SQInfo *pQInfo) { } qTrace("QInfo:%p vid:%d sid:%d id:%s, skip current result, offset:%" PRId64 ", next qrange:%" PRId64 "-%" PRId64, - pQInfo, pQuery->limit.offset, pQuery->lastKey); + pQInfo, pQuery->limit.offset, pQuery->current->lastKey); resetCtxOutputBuf(pRuntimeEnv); } limitResults(pQInfo); if (Q_STATUS_EQUAL(pQuery->status, QUERY_RESBUF_FULL)) { - qTrace("QInfo:%p query paused due to output limitation, next qrange:%" PRId64 "-%" PRId64, pQInfo, pQuery->lastKey, - pQuery->window.ekey); + qTrace("QInfo:%p query paused due to output limitation, next qrange:%" PRId64 "-%" PRId64, pQInfo, + pQuery->current->lastKey, pQuery->window.ekey); } if (!isTSCompQuery(pQuery)) { @@ -5018,11 +4949,12 @@ static void tableIntervalProcessImpl(SQueryRuntimeEnv *pRuntimeEnv) { } // handle time interval query on table -static void tableIntervalProcess(SQInfo *pQInfo) { +static void tableIntervalProcess(SQInfo *pQInfo, STableQueryInfo* pTableInfo) { SQueryRuntimeEnv *pRuntimeEnv = &(pQInfo->runtimeEnv); - SQuery * pQuery = pRuntimeEnv->pQuery; int32_t numOfInterpo = 0; + SQuery *pQuery = pRuntimeEnv->pQuery; + pQuery->current = pTableInfo; // skip blocks without load the actual data block from file if no filter condition present skipTimeInterval(pRuntimeEnv); @@ -5131,15 +5063,19 @@ static void tableQueryImpl(SQInfo *pQInfo) { // number of points returned during this query pQuery->rec.rows = 0; int64_t st = taosGetTimestampUs(); - + + assert(pQInfo->groupInfo.numOfTables == 1); + SArray* g = taosArrayGetP(pQInfo->groupInfo.pGroupList, 0); + SGroupItem* item = taosArrayGet(g, 0); + // group by normal column, sliding window query, interval query are handled by interval query processor if (isIntervalQuery(pQuery) || isGroupbyNormalCol(pQuery->pGroupbyExpr)) { // interval (down sampling operation) - tableIntervalProcess(pQInfo); + tableIntervalProcess(pQInfo, item->info); } else if (isFixedOutputQuery(pQuery)) { - tableFixedOutputProcess(pQInfo); + tableFixedOutputProcess(pQInfo, item->info); } else { // diff/add/multiply/subtract/division assert(pQuery->checkBuffer == 1); - tableMultiOutputProcess(pQInfo); + tableMultiOutputProcess(pQInfo, item->info); } // record the total elapsed time @@ -5833,7 +5769,6 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SSqlGroupbyExpr *pGrou pQuery->pos = -1; pQuery->window = pQueryMsg->window; - pQuery->lastKey = pQuery->window.skey; if (sem_init(&pQInfo->dataReady, 0, 0) != 0) { qError("QInfo:%p init dataReady sem failed, reason:%s", pQInfo, strerror(errno)); @@ -5910,9 +5845,7 @@ static int32_t initQInfo(SQueryTableMsg *pQueryMsg, void *tsdb, int32_t vgId, SQ if ((code = doInitQInfo(pQInfo, pTSBuf, tsdb, vgId, isSTable)) != TSDB_CODE_SUCCESS) { goto _error; } - - // qTrace("QInfo:%p set query flag and prepare runtime environment completed, ref:%d, wait for schedule", pQInfo, - // pQInfo->refCount); + return code; _error: @@ -6085,34 +6018,35 @@ int32_t qCreateQueryInfo(void *tsdb, int32_t vgId, SQueryTableMsg *pQueryMsg, qi if (pQueryMsg->numOfTables <= 0) { qError("Invalid number of tables to query, numOfTables:%d", pQueryMsg->numOfTables); code = TSDB_CODE_INVALID_QUERY_MSG; - goto _query_over; + goto _over; } if (pTableIdList == NULL || taosArrayGetSize(pTableIdList) == 0) { qError("qmsg:%p, SQueryTableMsg wrong format", pQueryMsg); code = TSDB_CODE_INVALID_QUERY_MSG; - goto _query_over; + goto _over; } SExprInfo *pExprs = NULL; if ((code = createSqlFunctionExprFromMsg(pQueryMsg, &pExprs, pExprMsg, pTagColumnInfo)) != TSDB_CODE_SUCCESS) { - goto _query_over; + goto _over; } SSqlGroupbyExpr *pGroupbyExpr = createGroupbyExprFromMsg(pQueryMsg, pGroupColIndex, &code); if ((pGroupbyExpr == NULL && pQueryMsg->numOfGroupCols != 0) || code != TSDB_CODE_SUCCESS) { - goto _query_over; + goto _over; } bool isSTableQuery = false; STableGroupInfo groupInfo = {0}; + //todo multitable_query?? if (TSDB_QUERY_HAS_TYPE(pQueryMsg->queryType, TSDB_QUERY_TYPE_MULTITABLE_QUERY|TSDB_QUERY_TYPE_TABLE_QUERY)) { isSTableQuery = TSDB_QUERY_HAS_TYPE(pQueryMsg->queryType, TSDB_QUERY_TYPE_MULTITABLE_QUERY); STableId *id = taosArrayGet(pTableIdList, 0); if ((code = tsdbGetOneTableGroup(tsdb, id->uid, &groupInfo)) != TSDB_CODE_SUCCESS) { - goto _query_over; + goto _over; } } else if (TSDB_QUERY_HAS_TYPE(pQueryMsg->queryType, TSDB_QUERY_TYPE_STABLE_QUERY)) { isSTableQuery = true; @@ -6129,7 +6063,7 @@ int32_t qCreateQueryInfo(void *tsdb, int32_t vgId, SQueryTableMsg *pQueryMsg, qi numOfGroupByCols); if (groupInfo.numOfTables == 0) { // no qualified tables no need to do query code = TSDB_CODE_SUCCESS; - goto _query_over; + goto _over; } } else { assert(0); @@ -6138,11 +6072,12 @@ int32_t qCreateQueryInfo(void *tsdb, int32_t vgId, SQueryTableMsg *pQueryMsg, qi (*pQInfo) = createQInfoImpl(pQueryMsg, pGroupbyExpr, pExprs, &groupInfo, pTagColumnInfo); if ((*pQInfo) == NULL) { code = TSDB_CODE_SERV_OUT_OF_MEMORY; + goto _over; } code = initQInfo(pQueryMsg, tsdb, vgId, *pQInfo, isSTableQuery); -_query_over: +_over: tfree(tagCond); tfree(tbnameCond); taosArrayDestroy(pTableIdList); @@ -6318,12 +6253,10 @@ static void buildTagQueryResult(SQInfo* pQInfo) { for(int32_t j = 0; j < pQuery->numOfOutput; ++j) { // todo check the return value, refactor codes if (pExprInfo[j].base.colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) { - tsdbGetTableName(pQInfo->tsdb, &item->id, &data); + data = tsdbGetTableName(pQInfo->tsdb, &item->id, &bytes); char* dst = pQuery->sdata[j]->data + i * (TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE); - STR_WITH_MAXSIZE_TO_VARSTR(dst, data, TSDB_TABLE_NAME_LEN); - tfree(data); - + memcpy(dst, data, varDataTLen(data)); } else {// todo refactor, return the true length of binary|nchar data tsdbGetTableTagVal(pQInfo->tsdb, &item->id, pExprInfo[j].base.colInfo.colId, &type, &bytes, &data); assert(bytes == pExprInfo[j].bytes && type == pExprInfo[j].type); diff --git a/src/tsdb/inc/tsdbMain.h b/src/tsdb/inc/tsdbMain.h index 278463f0d2acfadd4a9794a87f3e2f6cc23b9a41..2c3aff4b84bf5ad3d8efff1358e6192eae610575 100644 --- a/src/tsdb/inc/tsdbMain.h +++ b/src/tsdb/inc/tsdbMain.h @@ -81,7 +81,6 @@ typedef struct { // ---------- TSDB TABLE DEFINITION typedef struct STable { int8_t type; - char * name; STableId tableId; int64_t superUid; // Super table UID int32_t sversion; @@ -96,9 +95,10 @@ typedef struct STable { TSKEY lastKey; // lastkey inserted in this table, initialized as 0, TODO: make a structure struct STable *next; // TODO: remove the next struct STable *prev; + tstr * name; // NOTE: there a flexible string here } STable; -#define TSDB_GET_TABLE_LAST_KEY(pTable) ((pTable)->lastKey) +#define TSDB_GET_TABLE_LAST_KEY(tb) ((tb)->lastKey) void * tsdbEncodeTable(STable *pTable, int *contLen); STable *tsdbDecodeTable(void *cont, int contLen); @@ -121,6 +121,12 @@ typedef struct { int maxCols; } STsdbMeta; +// element put in skiplist for each table +typedef struct STableIndexElem { + STsdbMeta* pMeta; + STable* pTable; +} STableIndexElem; + STsdbMeta *tsdbInitMeta(char *rootDir, int32_t maxTables); int32_t tsdbFreeMeta(STsdbMeta *pMeta); STSchema * tsdbGetTableSchema(STsdbMeta *pMeta, STable *pTable); @@ -150,7 +156,7 @@ int32_t tsdbDropTableImpl(STsdbMeta *pMeta, STableId tableId); STable *tsdbIsValidTableToInsert(STsdbMeta *pMeta, STableId tableId); // int32_t tsdbInsertRowToTableImpl(SSkipListNode *pNode, STable *pTable); STable *tsdbGetTableByUid(STsdbMeta *pMeta, int64_t uid); -char * getTupleKey(const void *data); +char *getTSTupleKey(const void * data); typedef struct { int blockId; diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index 8d570911a91bd2fd3c730dd04617e65af3558130..653ec50af8b4ef66e804ca3f617e1302119afe41 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -808,7 +808,7 @@ static int32_t tdInsertRowToTable(STsdbRepo *pRepo, SDataRow row, STable *pTable if (pTable->mem == NULL) { pTable->mem = (SMemTable *)calloc(1, sizeof(SMemTable)); if (pTable->mem == NULL) return -1; - pTable->mem->pData = tSkipListCreate(5, TSDB_DATA_TYPE_TIMESTAMP, TYPE_BYTES[TSDB_DATA_TYPE_TIMESTAMP], 0, 0, 0, getTupleKey); + pTable->mem->pData = tSkipListCreate(5, TSDB_DATA_TYPE_TIMESTAMP, TYPE_BYTES[TSDB_DATA_TYPE_TIMESTAMP], 0, 0, 0, getTSTupleKey); pTable->mem->keyFirst = INT64_MAX; pTable->mem->keyLast = 0; } @@ -831,7 +831,7 @@ static int32_t tdInsertRowToTable(STsdbRepo *pRepo, SDataRow row, STable *pTable if (pTable->mem == NULL) { pTable->mem = (SMemTable *)calloc(1, sizeof(SMemTable)); if (pTable->mem == NULL) return -1; - pTable->mem->pData = tSkipListCreate(5, TSDB_DATA_TYPE_TIMESTAMP, TYPE_BYTES[TSDB_DATA_TYPE_TIMESTAMP], 0, 0, 0, getTupleKey); + pTable->mem->pData = tSkipListCreate(5, TSDB_DATA_TYPE_TIMESTAMP, TYPE_BYTES[TSDB_DATA_TYPE_TIMESTAMP], 0, 0, 0, getTSTupleKey); pTable->mem->keyFirst = INT64_MAX; pTable->mem->keyLast = 0; } diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index 0828db7f00d2e869abf2aef3fe02c926ff77be4f..107da929655e355dbc7e42697a0a7773433b23e6 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -1,6 +1,4 @@ #include - -// #include "taosdef.h" #include "tskiplist.h" #include "tsdb.h" #include "taosdef.h" @@ -10,6 +8,8 @@ #define TSDB_SUPER_TABLE_SL_LEVEL 5 // TODO: may change here #define TSDB_META_FILE_NAME "META" +const int32_t DEFAULT_TAG_INDEX_COLUMN = 0; + static int tsdbFreeTable(STable *pTable); static int32_t tsdbCheckTableCfg(STableCfg *pCfg); static int tsdbAddTableToMeta(STsdbMeta *pMeta, STable *pTable, bool addIdx); @@ -39,11 +39,12 @@ void *tsdbEncodeTable(STable *pTable, int *contLen) { void *ptr = ret; T_APPEND_MEMBER(ptr, pTable, STable, type); - // Encode name - *(int *)ptr = strlen(pTable->name); + // Encode name, todo refactor + *(int *)ptr = varDataLen(pTable->name); ptr = (char *)ptr + sizeof(int); - memcpy(ptr, pTable->name, strlen(pTable->name)); - ptr = (char *)ptr + strlen(pTable->name); + memcpy(ptr, varDataVal(pTable->name), varDataLen(pTable->name)); + ptr = (char *)ptr + varDataLen(pTable->name); + T_APPEND_MEMBER(ptr, &(pTable->tableId), STableId, uid); T_APPEND_MEMBER(ptr, &(pTable->tableId), STableId, tid); T_APPEND_MEMBER(ptr, pTable, STable, superUid); @@ -79,9 +80,12 @@ STable *tsdbDecodeTable(void *cont, int contLen) { T_READ_MEMBER(ptr, int8_t, pTable->type); int len = *(int *)ptr; ptr = (char *)ptr + sizeof(int); - pTable->name = calloc(1, len + 1); + pTable->name = calloc(1, len + VARSTR_HEADER_SIZE); if (pTable->name == NULL) return NULL; - memcpy(pTable->name, ptr, len); + + varDataSetLen(pTable->name, len); + memcpy(pTable->name->data, ptr, len); + ptr = (char *)ptr + len; T_READ_MEMBER(ptr, int64_t, pTable->tableId.uid); T_READ_MEMBER(ptr, int32_t, pTable->tableId.tid); @@ -105,8 +109,13 @@ void tsdbFreeEncode(void *cont) { } static char* getTagIndexKey(const void* pData) { - STable* table = *(STable**) pData; - return getTupleKey(table->tagVal); + STableIndexElem* elem = (STableIndexElem*) pData; + + SDataRow row = elem->pTable->tagVal; + STSchema* pSchema = tsdbGetTableTagSchema(elem->pMeta, elem->pTable); + STColumn* pCol = &pSchema->columns[DEFAULT_TAG_INDEX_COLUMN]; + + return tdGetRowDataOfCol(row, pCol->type, TD_DATA_ROW_HEAD_SIZE + pCol->offset); } int tsdbRestoreTable(void *pHandle, void *cont, int contLen) { @@ -225,36 +234,28 @@ STSchema * tsdbGetTableTagSchema(STsdbMeta *pMeta, STable *pTable) { } } +// todo refactor table name definition int32_t tsdbGetTableTagVal(TsdbRepoT* repo, STableId* id, int32_t colId, int16_t* type, int16_t* bytes, char** val) { STsdbMeta* pMeta = tsdbGetMeta(repo); STable* pTable = tsdbGetTableByUid(pMeta, id->uid); STSchema* pSchema = tsdbGetTableTagSchema(pMeta, pTable); - STColumn* pCol = NULL; - int32_t offset = 0; + for(int32_t col = 0; col < schemaNCols(pSchema); ++col) { STColumn* p = schemaColAt(pSchema, col); if (p->colId == colId) { pCol = p; break; } - - if (p->type == TSDB_DATA_TYPE_BINARY || p->type == TSDB_DATA_TYPE_NCHAR) { - offset += sizeof(int32_t); - } else { - offset += p->bytes; - } } if (pCol == NULL) { return -1; // No matched tags. Maybe the modification of tags has not been done yet. } - assert(pCol != NULL); - SDataRow row = (SDataRow)pTable->tagVal; - char* d = tdGetRowDataOfCol(row, pCol->type, TD_DATA_ROW_HEAD_SIZE + offset); + char* d = tdGetRowDataOfCol(row, pCol->type, TD_DATA_ROW_HEAD_SIZE + pCol->offset); *val = d; *type = pCol->type; @@ -263,15 +264,22 @@ int32_t tsdbGetTableTagVal(TsdbRepoT* repo, STableId* id, int32_t colId, int16_t return TSDB_CODE_SUCCESS; } -int32_t tsdbGetTableName(TsdbRepoT *repo, STableId* id, char** name) { +char* tsdbGetTableName(TsdbRepoT *repo, const STableId* id, int16_t* bytes) { STsdbMeta* pMeta = tsdbGetMeta(repo); STable* pTable = tsdbGetTableByUid(pMeta, id->uid); - *name = strndup(pTable->name, TSDB_TABLE_NAME_LEN); - if (*name == NULL) { - return -1; + if (pTable == NULL) { + if (bytes != NULL) { + *bytes = 0; + } + + return NULL; } else { - return 0; + if (bytes != NULL) { + *bytes = varDataLen(pTable->name); + } + + return (char*) pTable->name; } } @@ -296,7 +304,11 @@ int32_t tsdbCreateTableImpl(STsdbMeta *pMeta, STableCfg *pCfg) { super->schema = tdDupSchema(pCfg->schema); super->tagSchema = tdDupSchema(pCfg->tagSchema); super->tagVal = NULL; - super->name = strdup(pCfg->sname); + + // todo refactor extract method + size_t size = strnlen(pCfg->sname, TSDB_TABLE_NAME_LEN); + super->name = malloc(size + VARSTR_HEADER_SIZE); + STR_WITH_SIZE_TO_VARSTR(super->name, pCfg->sname, size); // index the first tag column STColumn* pColSchema = schemaColAt(super->tagSchema, 0); @@ -322,7 +334,11 @@ int32_t tsdbCreateTableImpl(STsdbMeta *pMeta, STableCfg *pCfg) { } table->tableId = pCfg->tableId; - table->name = strdup(pCfg->name); + + size_t size = strnlen(pCfg->name, TSDB_TABLE_NAME_LEN); + table->name = malloc(size + VARSTR_HEADER_SIZE); + STR_WITH_SIZE_TO_VARSTR(table->name, pCfg->name, size); + table->lastKey = 0; if (IS_CREATE_STABLE(pCfg)) { // TSDB_CHILD_TABLE table->type = TSDB_CHILD_TABLE; @@ -513,11 +529,14 @@ static int tsdbAddTableIntoIndex(STsdbMeta *pMeta, STable *pTable) { // NOTE: do not allocate the space for key, since in each skip list node, only keep the pointer to pTable, not the // actual key value, and the key value will be retrieved during query through the pTable and getTagIndexKey function - SSkipListNode* pNode = calloc(1, headSize + POINTER_BYTES); + SSkipListNode* pNode = calloc(1, headSize + sizeof(STableIndexElem)); pNode->level = level; SSkipList* list = pSTable->pIndex; - memcpy(SL_GET_NODE_DATA(pNode), &pTable, POINTER_BYTES); + STableIndexElem* elem = (STableIndexElem*) (SL_GET_NODE_DATA(pNode)); + + elem->pTable = pTable; + elem->pMeta = pMeta; tSkipListPut(list, pNode); return 0; @@ -539,7 +558,7 @@ static int tsdbRemoveTableFromIndex(STsdbMeta *pMeta, STable *pTable) { static int tsdbEstimateTableEncodeSize(STable *pTable) { int size = 0; size += T_MEMBER_SIZE(STable, type); - size += sizeof(int) + strlen(pTable->name); + size += sizeof(int) + varDataLen(pTable->name); size += T_MEMBER_SIZE(STable, tableId); size += T_MEMBER_SIZE(STable, superUid); size += T_MEMBER_SIZE(STable, sversion); @@ -556,8 +575,7 @@ static int tsdbEstimateTableEncodeSize(STable *pTable) { return size; } -char *getTupleKey(const void * data) { +char *getTSTupleKey(const void * data) { SDataRow row = (SDataRow)data; - return POINTER_SHIFT(row, TD_DATA_ROW_HEAD_SIZE); } \ No newline at end of file diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index 008ad223ed718de420bcb770b6dec4d736afb6e4..cbb128045eb849d00b9b9b03ea0c9d04abd37de7 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -1076,17 +1076,13 @@ static int tsdbReadRowsFromCache(SSkipListIterator* pIter, STable* pTable, TSKEY } assert(offset != -1); // todo handle error + void *value = tdGetRowDataOfCol(row, pColInfo->info.type, TD_DATA_ROW_HEAD_SIZE + offset); if (pColInfo->info.type == TSDB_DATA_TYPE_BINARY || pColInfo->info.type == TSDB_DATA_TYPE_NCHAR) { - void *value = tdGetRowDataOfCol(row, pColInfo->info.type, TD_DATA_ROW_HEAD_SIZE + offset); memcpy(pData, value, varDataTLen(value)); - - offset += sizeof(int32_t); } else { - memcpy(pData, dataRowTuple(row) + offset, pColInfo->info.bytes); - offset += pColInfo->info.bytes; + memcpy(pData, value, pColInfo->info.bytes); } - } numOfRows++; @@ -1225,8 +1221,8 @@ static int32_t getAllTableIdList(STable* pSuperTable, SArray* list) { while (tSkipListIterNext(iter)) { SSkipListNode* pNode = tSkipListIterGet(iter); - STable* t = *(STable**)SL_GET_NODE_DATA(pNode); - taosArrayPush(list, &t->tableId); + STableIndexElem* elem = (STableIndexElem*)(SL_GET_NODE_DATA((SSkipListNode*) pNode)); + taosArrayPush(list, &elem->pTable->tableId); } tSkipListDestroyIter(iter); @@ -1235,6 +1231,7 @@ static int32_t getAllTableIdList(STable* pSuperTable, SArray* list) { /** * convert the result pointer to table id instead of table object pointer + * todo remove it by using callback function to change the final result in-time. * @param pRes */ static void convertQueryResult(SArray* pRes, SArray* pTableList) { @@ -1244,8 +1241,8 @@ static void convertQueryResult(SArray* pRes, SArray* pTableList) { size_t size = taosArrayGetSize(pTableList); for (int32_t i = 0; i < size; ++i) { // todo speedup by using reserve space. - STable* pTable = taosArrayGetP(pTableList, i); - taosArrayPush(pRes, &pTable->tableId); + STableIndexElem* elem = taosArrayGet(pTableList, i); + taosArrayPush(pRes, &elem->pTable->tableId); } } @@ -1309,7 +1306,12 @@ void filterPrepare(void* expr, void* param) { pInfo->q = (char*) pCond->arr; } else { pInfo->q = calloc(1, pSchema->bytes); - tVariantDump(pCond, pInfo->q, pSchema->type); + if (pSchema->type == TSDB_DATA_TYPE_BINARY || pSchema->type == TSDB_DATA_TYPE_NCHAR) { + varDataSetLen(pInfo->q, pCond->nLen); + tVariantDump(pCond, varDataVal(pInfo->q), pSchema->type); + } else { + tVariantDump(pCond, pInfo->q, pSchema->type); + } } } @@ -1341,16 +1343,16 @@ int32_t tableGroupComparFn(const void *p1, const void *p2, const void *param) { int32_t bytes = 0; if (colIndex == TSDB_TBNAME_COLUMN_INDEX) { - f1 = pTable1->name; - f2 = pTable2->name; + f1 = (char*) pTable1->name; + f2 = (char*) pTable2->name; type = TSDB_DATA_TYPE_BINARY; - bytes = TSDB_TABLE_NAME_LEN; + bytes = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; } else { - f1 = dataRowTuple(pTable1->tagVal); - f2 = dataRowTuple(pTable2->tagVal); - - type = schemaColAt(pTableGroupSupp->pTagSchema, colIndex)->type; - bytes = schemaColAt(pTableGroupSupp->pTagSchema, colIndex)->bytes; + STColumn* pCol = schemaColAt(pTableGroupSupp->pTagSchema, colIndex); + bytes = pCol->bytes; + + f1 = tdGetRowDataOfCol(pTable1->tagVal, pCol->type, TD_DATA_ROW_HEAD_SIZE + pCol->offset); + f2 = tdGetRowDataOfCol(pTable2->tagVal, pCol->type, TD_DATA_ROW_HEAD_SIZE + pCol->offset); } int32_t ret = doCompare(f1, f2, type, bytes); @@ -1428,24 +1430,20 @@ SArray* createTableGroup(SArray* pTableList, STSchema* pTagSchema, SColIndex* pC bool tSkipListNodeFilterCallback(const void* pNode, void* param) { tQueryInfo* pInfo = (tQueryInfo*) param; - - STable* pTable = *(STable**)(SL_GET_NODE_DATA((SSkipListNode*)pNode)); + + STableIndexElem* elem = (STableIndexElem*)(SL_GET_NODE_DATA((SSkipListNode*)pNode)); char* val = NULL; int8_t type = pInfo->sch.type; if (pInfo->colIndex == TSDB_TBNAME_COLUMN_INDEX) { - val = pTable->name; + val = (char*) elem->pTable->name; type = TSDB_DATA_TYPE_BINARY; } else { STSchema* pTSchema = (STSchema*) pInfo->param; // todo table schema is identical to stable schema?? int32_t offset = pTSchema->columns[pInfo->colIndex].offset; - if (pInfo->sch.type == TSDB_DATA_TYPE_BINARY || pInfo->sch.type == TSDB_DATA_TYPE_NCHAR) { - val = tdGetRowDataOfCol(pTable->tagVal, pInfo->sch.type, TD_DATA_ROW_HEAD_SIZE + offset); - } else { - val = dataRowTuple(pTable->tagVal) + offset; - } + val = tdGetRowDataOfCol(elem->pTable->tagVal, pInfo->sch.type, TD_DATA_ROW_HEAD_SIZE + offset); } int32_t ret = 0; @@ -1456,8 +1454,6 @@ bool tSkipListNodeFilterCallback(const void* pNode, void* param) { ret = pInfo->compare(val, pInfo->q); } } else { -// tVariant t = {0}; -// tVariantCreateFromBinary(&t, val, (uint32_t)pInfo->sch.bytes, type); ret = pInfo->compare(val, pInfo->q); } @@ -1502,7 +1498,7 @@ static int32_t doQueryTableList(STable* pSTable, SArray* pRes, tExprNode* pExpr) .pExtInfo = pSTable->tagSchema, }; - SArray* pTableList = taosArrayInit(8, POINTER_BYTES); + SArray* pTableList = taosArrayInit(8, sizeof(STableIndexElem)); tExprTreeTraverse(pExpr, pSTable->pIndex, pTableList, &supp); tExprTreeDestroy(&pExpr, destroyHelper); diff --git a/src/util/src/talgo.c b/src/util/src/talgo.c index 32978453fc676cfb8d47fca10483471d275ad7e9..f343912cde267855bc083fbde47f380e9609742e 100644 --- a/src/util/src/talgo.c +++ b/src/util/src/talgo.c @@ -144,11 +144,11 @@ static void tqsortImpl(void *src, int32_t start, int32_t end, size_t size, const } if (leftPartEnd > start) { - tqsortImpl(src, size, start, leftPartEnd, param, comparFn, buf); + tqsortImpl(src, start, leftPartEnd, size, param, comparFn, buf); } if (rightPartStart < end) { - tqsortImpl(src, size, rightPartStart, end, param, comparFn, buf); + tqsortImpl(src, rightPartStart, end, size, param, comparFn, buf); } } diff --git a/src/util/src/tcompare.c b/src/util/src/tcompare.c index 2d6ae13f97b8394074eb265ac1a78a34fe5cf527..643f54550b0c3f2617abf2a539d2ddad7e6e1f57 100644 --- a/src/util/src/tcompare.c +++ b/src/util/src/tcompare.c @@ -60,8 +60,15 @@ int32_t compareDoubleVal(const void *pLeft, const void *pRight) { } } -int32_t compareStrVal(const void *pLeft, const void *pRight) { - return (int32_t)strcmp(pLeft, pRight); +int32_t compareLenPrefixedStr(const void *pLeft, const void *pRight) { + int32_t len1 = varDataLen(pLeft); + int32_t len2 = varDataLen(pRight); + + if (len1 != len2) { + return len1 > len2? 1:-1; + } else { + return (int32_t) strncmp(varDataVal(pLeft), varDataVal(pRight), len1); + } } int32_t compareWStrVal(const void *pLeft, const void *pRight) { @@ -267,7 +274,7 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) { } else if (optr == TSDB_RELATION_IN) { comparFn = compareFindStrInArray; } else { /* normal relational comparFn */ - comparFn = compareStrVal; + comparFn = compareLenPrefixedStr; } break; @@ -296,6 +303,7 @@ __compar_fn_t getKeyComparFunc(int32_t keyType) { switch (keyType) { case TSDB_DATA_TYPE_TINYINT: + case TSDB_DATA_TYPE_BOOL: comparFn = compareInt8Val; break; case TSDB_DATA_TYPE_SMALLINT: @@ -308,17 +316,13 @@ __compar_fn_t getKeyComparFunc(int32_t keyType) { case TSDB_DATA_TYPE_TIMESTAMP: comparFn = compareInt64Val; break; - case TSDB_DATA_TYPE_BOOL: - comparFn = compareInt32Val; - break; - case TSDB_DATA_TYPE_FLOAT: case TSDB_DATA_TYPE_DOUBLE: comparFn = compareDoubleVal; break; case TSDB_DATA_TYPE_BINARY: - comparFn = compareStrVal; + comparFn = compareLenPrefixedStr; break; case TSDB_DATA_TYPE_NCHAR: @@ -349,13 +353,20 @@ int32_t doCompare(const char* f1, const char* f2, int32_t type, size_t size) { } return (ret < 0) ? -1 : 1; } - default: { - int32_t ret = strncmp(f1, f2, (size_t)size); - if (ret == 0) { - return ret; - } + default: { // todo refactor + tstr* t1 = (tstr*) f1; + tstr* t2 = (tstr*) f2; - return (ret < 0) ? -1 : 1; + if (t1->len != t2->len) { + return t1->len > t2->len? 1:-1; + } else { + int32_t ret = strncmp(t1->data, t2->data, t1->len); + if (ret == 0) { + return 0; + } else { + return ret < 0? -1:1; + } + } } } } diff --git a/tests/script/general/cache/restart_metrics.sim b/tests/script/general/cache/restart_metrics.sim index dbd15b945f6cb855a67f2531547af8c95b874897..c85a66869ac6cc24fc14645ccf1aa4fc7a1f4e8f 100644 --- a/tests/script/general/cache/restart_metrics.sim +++ b/tests/script/general/cache/restart_metrics.sim @@ -27,11 +27,15 @@ sql create table $tb using $mt tags( "1" ) sql insert into $tb values (now, 1) sql select * from $tb -print ===>rows $rows, data $data01 +#print ===>rows $rows, data $data01 + if $rows != 1 then + print expect 1, actual: $rows return -1 -endi +endi + if $data01 != 1 then + print expect 1 actual: $data01 return -1 endi @@ -66,8 +70,10 @@ sql select * from $tb print ===>rows $rows, data $data01 if $rows != 1 then return -1 -endi +endi + if $data01 != 1 then + print expect 1, actual $data01 return -1 endi @@ -80,6 +86,7 @@ if $data01 != 1 then return -1 endi if $data02 != 3 then + print expect 3 actual: $data02 return -1 endi diff --git a/tests/script/general/field/bigint.sim b/tests/script/general/field/bigint.sim index 5cca73595c9159c8da8cea31e24471814f8f9771..10060f7422f50ccbb36b118d9dbfbc7729059e3f 100644 --- a/tests/script/general/field/bigint.sim +++ b/tests/script/general/field/bigint.sim @@ -132,7 +132,9 @@ endi print =============== step6 sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from $mt where tbcol = 1 group by tgcol print $data00 $data01 $data02 $data03 $data04 $data05 $data06 -if $data00 != 100 then +print $data10 $data11 $data12 $data13 $data14 $data15 $data16 +if $data00 != 100 then + print expect 100, actual $data00 return -1 endi diff --git a/tests/script/general/parser/testSuite.sim b/tests/script/general/parser/testSuite.sim index aaf8979337f8914d0fc2aa50aceda2cff6c8bd71..0719d1c330c42ad983696f256ae7240bf049bfab 100644 --- a/tests/script/general/parser/testSuite.sim +++ b/tests/script/general/parser/testSuite.sim @@ -1,113 +1,97 @@ -# run general/parser/alter.sim -# sleep 2000 -# run general/parser/alter1.sim -# sleep 2000 -# run general/parser/alter_stable.sim -# sleep 2000 -# run general/parser/auto_create_tb.sim -# sleep 2000 -# run general/parser/auto_create_tb_drop_tb.sim -# sleep 2000 +#run general/parser/alter.sim +#sleep 2000 +#run general/parser/alter1.sim +#sleep 2000 +#run general/parser/alter_stable.sim +#sleep 2000 +#run general/parser/auto_create_tb.sim +#sleep 2000 +#run general/parser/auto_create_tb_drop_tb.sim -run general/parser/binary_escapeCharacter.sim -sleep 2000 -run general/parser/bug.sim sleep 2000 run general/parser/col_arithmetic_operation.sim sleep 2000 -run general/parser/columnValue_bigint.sim +run general/parser/columnValue.sim sleep 2000 -run general/parser/columnValue_bool.sim +run general/parser/commit.sim sleep 2000 -run general/parser/columnValue_double.sim +run general/parser/create_db.sim sleep 2000 -run general/parser/columnValue_float.sim +run general/parser/create_mt.sim sleep 2000 -run general/parser/columnValue_int.sim +run general/parser/create_tb.sim +sleep 2000 +run general/parser/dbtbnameValidate.sim +sleep 2000 +run general/parser/import_commit1.sim +sleep 2000 +run general/parser/import_commit2.sim +sleep 2000 +run general/parser/import_commit3.sim +sleep 2000 +run general/parser/insert_tb.sim +sleep 2000 +run general/parser/first_last.sim +sleep 2000 +run general/parser/import_file.sim +sleep 2000 +run general/parser/fill.sim +sleep 2000 +run general/parser/fill_stb.sim +sleep 2000 +run general/parser/tags_dynamically_specifiy.sim +sleep 2000 +run general/parser/interp.sim +run general/parser/lastrow.sim +sleep 2000 +run general/parser/limit.sim +sleep 2000 +run general/parser/limit1.sim +sleep 2000 +run general/parser/limit1_tblocks100.sim +sleep 2000 +run general/parser/limit2.sim +sleep 2000 +run general/parser/mixed_blocks.sim +sleep 2000 +run general/parser/nchar.sim +sleep 2000 +run general/parser/null_char.sim +sleep 2000 +run general/parser/selectResNum.sim +sleep 2000 +run general/parser/select_across_vnodes.sim sleep 2000 - -# sleep 2000 -# run general/parser/col_arithmetic_operation.sim -# sleep 2000 -# run general/parser/columnValue.sim -# sleep 2000 -# run general/parser/commit.sim -# run general/parser/create_db.sim -# sleep 2000 -# run general/parser/create_mt.sim -# sleep 2000 -# run general/parser/create_tb.sim -# sleep 2000 -# run general/parser/dbtbnameValidate.sim -# sleep 2000 -# run general/parser/fill.sim -# sleep 2000 -# run general/parser/fill_stb.sim -# sleep 2000 -# run general/parser/first_last.sim -# sleep 2000 -# run general/parser/import_commit1.sim -# sleep 2000 -# run general/parser/import_commit2.sim -# sleep 2000 -# run general/parser/import_commit3.sim -# sleep 2000 -# run general/parser/import_file.sim -# sleep 2000 -# run general/parser/insert_tb.sim -# sleep 2000 -# run general/parser/tags_dynamically_specifiy.sim -# sleep 2000 -# run general/parser/interp.sim -# run general/parser/lastrow.sim -# sleep 2000 -# run general/parser/limit.sim -# sleep 2000 -# run general/parser/limit1.sim -# sleep 2000 -# run general/parser/limit1_tblocks100.sim -# sleep 2000 -# run general/parser/limit2.sim -# sleep 2000 -# run general/parser/mixed_blocks.sim -# sleep 2000 -# run general/parser/nchar.sim -# sleep 2000 -# run general/parser/null_char.sim -# sleep 2000 -# run general/parser/selectResNum.sim -# sleep 2000 -# run general/parser/select_across_vnodes.sim -# sleep 2000 run general/parser/select_from_cache_disk.sim sleep 2000 -# run general/parser/set_tag_vals.sim -# sleep 2000 -# run general/parser/single_row_in_tb.sim -# sleep 2000 -# run general/parser/slimit.sim -# sleep 2000 +run general/parser/set_tag_vals.sim +sleep 2000 +run general/parser/single_row_in_tb.sim +sleep 2000 +run general/parser/slimit.sim +sleep 2000 run general/parser/slimit1.sim sleep 2000 -run general/parser/slimit1_query.sim -sleep 2000 -# run general/parser/slimit_alter_tags.sim -# sleep 2000 -# run general/parser/stream_on_sys.sim -# sleep 2000 -# run general/parser/stream.sim -# sleep 2000 -# run general/parser/tbnameIn.sim -# sleep 2000 -# run general/parser/where.sim -# sleep 2000 -# #run general/parser/repeatAlter.sim -# sleep 2000 -# #run general/parser/repeatStream.sim -# sleep 2000 -# run general/parser/join.sim -# run general/parser/join_multivnode.sim -# run general/parser/projection_limit_offset.sim -# sleep 2000 -# run general/parser/select_with_tags.sim -# run general/parser/groupby.sim +run general/parser/slimit_alter_tags.sim +sleep 2000 +run general/parser/stream_on_sys.sim +sleep 2000 +run general/parser/stream.sim +sleep 2000 +run general/parser/tbnameIn.sim +sleep 2000 +run general/parser/where.sim +sleep 2000 +#run general/parser/repeatAlter.sim +sleep 2000 +#run general/parser/repeatStream.sim +sleep 2000 +run general/parser/join.sim +sleep 2000 +run general/parser/join_multivnode.sim +sleep 2000 +run general/parser/projection_limit_offset.sim +sleep 2000 +run general/parser/select_with_tags.sim +sleep 2000 +run general/parser/groupby.sim diff --git a/tests/script/general/tag/bool.sim b/tests/script/general/tag/bool.sim index 540eaf123872d3cbdba15fd3556866802992be9a..349cb738bffbb216305af0718611987ae7f20f9c 100644 --- a/tests/script/general/tag/bool.sim +++ b/tests/script/general/tag/bool.sim @@ -122,7 +122,8 @@ if $rows != 100 then return -1 endi sql select * from $mt where tgcol = 1 -if $rows != 100 then +if $rows != 100 then + print expect 100, actual:$rows return -1 endi sql select * from $mt where tgcol <> 1 diff --git a/tests/script/general/tag/filter.sim b/tests/script/general/tag/filter.sim index 4388f029f9c84b707ae564962e398c098b4b5529..75a6ed00da6d3b8173b748961d42ab8f909e7ef1 100644 --- a/tests/script/general/tag/filter.sim +++ b/tests/script/general/tag/filter.sim @@ -122,7 +122,8 @@ endi print =============== step14 sql select count(tbcol) as c from $mt where ts > 1000 group by tgcol print $data00 $data01 $data02 $data03 $data04 $data05 $data06 -if $data00 != 100 then +if $data00 != 100 then + print expect 100, actual $data00 return -1 endi diff --git a/tests/script/test.sh b/tests/script/test.sh index 743597eabd1a301cc45990bce12f5727f18042e0..8e3959a680b8e3d908645802db2d93c946aa4d62 100755 --- a/tests/script/test.sh +++ b/tests/script/test.sh @@ -99,7 +99,8 @@ echo "cDebugFlag 135" >> $TAOS_CFG echo "httpDebugFlag 135" >> $TAOS_CFG echo "monitorDebugFlag 135" >> $TAOS_CFG echo "udebugFlag 135" >> $TAOS_CFG -echo "clog 0" >> $TAOS_CFG +echo "tablemetakeeptimer 5" >> $TAOS_CFG +echo "wal 0" >> $TAOS_CFG echo "asyncLog 0" >> $TAOS_CFG echo "locale en_US.UTF-8" >> $TAOS_CFG echo " " >> $TAOS_CFG