From 605e63200a241b680961a7317b897fecb6a3c7fa Mon Sep 17 00:00:00 2001 From: Bomin Zhang Date: Wed, 13 May 2020 10:12:57 +0800 Subject: [PATCH] fix failed test cases --- src/client/src/tscServer.c | 7 +-- src/client/src/tscSub.c | 8 +-- src/query/src/queryExecutor.c | 63 +++++++++++++--------- tests/script/general/cache/new_metrics.sim | 2 +- 4 files changed, 47 insertions(+), 33 deletions(-) diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 32eee08541..4d9d107b01 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -39,7 +39,7 @@ int (*tscProcessMsgRsp[TSDB_SQL_MAX])(SSqlObj *pSql); void tscProcessActivityTimer(void *handle, void *tmrId); int tscKeepConn[TSDB_SQL_MAX] = {0}; -TSKEY tscGetSubscriptionProgress(void* sub, int64_t uid); +TSKEY tscGetSubscriptionProgress(void* sub, int64_t uid, TSKEY dflt); void tscUpdateSubscriptionProgress(void* sub, int64_t uid, TSKEY ts); void tscSaveSubscriptionProgress(void* sub); @@ -575,6 +575,7 @@ static int32_t tscEstimateQueryMsgSize(SSqlCmd *pCmd, int32_t clauseIndex) { static char *doSerializeTableInfo(SQueryTableMsg* pQueryMsg, SSqlObj *pSql, char *pMsg) { STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pSql->cmd, pSql->cmd.clauseIndex, 0); + TSKEY dfltKey = htobe64(pQueryMsg->window.skey); STableMeta * pTableMeta = pTableMetaInfo->pTableMeta; if (UTIL_TABLE_IS_NORMAL_TABLE(pTableMetaInfo) || pTableMetaInfo->pVgroupTables == NULL) { @@ -596,7 +597,7 @@ static char *doSerializeTableInfo(SQueryTableMsg* pQueryMsg, SSqlObj *pSql, char STableIdInfo *pTableIdInfo = (STableIdInfo *)pMsg; pTableIdInfo->tid = htonl(pTableMeta->sid); pTableIdInfo->uid = htobe64(pTableMeta->uid); - pTableIdInfo->key = htobe64(tscGetSubscriptionProgress(pSql->pSubscription, pTableMeta->uid)); + pTableIdInfo->key = htobe64(tscGetSubscriptionProgress(pSql->pSubscription, pTableMeta->uid, dfltKey)); pQueryMsg->numOfTables = htonl(1); // set the number of tables @@ -624,7 +625,7 @@ static char *doSerializeTableInfo(SQueryTableMsg* pQueryMsg, SSqlObj *pSql, char STableIdInfo *pTableIdInfo = (STableIdInfo *)pMsg; pTableIdInfo->tid = htonl(pItem->tid); pTableIdInfo->uid = htobe64(pItem->uid); - pTableIdInfo->key = htobe64(tscGetSubscriptionProgress(pSql->pSubscription, pItem->uid)); + pTableIdInfo->key = htobe64(tscGetSubscriptionProgress(pSql->pSubscription, pItem->uid, dfltKey)); pMsg += sizeof(STableIdInfo); } } diff --git a/src/client/src/tscSub.c b/src/client/src/tscSub.c index 9a3f3d290c..8e90660a24 100644 --- a/src/client/src/tscSub.c +++ b/src/client/src/tscSub.c @@ -56,16 +56,16 @@ static int tscCompareSubscriptionProgress(const void* a, const void* b) { return 0; } -TSKEY tscGetSubscriptionProgress(void* sub, int64_t uid) { +TSKEY tscGetSubscriptionProgress(void* sub, int64_t uid, TSKEY dflt) { if (sub == NULL) { - return 0; + return dflt; } SSub* pSub = (SSub*)sub; SSubscriptionProgress target = {.uid = uid, .key = 0}; SSubscriptionProgress* p = taosArraySearch(pSub->progress, tscCompareSubscriptionProgress, &target); if (p == NULL) { - return INT64_MIN; + return dflt; } return p->key; } @@ -228,7 +228,7 @@ static int tscUpdateSubscription(STscObj* pObj, SSub* pSub) { for( size_t i = 0; i < numOfTables; i++ ) { STidTags* tt = taosArrayGet( tables, i ); SSubscriptionProgress p = { .uid = tt->uid }; - p.key = tscGetSubscriptionProgress(pSub, tt->uid); + p.key = tscGetSubscriptionProgress(pSub, tt->uid, INT64_MIN); taosArrayPush(progress, &p); } taosArraySort(progress, tscCompareSubscriptionProgress); diff --git a/src/query/src/queryExecutor.c b/src/query/src/queryExecutor.c index 24f0f53ca5..f48404ab3a 100644 --- a/src/query/src/queryExecutor.c +++ b/src/query/src/queryExecutor.c @@ -4162,38 +4162,51 @@ static bool skipTimeInterval(SQueryRuntimeEnv *pRuntimeEnv) { return true; } -int32_t doInitQInfo(SQInfo *pQInfo, void *param, void *tsdb, int32_t vgId, bool isSTableQuery) { - SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv; +static void setupQueryHandle(void* tsdb, SQInfo* pQInfo, bool isSTableQuery) { + SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv; SQuery *pQuery = pQInfo->runtimeEnv.pQuery; - int32_t code = TSDB_CODE_SUCCESS; - setScanLimitationByResultBuffer(pQuery); - changeExecuteScanOrder(pQuery, false); + if (onlyQueryTags(pQuery)) { + return; + } + + if (isSTableQuery && (!isIntervalQuery(pQuery)) && (!isFixedOutputQuery(pQuery))) { + return; + } STsdbQueryCond cond = { - .twindow = pQuery->window, - .order = pQuery->order.order, - .colList = pQuery->colList, - .numOfCols = pQuery->numOfCols, + .twindow = pQuery->window, + .order = pQuery->order.order, + .colList = pQuery->colList, + .numOfCols = pQuery->numOfCols, }; - - - // normal query setup the queryhandle here - if (!onlyQueryTags(pQuery)) { - if (!isSTableQuery && isFirstLastRowQuery(pQuery)) { // in case of last_row query, invoke a different API. - pRuntimeEnv->pQueryHandle = tsdbQueryLastRow(tsdb, &cond, &pQInfo->tableIdGroupInfo); - } else if (!isSTableQuery || isIntervalQuery(pQuery) || isFixedOutputQuery(pQuery)) { - - if(pQInfo->groupInfo.numOfTables == 1) { - SArray* pa = taosArrayGetP(pQInfo->groupInfo.pGroupList, 0); - SGroupItem* pItem = taosArrayGet(pa, 0); - cond.twindow = pItem->info->win; - } - pRuntimeEnv->pQueryHandle = tsdbQueryTables(tsdb, &cond, &pQInfo->tableIdGroupInfo); - } + if (!isSTableQuery + && (pQInfo->groupInfo.numOfTables == 1) + && (cond.order == TSDB_ORDER_ASC) + && (!isIntervalQuery(pQuery)) + && (!isGroupbyNormalCol(pQuery->pGroupbyExpr)) + && (!isFixedOutputQuery(pQuery)) + ) { + SArray* pa = taosArrayGetP(pQInfo->groupInfo.pGroupList, 0); + SGroupItem* pItem = taosArrayGet(pa, 0); + cond.twindow = pItem->info->win; } + + pRuntimeEnv->pQueryHandle = tsdbQueryTables(tsdb, &cond, &pQInfo->tableIdGroupInfo); +} + + +int32_t doInitQInfo(SQInfo *pQInfo, void *param, void *tsdb, int32_t vgId, bool isSTableQuery) { + SQueryRuntimeEnv *pRuntimeEnv = &pQInfo->runtimeEnv; + + SQuery *pQuery = pQInfo->runtimeEnv.pQuery; + int32_t code = TSDB_CODE_SUCCESS; + + setScanLimitationByResultBuffer(pQuery); + changeExecuteScanOrder(pQuery, false); + setupQueryHandle(tsdb, pQInfo, isSTableQuery); pQInfo->tsdb = tsdb; pQInfo->vgId = vgId; @@ -5772,7 +5785,7 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SArray* pTableIdList, if (pTableId != NULL ) { window.skey = pTableId->key; } else { - window.skey = INT64_MIN; + window.skey = pQueryMsg->window.skey; } item.info = createTableQueryInfo(&pQInfo->runtimeEnv, item.id, window); item.info->groupIdx = i; diff --git a/tests/script/general/cache/new_metrics.sim b/tests/script/general/cache/new_metrics.sim index 64170ec67e..0e304d9acb 100644 --- a/tests/script/general/cache/new_metrics.sim +++ b/tests/script/general/cache/new_metrics.sim @@ -27,7 +27,7 @@ sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol bool) $i = 0 while $i < 5 $tb = $tbPrefix . $i - sql create table $tb using $mt tags( 0 ) + sql create table $tb using $mt tags( $i ) $x = 0 while $x < $rowNum $val = $x * 60000 -- GitLab