From 490370ddb726b70ad6ee8979ecd2f5ae4143410c Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Wed, 22 Feb 2023 10:22:22 +0800 Subject: [PATCH 1/5] test : add 0-other/tag_index_basic.py --- tests/system-test/0-others/tag_index_basic.py | 161 ++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 tests/system-test/0-others/tag_index_basic.py diff --git a/tests/system-test/0-others/tag_index_basic.py b/tests/system-test/0-others/tag_index_basic.py new file mode 100644 index 0000000000..2d2f7a231b --- /dev/null +++ b/tests/system-test/0-others/tag_index_basic.py @@ -0,0 +1,161 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + + +from util.log import * +from util.cases import * +from util.sql import * +from util.common import * +from util.sqlset import * +import random + + +class TDTestCase: + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + self.setsql = TDSetSql() + self.column_dict = { + '`ts`': 'timestamp', + '`col1`': 'tinyint', + '`col2`': 'smallint', + '`col3`': 'int', + '`col4`': 'bigint', + '`col5`': 'tinyint unsigned', + '`col6`': 'smallint unsigned', + '`col7`': 'int unsigned', + '`col8`': 'bigint unsigned', + '`col9`': 'float', + '`col10`': 'double', + '`col11`': 'bool', + '`col12`': 'varchar(20)', + '`col13`': 'nchar(20)' + } + self.tag_dict = { + '`t1`': 'tinyint', + '`t2`': 'smallint', + '`t3`': 'int', + '`t4`': 'bigint', + '`t5`': 'tinyint unsigned', + '`t6`': 'smallint unsigned', + '`t7`': 'int unsigned', + '`t8`': 'bigint unsigned', + '`t9`': 'float', + '`t10`': 'double', + '`t11`': 'bool', + '`t12`': 'varchar(20)', + '`t13`': 'nchar(20)', + '`t14`': 'timestamp' + } + + + def set_stb_sql(self,stbname,column_dict,tag_dict): + column_sql = '' + tag_sql = '' + for k,v in column_dict.items(): + column_sql += f"{k} {v}, " + for k,v in tag_dict.items(): + tag_sql += f"{k} {v}, " + create_stb_sql = f'create stable {stbname} ({column_sql[:-2]}) tags ({tag_sql[:-2]})' + return create_stb_sql + + # create stable and child tables + def create_table(self, stbname, tbname, count): + tdSql.prepare() + tdSql.execute('use db') + + # create stable + create_table_sql = self.set_stb_sql(stbname, self.column_dict, self.tag_dict) + tdSql.execute(create_table_sql) + + # create child table + for i in range(count): + tags = f'{i},{i},{i},{i},{i},{i},{i},{i},{i}.000{i},{i}.000{i},true,"var{i}","nch{i}",now' + sql = f'create table {tbname}{i} using {stbname} tags({tags})' + tdSql.execute(sql) + + + # create stable and child tables + def create_tagidx(self, stbname): + for key in self.tag_dict.keys: + sql = f'create idx_{key} on {stbname} ({key})' + tdSql.execute(sql) + + # check show indexs + def show_tagidx(self, stbname): + sql = f'select index_name,column_name from information_schema.ins_indexes where db_name="db"' + tdSql.execute(sql) + i = 0 + for key in self.tag_dict.keys: + tdSql.checkData(i, 0, f'idx_{key}') + tdSql.checkData(i, 1, f'{key}') + i += 1 + + # query with tag idx + def query_tagidx(self, stbname): + sql = f'select * from meters where t1=10' + tdSql.execute(sql) + sql = f'select * from meters where t2<10' + tdSql.execute(sql) + sql = f'select * from meters where t3>10' + tdSql.execute(sql) + sql = f'select * from meters where t12="11"' + tdSql.execute(sql) + sql = f'select * from meters where (t4 < 10 or t5 = 20) and t6= 30' + tdSql.execute(sql) + sql = f'select * from meters where (t7 < 20 and t8 = 20) or t9= 30' + tdSql.execute(sql) + + # drop child table + def drop_tables(self, tbname, count): + start = random.randint(1, count/2) + end = random.random(count/2 + 1, count - 1) + for i in range(start, end): + sql = f'drop table {tbname}{i}' + tdSql.execute(sql) + + # drop tag index + def drop_tagidx(self, stbname): + # drop index + for key in self.tag_dict.keys: + sql = f'drop index idx_{key}' + tdSql.execute(sql) + + # check idx result is 0 + sql = f'select index_name,column_name from information_schema.ins_indexes where db_name="db"' + tdSql.execute(sql) + tdSql.checkRows(0) + + # run + def run(self): + stable = "meters" + tbname = "d" + count = 1000 + self.create_table(stable, tbname, count) + self.create_tagidx(stable) + self.show_tagidx(stable) + self.query_tagidx(stable) + self.drop_tables(tbname, count) + self.drop_tagidx(stable) + # query after delete , expect no crash + self.query_tagidx(stable) + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) + From 40841dd6666b6baabf8e09e241cca82db1720b25 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Wed, 22 Feb 2023 11:04:57 +0800 Subject: [PATCH 2/5] test: modify tag range --- tests/system-test/0-others/tag_index_basic.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/system-test/0-others/tag_index_basic.py b/tests/system-test/0-others/tag_index_basic.py index 2d2f7a231b..015ecc5c11 100644 --- a/tests/system-test/0-others/tag_index_basic.py +++ b/tests/system-test/0-others/tag_index_basic.py @@ -81,7 +81,8 @@ class TDTestCase: # create child table for i in range(count): - tags = f'{i},{i},{i},{i},{i},{i},{i},{i},{i}.000{i},{i}.000{i},true,"var{i}","nch{i}",now' + ti = i % 128 + tags = f'{ti},{ti},{i},{i},{ti},{ti},{i},{i},{i}.000{i},{i}.000{i},true,"var{i}","nch{i}",now' sql = f'create table {tbname}{i} using {stbname} tags({tags})' tdSql.execute(sql) From b4d84f1e5e307cda81629e5f915ae8f7b3375363 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Wed, 22 Feb 2023 14:36:26 +0800 Subject: [PATCH 3/5] test: add case tag index passed ok --- tests/system-test/0-others/tag_index_basic.py | 149 ++++++++++++------ 1 file changed, 100 insertions(+), 49 deletions(-) diff --git a/tests/system-test/0-others/tag_index_basic.py b/tests/system-test/0-others/tag_index_basic.py index 015ecc5c11..76888a247f 100644 --- a/tests/system-test/0-others/tag_index_basic.py +++ b/tests/system-test/0-others/tag_index_basic.py @@ -27,36 +27,36 @@ class TDTestCase: tdSql.init(conn.cursor()) self.setsql = TDSetSql() self.column_dict = { - '`ts`': 'timestamp', - '`col1`': 'tinyint', - '`col2`': 'smallint', - '`col3`': 'int', - '`col4`': 'bigint', - '`col5`': 'tinyint unsigned', - '`col6`': 'smallint unsigned', - '`col7`': 'int unsigned', - '`col8`': 'bigint unsigned', - '`col9`': 'float', - '`col10`': 'double', - '`col11`': 'bool', - '`col12`': 'varchar(20)', - '`col13`': 'nchar(20)' + 'ts': 'timestamp', + 'col1': 'tinyint', + 'col2': 'smallint', + 'col3': 'int', + 'col4': 'bigint', + 'col5': 'tinyint unsigned', + 'col6': 'smallint unsigned', + 'col7': 'int unsigned', + 'col8': 'bigint unsigned', + 'col9': 'float', + 'col10': 'double', + 'col11': 'bool', + 'col12': 'varchar(20)', + 'col13': 'nchar(20)' } self.tag_dict = { - '`t1`': 'tinyint', - '`t2`': 'smallint', - '`t3`': 'int', - '`t4`': 'bigint', - '`t5`': 'tinyint unsigned', - '`t6`': 'smallint unsigned', - '`t7`': 'int unsigned', - '`t8`': 'bigint unsigned', - '`t9`': 'float', - '`t10`': 'double', - '`t11`': 'bool', - '`t12`': 'varchar(20)', - '`t13`': 'nchar(20)', - '`t14`': 'timestamp' + 't1': 'tinyint', + 't2': 'smallint', + 't3': 'int', + 't4': 'bigint', + 't5': 'tinyint unsigned', + 't6': 'smallint unsigned', + 't7': 'int unsigned', + 't8': 'bigint unsigned', + 't9': 'float', + 't10': 'double', + 't11': 'bool', + 't12': 'varchar(20)', + 't13': 'nchar(20)', + 't14': 'timestamp' } @@ -85,58 +85,108 @@ class TDTestCase: tags = f'{ti},{ti},{i},{i},{ti},{ti},{i},{i},{i}.000{i},{i}.000{i},true,"var{i}","nch{i}",now' sql = f'create table {tbname}{i} using {stbname} tags({tags})' tdSql.execute(sql) + + tdLog.info(f" create {count} child tables ok.") # create stable and child tables def create_tagidx(self, stbname): - for key in self.tag_dict.keys: - sql = f'create idx_{key} on {stbname} ({key})' + cnt = -1 + for key in self.tag_dict.keys(): + # first tag have default index, so skip + if cnt == -1: + cnt = 0 + continue; + sql = f'create index idx_{key} on {stbname} ({key})' + tdLog.info(f" sql={sql}") + tdSql.execute(sql) + cnt += 1 + tdLog.info(f' create {cnt} tag indexs ok.') + + # insert to child table d1 data + def insert_data(self, tbname): + # d1 insert 3 rows + for i in range(3): + sql = f'insert into {tbname}1(ts,col1) values(now,{i});' + tdSql.execute(sql) + # d20 insert 4 + for i in range(4): + sql = f'insert into {tbname}20(ts,col1) values(now,{i});' tdSql.execute(sql) # check show indexs def show_tagidx(self, stbname): sql = f'select index_name,column_name from information_schema.ins_indexes where db_name="db"' - tdSql.execute(sql) - i = 0 - for key in self.tag_dict.keys: - tdSql.checkData(i, 0, f'idx_{key}') - tdSql.checkData(i, 1, f'{key}') - i += 1 + tdSql.query(sql) + rows = len(self.tag_dict.keys())-1 + tdSql.checkRows(rows) + + for i in range(rows): + col_name = tdSql.getData(i, 1) + idx_name = f'idx_{col_name}' + tdSql.checkData(i, 0, idx_name) + + tdLog.info(f' show {rows} tag indexs ok.') # query with tag idx def query_tagidx(self, stbname): - sql = f'select * from meters where t1=10' - tdSql.execute(sql) + sql = f'select * from meters where t1=1' + tdSql.query(sql) + tdSql.checkRows(3) + sql = f'select * from meters where t2<10' - tdSql.execute(sql) - sql = f'select * from meters where t3>10' - tdSql.execute(sql) + tdSql.query(sql) + tdSql.checkRows(3) + + sql = f'select * from meters where t2>10' + tdSql.query(sql) + tdSql.checkRows(4) + + sql = f'select * from meters where t3<30' + tdSql.query(sql) + tdSql.checkRows(7) + sql = f'select * from meters where t12="11"' - tdSql.execute(sql) + tdSql.query(sql) + tdSql.checkRows(0) + sql = f'select * from meters where (t4 < 10 or t5 = 20) and t6= 30' - tdSql.execute(sql) - sql = f'select * from meters where (t7 < 20 and t8 = 20) or t9= 30' - tdSql.execute(sql) + tdSql.query(sql) + tdSql.checkRows(0) + + sql = f'select * from meters where (t7 < 20 and t8 = 20) or t4 = 20' + tdSql.query(sql) + tdSql.checkRows(4) # drop child table def drop_tables(self, tbname, count): - start = random.randint(1, count/2) - end = random.random(count/2 + 1, count - 1) + # table d1 and d20 have verify data , so can not drop + start = random.randint(21, count/2) + end = random.randint(count/2 + 1, count - 1) for i in range(start, end): sql = f'drop table {tbname}{i}' tdSql.execute(sql) + cnt = end - start + 1 + tdLog.info(f' drop table from {start} to {end} count={cnt}') # drop tag index def drop_tagidx(self, stbname): # drop index - for key in self.tag_dict.keys: + cnt = -1 + for key in self.tag_dict.keys(): + # first tag have default index, so skip + if cnt == -1: + cnt = 0 + continue; sql = f'drop index idx_{key}' tdSql.execute(sql) + cnt += 1 # check idx result is 0 sql = f'select index_name,column_name from information_schema.ins_indexes where db_name="db"' - tdSql.execute(sql) + tdSql.query(sql) tdSql.checkRows(0) + tdLog.info(f' drop {cnt} tag indexs ok.') # run def run(self): @@ -145,6 +195,7 @@ class TDTestCase: count = 1000 self.create_table(stable, tbname, count) self.create_tagidx(stable) + self.insert_data(tbname) self.show_tagidx(stable) self.query_tagidx(stable) self.drop_tables(tbname, count) From 2c8b75885a0f04f0f4219b277b027db226eac6de Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Wed, 22 Feb 2023 14:38:32 +0800 Subject: [PATCH 4/5] test: add case tag index passed ok1 --- tests/system-test/0-others/tag_index_basic.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/system-test/0-others/tag_index_basic.py b/tests/system-test/0-others/tag_index_basic.py index 76888a247f..195d8910e7 100644 --- a/tests/system-test/0-others/tag_index_basic.py +++ b/tests/system-test/0-others/tag_index_basic.py @@ -190,9 +190,11 @@ class TDTestCase: # run def run(self): + # var stable = "meters" tbname = "d" count = 1000 + # do self.create_table(stable, tbname, count) self.create_tagidx(stable) self.insert_data(tbname) @@ -209,5 +211,4 @@ class TDTestCase: tdLog.success("%s successfully executed" % __file__) tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) - +tdCases.addLinux(__file__, TDTestCase()) \ No newline at end of file From bc8b82ecc5cde9dd15cd901d2dbe7074ee0abe8d Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Thu, 23 Feb 2023 09:47:28 +0800 Subject: [PATCH 5/5] test: add tag_index_basic.py to cases.task list --- tests/parallel_test/cases.task | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index 205270e91c..63760d6ae4 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -429,6 +429,7 @@ ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/user_manage.py ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/fsync.py ,,n,system-test,python3 ./test.py -f 0-others/compatibility.py +,,n,system-test,python3 ./test.py -f 0-others/tag_index_basic.py ,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/alter_database.py ,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/influxdb_line_taosc_insert.py ,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/opentsdb_telnet_line_taosc_insert.py