diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index afec5896cd38b4ac783a58a67ea987f0013cafd5..11d6665614c4a4075fbd7cc056cce2fcc107a946 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -122,7 +122,7 @@ void initGroupedResultInfo(SGroupResInfo* pGroupResInfo, SSHashObj* pHashmap, in if (order == TSDB_ORDER_ASC || order == TSDB_ORDER_DESC) { __compar_fn_t fn = (order == TSDB_ORDER_ASC) ? resultrowComparAsc : resultrowComparDesc; - int32_t size = POINTER_BYTES; + int32_t size = POINTER_BYTES; taosSort(pGroupResInfo->pRows->pData, taosArrayGetSize(pGroupResInfo->pRows), size, fn); } @@ -752,8 +752,8 @@ end: } static int tableUidCompare(const void* a, const void* b) { - uint64_t u1 = *(uint64_t*)a; - uint64_t u2 = *(uint64_t*)b; + int64_t u1 = *(uint64_t*)a; + int64_t u2 = *(uint64_t*)b; if (u1 == u2) { return 0; } diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index 115a6ab5592c7e17df49a3e080a69922cee11fdf..b7823136888f11e7564fb8284ef44c75d2ceda24 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -3191,12 +3191,24 @@ static int32_t optSysCheckOper(SNode* pOpear) { } return 0; } + +static int tableUidCompare(const void* a, const void* b) { + int64_t u1 = *(int64_t*)a; + int64_t u2 = *(int64_t*)b; + if (u1 == u2) { + return 0; + } + return u1 < u2 ? -1 : 1; +} static int32_t optSysMergeRslt(SArray* mRslt, SArray* rslt) { // TODO, find comm mem from mRslt for (int i = 0; i < taosArrayGetSize(mRslt); i++) { SArray* aRslt = taosArrayGetP(mRslt, i); taosArrayAddAll(rslt, aRslt); } + taosArraySort(rslt, tableUidCompare); + taosArrayRemoveDuplicate(rslt, tableUidCompare, NULL); + return 0; } @@ -3455,7 +3467,7 @@ static SSDataBlock* sysTableBuildUserTablesByUids(SOperatorInfo* pOperator) { if (i >= taosArrayGetSize(pIdx->uids)) { doSetOperatorCompleted(pOperator); } else { - pIdx->lastIdx = i; + pIdx->lastIdx = i + 1; } blockDataDestroy(p); @@ -3464,7 +3476,9 @@ static SSDataBlock* sysTableBuildUserTablesByUids(SOperatorInfo* pOperator) { return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes; } static SSDataBlock* sysTableBuildUserTables(SOperatorInfo* pOperator) { - SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + + qError("%p buildUserTable", pTaskInfo); SSysTableScanInfo* pInfo = pOperator->info; if (pInfo->pCur == NULL) { pInfo->pCur = metaOpenTbCursor(pInfo->readHandle.meta); diff --git a/tests/script/tsim/stable/metrics_idx.sim b/tests/script/tsim/stable/metrics_idx.sim new file mode 100644 index 0000000000000000000000000000000000000000..844d41f3a83fe729fe0b9241e2b914efeabff7b7 --- /dev/null +++ b/tests/script/tsim/stable/metrics_idx.sim @@ -0,0 +1,65 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start +sql connect + +$dbPrefix = m_me_db_idx +$tbPrefix = m_me_tb_idx +$mtPrefix = m_me_mt_idx + +print =============== step1 +$i = 0 +$db = $dbPrefix +$mt = $mtPrefix + +sql drop database if exists $db +sql create database $db + +sql use $db + +sql create table $mt (ts timestamp, speed int) TAGS(sp int) + +$tbNum = 10000 + +while $i < $tbNum + $tb = $tbPrefix . $i + sql insert into $tb using $mt tags( $i ) values(now, $i ) + $i = $i + 1 +endw + +sql use information_schema +sql select count(*) from ins_tables where db_name = "m_me_db_idx" and create_time > now() - 10m +if $data[0][0] != $tbNum then + return -1 +endi + +sql select count(*) from ins_tables where db_name = "m_me_db_idx" and create_time < now(); +if $data[0][0] != $tbNum then + return -1 +endi + +sleep 1000 + + +sql use $db +$doubletbNum = 20000 + +while $i < $doubletbNum + $tb = $tbPrefix . $i + sql insert into $tb using $mt tags( $i ) values(now, $i ) + $i = $i + 1 +endw + + +sql use information_schema + +sql select count(*) from ins_tables where db_name = "m_me_db_idx" and create_time < now(); +if $data[0][0] != $doubletbNum then + print ==== $data[0][0] + return -1 +endi + + + + +