long_where_query.py 10.7 KB
Newer Older
H
happyguoxy 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
###################################################################
#           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 -*-

import random
import string
import os
import time
from util.log import tdLog
from util.cases import tdCases
from util.sql import tdSql
from util.dnodes import tdDnodes

class TDTestCase:
    updatecfgDict={'maxSQLLength':1048576}
    def init(self, conn, logSql):
        tdLog.debug("start to execute %s" % __file__)
        tdSql.init(conn.cursor(), logSql)

        self.ts = 1538548685000
        self.num = 100

    def get_random_string(self, length):
        letters = string.ascii_lowercase
        result_str = ''.join(random.choice(letters) for i in range(length))
        return result_str

    def run(self):
        tdSql.prepare()
        # test case for https://jira.taosdata.com:18080/browse/TD-5213

        print("==============step1, regular table==============")
        startTime = time.time() 
        sql = "create table regular_table_1(ts timestamp, "
        for i in range(4094):
            sql += "col00000111112222233333444445555566666777778888899999000000l%d int, " % (i + 1)
        sql += "col4095 binary(22))"  
        tdLog.info(len(sql))      
        tdSql.execute(sql)

        tdLog.info("========== test1.1 : test regular table in ( ) ==========")
        sql = '''insert into regular_table_1(ts,col00000111112222233333444445555566666777778888899999000000l1) values(now,1);'''
        tdSql.execute(sql)
        sql = ''' select * from regular_table_1  where  col00000111112222233333444445555566666777778888899999000000l1 in (1); '''
        tdSql.query(sql)  
        tdSql.checkData(0, 1, 1)

        for i in range(self.num):
            sql = "insert into regular_table_1 values(%d, "
            for j in range(4094):
                str = "'%s', " % random.randint(0,1000)                
                sql += str
            sql += "'%s')" % self.get_random_string(22)
            tdSql.execute(sql % (self.ts + i))
        time.sleep(1)
        tdSql.query("select count(*) from regular_table_1")
        tdSql.checkData(0, 0, self.num+1)
        tdSql.query("select * from regular_table_1")
        tdSql.checkRows(self.num+1)
        tdSql.checkCols(4096)

        #maxSQLLength 1048576
        sql = "select * from regular_table_1 where col00000111112222233333444445555566666777778888899999000000l1 in ("
        for i in range(2,128840):
            sql += "%d , " % (i + 1)
        sql += "1 ,12345) order by ts desc;"  
        #tdLog.info(sql)
        tdLog.info(len(sql)) 
        tdSql.query(sql)  
        tdSql.checkData(0, 1, 1)
        tdSql.checkCols(4096)

        #maxSQLLength 1048577--error
        sql = "select * from regular_table_1 where col00000111112222233333444445555566666777778888899999000000l1 in ("
        for i in range(2,128840):
            sql += "%d , " % (i + 1)
        sql += "1 ,123456) order by ts desc;"  
        #tdLog.info(sql)
        tdLog.info(len(sql))  
        tdSql.error(sql)  

        tdLog.info("========== test1.2 : test regular table in (' ') ==========")
        sql = '''insert into regular_table_1(ts,col4095) values(now,1);'''
        tdSql.execute(sql)
        sql = ''' select * from regular_table_1  where  col4095 in ('1',"1"); '''
        tdSql.query(sql)  
        tdSql.checkData(0, 4095, 1)

        #maxSQLLength 1048576
        sql = " select * from regular_table_1 where col4095 in ("
        for i in range(96328):
            sql += " '%d' , " % (i + 1)
        sql += " '1' ) order by ts desc;" 
        #tdLog.info(sql)
        tdLog.info(len(sql)) 
        tdSql.query(sql)  
        tdSql.checkData(0, 4095, 1)
        tdSql.checkCols(4096)
        
        #maxSQLLength 1048577--error
        sql = " select * from regular_table_1 where col4095 in ("
        for i in range(96328):
            sql += " '%d' , " % (i + 1)
        sql += " '123' ) order by ts desc;" 
        #tdLog.info(sql)
        tdLog.info(len(sql))   
        tdSql.error(sql)  
        
        endTime = time.time()
        print("total time %ds" % (endTime - startTime))
 



        print("==============step2, super table ==============")
        startTime = time.time() 
        sql = "create stable stable_1(ts timestamp, "
        for i in range(4090):
            sql += "col00000111112222233333444445555566666777778888899999000000l%d int, " % (i + 1)
        sql += "col4091 binary(22))"  
        sql += " tags (loc nchar(10),tag_1 int,tag_2 int,tag_3 int) " 
        tdLog.info(len(sql))      
        tdSql.execute(sql)
        sql = '''create table table_1 using stable_1 
                    tags('table_1' , '1' , '2' , '3' );'''
        tdSql.execute(sql)

        tdLog.info("========== test2.1 : test super table in ( ) ==========")
        sql = '''insert into table_1(ts,col00000111112222233333444445555566666777778888899999000000l1) values(now,1);'''
        tdSql.execute(sql)
        sql = ''' select * from stable_1  where  col00000111112222233333444445555566666777778888899999000000l1 in (1); '''
        tdSql.query(sql)  
        tdSql.checkData(0, 1, 1)
        sql = ''' select * from table_1  where  col00000111112222233333444445555566666777778888899999000000l1 in (1); '''
        tdSql.query(sql)  
        tdSql.checkData(0, 1, 1)

        for i in range(self.num):
            sql = "insert into table_1 values(%d, "
            for j in range(4090):
                str = "'%s', " % random.randint(0,1000)                
                sql += str
            sql += "'%s')" % self.get_random_string(22)
            tdSql.execute(sql % (self.ts + i))
        time.sleep(1)

        tdSql.query("select count(*) from table_1")
        tdSql.checkData(0, 0, self.num+1)
        tdSql.query("select * from table_1")
        tdSql.checkRows(self.num+1)
        tdSql.checkCols(4092)

        tdSql.query("select count(*) from stable_1")
        tdSql.checkData(0, 0, self.num+1)
        tdSql.query("select * from stable_1")
        tdSql.checkRows(self.num+1)
        tdSql.checkCols(4096)

        #maxSQLLength 1048576
        sql = "select * from table_1 where col00000111112222233333444445555566666777778888899999000000l1 in ("
        for i in range(128840):
            sql += "%d , " % (i + 1)
        sql += "1 ,12345) order by ts desc;"  
        #tdLog.info(sql)
        tdLog.info(len(sql)) 
        tdSql.query(sql)  
        tdSql.checkData(0, 1, 1)
        tdSql.checkCols(4092)  

        sql = "select * from stable_1 where col00000111112222233333444445555566666777778888899999000000l1 in ("
        for i in range(128840):
            sql += "%d , " % (i + 1)
        sql += "1 ,1234) order by ts desc;"  
        #tdLog.info(sql)
        tdLog.info(len(sql)) 
        tdSql.query(sql)  
        tdSql.checkData(0, 1, 1)
        tdSql.checkCols(4096)      

        #TD-5640
        sql = "select * from stable_1 where tag_1 in ("
        for i in range(128847):
            sql += "%d , " % (i + 1)
        sql += "1)order by ts desc;"  
        #tdLog.info(sql)
        tdLog.info(len(sql)) 
        tdSql.query(sql)  
        tdSql.checkData(0, 1, 1)
        tdSql.checkCols(4096)    

        #maxSQLLength 1048577--error
        sql = "select * from table_1 where col00000111112222233333444445555566666777778888899999000000l1 in ("
        for i in range(128840):
            sql += "%d , " % (i + 1)
        sql += "1 ,123456) order by ts desc;"  
        #tdLog.info(sql)
        tdLog.info(len(sql)) 
        tdSql.error(sql)    

        sql = "select * from stable_1 where col00000111112222233333444445555566666777778888899999000000l1 in ("
        for i in range(128840):
            sql += "%d , " % (i + 1)
        sql += "1 ,12345) order by ts desc;"  
        #tdLog.info(sql)
        tdLog.info(len(sql)) 
        tdSql.error(sql)    

        sql = "select * from stable_1 where tag_1 in ("
        for i in range(128847):
            sql += "%d , " % (i + 1)
        sql += "1) order by ts desc;"  
        #tdLog.info(sql)
        tdLog.info(len(sql)) 
        tdSql.error(sql)     


        tdLog.info("========== tests2.2 : test super table in (' ') ==========")
        sql = '''insert into table_1(ts,col4091) values(now,1);'''
        tdSql.execute(sql)
        sql = ''' select * from table_1  where  col4091 in ('1',"1"); '''
        tdSql.query(sql)  
        tdSql.checkData(0, 4091, 1)

        #maxSQLLength 1048576
        sql = " select * from table_1 where col4091 in ("
        for i in range(96328):
            sql += " '%d' , " % (i + 1)
        sql += " '1','123456' ) order by ts desc;" 
        #tdLog.info(sql)
        tdLog.info(len(sql)) 
        tdSql.query(sql)  
        tdSql.checkData(0, 4091, 1)
        tdSql.checkCols(4092)

        sql = " select * from stable_1 where col4091 in ("
        for i in range(96328):
            sql += " '%d' , " % (i + 1)
        sql += " '1','12345' ) order by ts desc;" 
        #tdLog.info(sql)
        tdLog.info(len(sql)) 
        tdSql.query(sql)  
        tdSql.checkData(0, 4091, 1)
        tdSql.checkCols(4096)

        #TD-5650
        sql = " select * from stable_1 where loc in ("
        for i in range(96328):
            sql += " '%d' , " % (i + 1)
        sql += " '123','table_1' ) order by ts desc;" 
        #tdLog.info(sql)
        tdLog.info(len(sql)) 
        tdSql.query(sql)  
        tdSql.checkData(0, 4092, 'table_1')
        tdSql.checkCols(4096)

        #maxSQLLength 1048577--error
        sql = " select * from table_1 where col4091 in ("
        for i in range(96328):
            sql += " '%d' , " % (i + 1)
        sql += " '1','1234567' ) order by ts desc;" 
        #tdLog.info(sql)
        tdLog.info(len(sql)) 
        tdSql.error(sql) 

        sql = " select * from stable_1 where col4091 in ("
        for i in range(96328):
            sql += " '%d' , " % (i + 1)
        sql += " '1','123456' ) order by ts desc;" 
        #tdLog.info(sql)
        tdLog.info(len(sql)) 
        tdSql.error(sql) 

        sql = " select * from stable_1 where loc in ("
        for i in range(96328):
            sql += " '%d' , " % (i + 1)
        sql += " '1','1234567890' ) order by ts desc;" 
        #tdLog.info(sql)
        tdLog.info(len(sql)) 
        tdSql.error(sql) 

        endTime = time.time()
        print("total time %ds" % (endTime - startTime))
292
        #os.system("rm -rf query/long_where_query.py.sql")
H
happyguoxy 已提交
293 294 295 296 297 298 299 300 301


    def stop(self):
        tdSql.close()
        tdLog.success("%s successfully executed" % __file__)


tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())