From 1eef25620d87d21c78e11a596881453e2643d29c Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Thu, 3 Nov 2022 10:09:36 +0800 Subject: [PATCH 1/2] fix: fix tbname in crash issue --- source/libs/executor/src/executil.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index 32386a72fd..5806aca6f2 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -925,6 +925,15 @@ static int32_t optimizeTbnameInCondImpl(void* metaHandle, int64_t suid, SArray* SArray* pTbList = getTableNameList(pList); int32_t numOfTables = taosArrayGetSize(pTbList); + SHashObj *uHash = NULL; + size_t listlen = taosArrayGetSize(list); // len > 0 means there already have uids + if (listlen > 0) { + uHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); + for (int i = 0; i < listlen; i++) { + int64_t *uid = taosArrayGet(list, i); + taosHashPut(uHash, uid, sizeof(int64_t), &i, sizeof(i)); + } + } for (int i = 0; i < numOfTables; i++) { char* name = taosArrayGetP(pTbList, i); @@ -933,9 +942,12 @@ static int32_t optimizeTbnameInCondImpl(void* metaHandle, int64_t suid, SArray* if (metaGetTableUidByName(metaHandle, name, &uid) == 0) { ETableType tbType = TSDB_TABLE_MAX; if (metaGetTableTypeByName(metaHandle, name, &tbType) == 0 && tbType == TSDB_CHILD_TABLE) { - taosArrayPush(list, &uid); + if (NULL == uHash || taosHashGet(uHash, &uid, sizeof(uid)) == NULL) { + taosArrayPush(list, &uid); + } } else { taosArrayDestroy(pTbList); + taosHashCleanup(uHash); return -1; } } else { @@ -944,6 +956,7 @@ static int32_t optimizeTbnameInCondImpl(void* metaHandle, int64_t suid, SArray* } } + taosHashCleanup(uHash); taosArrayDestroy(pTbList); return 0; } From d2a29ed7a7f6489bc593cc291abb579528432f34 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Thu, 3 Nov 2022 10:18:02 +0800 Subject: [PATCH 2/2] fix:add tbname in test cases --- tests/script/jenkins/basic.txt | 1 + tests/script/tsim/tag/tbNameIn.sim | 102 +++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 tests/script/tsim/tag/tbNameIn.sim diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 1a80aa0681..70b422cf53 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -449,6 +449,7 @@ ./test.sh -f tsim/tag/smallint.sim ./test.sh -f tsim/tag/tinyint.sim ./test.sh -f tsim/tag/drop_tag.sim +./test.sh -f tsim/tag/tbNameIn.sim ./test.sh -f tmp/monitor.sim #======================b1-end=============== diff --git a/tests/script/tsim/tag/tbNameIn.sim b/tests/script/tsim/tag/tbNameIn.sim new file mode 100644 index 0000000000..1af4bd6a9e --- /dev/null +++ b/tests/script/tsim/tag/tbNameIn.sim @@ -0,0 +1,102 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start +sql connect + +print ======== step1 +sql drop database if exists db1; +sql create database db1 vgroups 3; +sql use db1; +sql create stable st1 (ts timestamp, f1 int) tags(tg1 int); +sql create table tb1 using st1 tags(1); +sql create table tb2 using st1 tags(2); +sql create table tb3 using st1 tags(3); +sql create table tb4 using st1 tags(4); +sql create table tb5 using st1 tags(5); +sql create table tb6 using st1 tags(6); +sql create table tb7 using st1 tags(7); +sql create table tb8 using st1 tags(8); + +sql insert into tb1 values ('2022-07-10 16:31:01', 1); +sql insert into tb2 values ('2022-07-10 16:31:02', 2); +sql insert into tb3 values ('2022-07-10 16:31:03', 3); +sql insert into tb4 values ('2022-07-10 16:31:04', 4); +sql insert into tb5 values ('2022-07-10 16:31:05', 5); +sql insert into tb6 values ('2022-07-10 16:31:06', 6); +sql insert into tb7 values ('2022-07-10 16:31:07', 7); +sql insert into tb8 values ('2022-07-10 16:31:08', 8); + +sql select * from tb1 where tbname in ('tb1'); +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from tb1 where tbname in ('tb1','tb1'); +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from tb1 where tbname in ('tb1','tb2','tb1'); +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from tb1 where tbname in ('tb1','tb2','st1'); +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from tb1 where tbname = 'tb1'; +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from tb1 where tbname > 'tb1'; +if $rows != 0 then + return -1 +endi +sql select * from st1 where tbname in ('tb1'); +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from st1 where tbname in ('tb1','tb1'); +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from st1 where tbname in ('tb1','tb2','tb1'); +if $rows != 2 then + return -1 +endi +sql select * from st1 where tbname in ('tb1','tb2','st1'); +if $rows != 2 then + return -1 +endi +sql select * from st1 where tbname = 'tb1'; +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from st1 where tbname > 'tb1'; +if $rows != 7 then + return -1 +endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT