Merge pull request #20416 from taosdata/enh/changeTagIndexCase

change tag index case
This commit is contained in:
Shengliang Guan 2023-03-12 20:46:48 +08:00 committed by GitHub
commit 5a957eeba2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 99 additions and 95 deletions

View File

@ -11,27 +11,24 @@
# -*- coding: utf-8 -*-
from ssl import ALERT_DESCRIPTION_CERTIFICATE_UNOBTAINABLE
import taos
import os
import random
import socket
import string
import subprocess
import sys
import time
import os
import socket
import subprocess
import random
import string
import random
from ssl import ALERT_DESCRIPTION_CERTIFICATE_UNOBTAINABLE
from util.log import *
from util.sql import *
import taos
from util.cases import *
from util.common import *
from util.dnodes import *
from util.dnodes import TDDnode, TDDnodes
from util.log import *
from util.sql import *
from util.sqlset import *
from util.dnodes import *
from util.dnodes import TDDnodes
from util.dnodes import TDDnode
#
# -------------- util --------------------------
@ -67,24 +64,27 @@ def pathSize(path):
# --------------- cluster ------------------------
#
class MyDnodes(TDDnodes):
def __init__(self, dnodes_lists):
super(MyDnodes, self).__init__()
self.dnodes = dnodes_lists # dnode must be TDDnode instance
self.simDeployed = False
class TagCluster:
noConn = True
def init(self, conn, logSql, replicaVar=1):
tdLog.debug(f"start to excute {__file__}")
self.TDDnodes = None
self.depoly_cluster(5)
self.master_dnode = self.TDDnodes.dnodes[0]
self.host = self.master_dnode.cfgDict["fqdn"]
conn1 = taos.connect(self.master_dnode.cfgDict["fqdn"] , config=self.master_dnode.cfgDir)
conn1 = taos.connect(
self.master_dnode.cfgDict["fqdn"], config=self.master_dnode.cfgDir)
tdSql.init(conn1.cursor())
def getBuildPath(self):
selfPath = os.path.dirname(os.path.realpath(__file__))
@ -101,7 +101,6 @@ class TagCluster:
break
return buildPath
def depoly_cluster(self, dnodes_nums):
testCluster = False
@ -136,7 +135,8 @@ class TagCluster:
sql = ""
for dnode in self.TDDnodes.dnodes[1:]:
# print(dnode.cfgDict)
dnode_id = dnode.cfgDict["fqdn"] + ":" +dnode.cfgDict["serverPort"]
dnode_id = dnode.cfgDict["fqdn"] + \
":" + dnode.cfgDict["serverPort"]
if dnode_first_host == "":
dnode_first_host = dnode.cfgDict["firstEp"].split(":")[0]
dnode_first_port = dnode.cfgDict["firstEp"].split(":")[-1]
@ -150,7 +150,6 @@ class TagCluster:
time.sleep(2)
tdLog.info(" create cluster done! ")
def getConnection(self, dnode):
host = dnode.cfgDict["fqdn"]
port = dnode.cfgDict["serverPort"]
@ -274,31 +273,35 @@ class TDTestCase:
# create stable and child tables
def create_table(self, stbname, tbname, count):
# create stable
create_table_sql = self.set_stb_sql(stbname, self.column_dict, self.tag_dict)
create_table_sql = self.set_stb_sql(
stbname, self.column_dict, self.tag_dict)
tdSql.execute(create_table_sql)
# create child table
tdLog.info(f" start create {count} child tables.")
for i in range(count):
ti = i % 128
batchSql = ""
batchSize = 5000
for i in range(int(count/batchSize)):
batchSql = "create table"
for j in range(batchSize):
ti = (i * batchSize + j) % 128
binTxt = self.random_string(self.lenBinary)
tags = f'{ti},{ti},{i},{i},{ti},{ti},{i},{i},{i}.000{i},{i}.000{i},true,"{binTxt}","nch{i}",now'
sql = f'create table {tbname}{i} using {stbname} tags({tags})'
tdSql.execute(sql)
if i > 0 and i % 1000 == 0:
tdLog.info(f" child table count = {i}")
tdLog.info(f" end create {count} child tables.")
idx = i * batchSize + j
tags = f'{ti},{ti},{idx},{idx},{ti},{ti},{idx},{idx},{idx}.000{idx},{idx}.000{idx},true,"{binTxt}","nch{idx}",now'
sql = f'{tbname}{idx} using {stbname} tags({tags})'
batchSql = batchSql + " " + sql
tdSql.execute(batchSql)
tdLog.info(f" child table count = {i * batchSize}")
# create stable and child tables
def create_tagidx(self, stbname):
cnt = -1
for key in self.tag_dict.keys():
# first tag have default index, so skip
if cnt == -1:
cnt = 0
continue;
continue
sql = f'create index idx_{key} on {stbname} ({key})'
tdLog.info(f" sql={sql}")
tdSql.execute(sql)
@ -376,8 +379,8 @@ class TDTestCase:
self.query(sql)
tdSql.checkRows(4)
# drop child table
def drop_tables(self, tbname, count):
# table d1 and d20 have verify data , so can not drop
start = random.randint(21, count/2)
@ -396,7 +399,7 @@ class TDTestCase:
# first tag have default index, so skip
if cnt == -1:
cnt = 0
continue;
continue
sql = f'drop index idx_{key}'
tdSql.execute(sql)
cnt += 1
@ -414,11 +417,13 @@ class TDTestCase:
cnt = len(db.sqls)
cnt1 = len(db1.sqls)
if cnt != len(db1.sqls):
tdLog.info(f" datebase sql count not equal. cnt={cnt} cnt1={cnt1}\n")
tdLog.info(
f" datebase sql count not equal. cnt={cnt} cnt1={cnt1}\n")
return False
tdLog.info(f" database sql cnt ={cnt}")
print(f" ----------------- performance (child tables = {count})--------------------")
print(
f" ----------------- performance (child tables = {count})--------------------")
print(" No time(index) time(no-index) diff(col3-col2) rate(col2/col3) sql")
for i in range(cnt):
key = db.sqls[i]
@ -427,7 +432,8 @@ class TDTestCase:
value1 = db1.spends[i]
diff = value1 - value
rate = value/value1*100
print(" %d %.3fs %.3fs %.3fs %d%% %s"%(i+1, value, value1, diff, rate, key))
print(" %d %.3fs %.3fs %.3fs %d%% %s" % (
i+1, value, value1, diff, rate, key))
print(" --------------------- end ------------------------")
return True
@ -457,10 +463,8 @@ class TDTestCase:
print(" -------------------- end ------------------------")
# main
def testdb(self, dbname, stable, tbname, count, createidx):
# cur
if createidx:
@ -511,10 +515,10 @@ class TDTestCase:
self.show_diskspace()
def stop(self):
self.tagCluster.stop()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())