union.sim 8.9 KB
Newer Older
1 2 3
system sh/stop_dnodes.sh

system sh/deploy.sh -n dnode1 -i 1
4
system sh/cfg.sh -n dnode1 -c walLevel -v 1
5 6
system sh/cfg.sh -n dnode1 -c debugFlag -v 135
system sh/cfg.sh -n dnode1 -c rpcDebugFlag -v 135
H
Haojun Liao 已提交
7 8
system sh/cfg.sh -n dnode1 -c maxtablespervnode -v 4

9
system sh/exec.sh -n dnode1 -s start
H
Haojun Liao 已提交
10
sleep 100
H
Haojun Liao 已提交
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
sql connect

$dbPrefix = union_db
$tbPrefix = union_tb
$tbPrefix1 = union_tb_
$mtPrefix = union_mt
$tbNum = 10
$rowNum = 10000
$totalNum = $tbNum * $rowNum

print =============== union.sim
$i = 0
$db = $dbPrefix . $i
$mt = $mtPrefix . $i

$j = 1

$mt1 = $mtPrefix . $j
29

H
Haojun Liao 已提交
30
sql drop database if exists $db -x step1
31
step1:
H
Haojun Liao 已提交
32
sql create database if not exists $db
H
Haojun Liao 已提交
33
sql use $db
34 35 36 37 38
sql create table $mt (ts timestamp, c1 int, c2 float, c3 bigint, c4 smallint, c5 tinyint, c6 double, c7 bool, c8 binary(10), c9 nchar(9)) TAGS(t1 int)

$i = 0
$t = 1578203484000

H
Haojun Liao 已提交
39 40 41
$half = $tbNum / 2

while $i < $half
42
  $tb = $tbPrefix . $i
H
Haojun Liao 已提交
43 44 45 46

  $nextSuffix = $i + $half
  $tb1 = $tbPrefix . $nextSuffix

47
  sql create table $tb using $mt tags( $i )
H
Haojun Liao 已提交
48
  sql create table $tb1 using $mt tags( $nextSuffix )
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

  $x = 0
  while $x < $rowNum
    $ms = $x * 1000
    $ms = $ms * 60

    $c = $x / 100
    $c = $c * 100
    $c = $x - $c
    $binary = 'binary . $c
    $binary = $binary . '
    $nchar = 'nchar . $c
    $nchar = $nchar . '

    $t1 = $t + $ms
H
Haojun Liao 已提交
64
    sql insert into $tb values ($t1 , $c , $c , $c , $c , $c , $c , $c , $binary , $nchar )  $tb1 values ($t1 , $c , $c , $c , $c , $c , $c , $c , $binary , $nchar )
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
    $x = $x + 1
  endw

  $i = $i + 1
endw

sql create table $mt1 (ts timestamp, c1 int, c2 float, c3 bigint, c4 smallint, c5 tinyint, c6 double, c7 bool, c8 binary(10), c9 nchar(9)) TAGS(t1 int)

$j = 0
$t = 1578203484000
$rowNum = 1000
$tbNum = 5
$i = 0

while $i < $tbNum
  $tb1 = $tbPrefix1 . $j
  sql create table $tb1 using $mt1 tags( $i )

  $x = 0
  while $x < $rowNum
    $ms = $x * 1000
    $ms = $ms * 60

    $c = $x / 100
    $c = $c * 100
    $c = $x - $c
    $binary = 'binary . $c
    $binary = $binary . '
    $nchar = 'nchar . $c
    $nchar = $nchar . '

    $t1 = $t + $ms
    sql insert into $tb1 values ($t1 , $c , $c , $c , $c , $c , $c , $c , $binary , $nchar )
    $x = $x + 1
  endw

  $i = $i + 1
  $j = $j + 1
endw

print sleep 1sec.
H
Haojun Liao 已提交
106
sleep 100
H
Haojun Liao 已提交
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

$i = 1
$tb = $tbPrefix . $i

## column type not identical
sql_error select count(*) as a from union_mt0 union all select avg(c1) as a from union_mt0
sql_error select count(*) as a from union_mt0 union all select spread(c1) as a from union_mt0;

## union not supported
sql_error (select count(*) from union_mt0) union (select count(*) from union_mt0);

## column type not identical
sql_error select c1 from union_mt0 limit 10 union all select c2 from union_tb1 limit 20;

## union not support recursively union
sql_error select c1 from union_tb0 limit 2 union all (select c1 from union_tb1 limit 1 union all select c1 from union_tb3 limit 2);
sql_error (select c1 from union_tb0 limit 1 union all select c1 from union_tb1 limit 1) union all (select c1 from union_tb0 limit 10 union all select c1 from union_tb1 limit 10);

# union as subclause
sql_error (select c1 from union_tb0 limit 1 union all select c1 from union_tb1 limit 1) limit 1

# sql with parenthese
sql (((select c1 from union_tb0)))
if $rows != 10000 then
  return -1
endi

if $data00 != 0 then
  return -1
endi

if $data10 != 1 then
  return -1
endi

# mixed order
sql select ts, c1 from union_tb1 order by ts asc limit 10 union all select ts, c1 from union_tb0 order by ts desc limit 2 union all select ts, c1 from union_tb2 order by ts asc limit 10
if $rows != 22 then
  return -1
endi

if $data00 != @20-01-05 13:51:24.000@ then
  return -1
endi

if $data01 != 0 then
  return -1
endi

if $data10 != @20-01-05 13:52:24.000@ then
  return -1
endi

if $data11 != 1 then
  return -1
endi

if $data90 != @20-01-05 14:00:24.000@ then
  return -1
endi

if $data91 != 9 then
  return -1
endi

# different sort order

# super table & normal table mixed up
sql select c3 from union_tb0 limit 2 union all select sum(c1) as c3 from union_mt0;
if $rows != 3 then
  return -1
endi

if $data00 != 0 then
  return -1
endi

if $data10 != 1 then
  return -1
endi

if $data20 != 4950000 then
  return -1
endi

# type compatible
sql select c3 from union_tb0 limit 2 union all select sum(c1) as c3 from union_tb1;
if $rows != 3 then
 return -1
endi

if $data00 != 0 then
   return -1
endi

if $data10 != 1 then
  return -1
endi

if $data20 != 495000 then
  return -1
endi

# two join subclause
sql select count(*) as c from union_tb0, union_tb1 where union_tb0.ts=union_tb1.ts union all select union_tb0.c3 as c from union_tb0, union_tb1 where union_tb0.ts=union_tb1.ts limit 10
if $rows != 11 then
  return -1
endi

if $data00 != 10000 then
  return -1
endi

if $data10 != 0 then
  return -1
endi

if $data20 != 1 then
  return -1
endi

if $data90 != 8 then
 return -1
endi

print ===========================================tags union
# two super table tag union, limit is not active during retrieve tags query
H
Haojun Liao 已提交
234
sql select t1 from union_mt0 union all select t1 from union_mt0
H
Haojun Liao 已提交
235 236 237 238 239 240 241 242 243 244 245 246
if $rows != 20 then
  return -1
endi

if $data00 != 0 then
  return -1
endi

if $data90 != 9 then
  return -1
endi

H
Haojun Liao 已提交
247 248 249 250
#sql select t1 from union_mt0 union all select t1 from union_mt0 limit 1
#if $row != 11 then
#  return -1
#endi
H
Haojun Liao 已提交
251 252 253 254 255 256 257 258 259 260
#========================================== two super table join subclause
print ================two super table join subclause
sql select avg(union_mt0.c1) as c from union_mt0 interval(1h) limit 10 union all select union_mt1.ts, union_mt1.c1/1.0 as c from union_mt0, union_mt1 where union_mt1.ts=union_mt0.ts and union_mt1.t1=union_mt0.t1 limit 5;
print the rows value is: $rows

if $rows != 15 then
  return -1
endi

# first subclause are empty
H
Haojun Liao 已提交
261
sql select count(*) as c from union_tb0 where ts > now + 3650d union all select sum(c1) as c from union_tb1;
H
Haojun Liao 已提交
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 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
if $rows != 1 then
  return -1
endi

if $data00 != 495000 then
  return -1
endi

# all subclause are empty
sql select c1 from union_tb0 limit 0 union all select c1 from union_tb1 where ts>'2021-1-1 0:0:0'
if $rows != 0 then
  return -1
endi

# middle subclause empty
sql select c1 from union_tb0 limit 1 union all select c1 from union_tb1 where ts>'2030-1-1 0:0:0' union all select last(c1) as c1 from union_tb1;
if $rows != 2 then
  return -1
endi

if $data00 != 0 then
  return -1
endi

if $data10 != 99 then
  return -1
endi

# multi-vnode projection query
sql (select c1 from union_mt0) union all select c1 from union_mt0;
if $rows != 200000 then
 return -1
endi

# multi-vnode projection query + limit
sql (select ts, c1 from union_mt0 limit 1) union all (select ts, c1 from union_mt0 limit 1);
if $rows != 2 then
  return -1
endi

if $data00 != @20-01-05 13:51:24.000@ then
  return -1
endi

if $data01 != 0 then
  return -1
endi

if $data10 != @20-01-05 13:51:24.000@ then
  return -1
endi

if $data11 != 0 then
  return -1
endi

# two aggregated functions for super tables
sql select sum(c1) as a from union_mt0 interval(1s) limit 9 union all select ts, max(c3) as a from union_mt0 limit 2;
if $rows != 10 then
  return -1
endi

if $data00 != @20-01-05 13:51:24.000@ then
  return -1
endi

if $data01 != 0 then
  return -1
endi

if $data10 != @20-01-05 13:52:24.000@ then
  return -1
endi

if $data11 != 10 then
  return -1
endi

if $data20 != @20-01-05 13:53:24.000@ then
  return -1
endi

if $data21 != 20 then
  return -1
endi

if $data90 != @20-01-05 15:30:24.000@ then
  return -1
endi

if $data91 != 99 then
  return -1
endi

H
Haojun Liao 已提交
356
#=================================================================================================
H
Haojun Liao 已提交
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
# two aggregated functions for normal tables
sql select sum(c1) as a from union_tb0 limit 1 union all select sum(c3) as a from union_tb1 limit 2;
if $rows != 2 then
  return -1
endi

if $data00 != 495000 then
  return -1
endi

if $data10 != 495000 then
  return -1
endi

# two super table query + interval + limit
sql select ts, first(c3) as a from union_mt0 limit 1 union all select sum(c3) as a from union_mt0 interval(1h) limit 1;
if $rows != 2 then
  return -1
endi

if $data00 != @20-01-05 13:51:24.000@ then
 return -1
endi

if $data01 != 0 then
  return -1
endi

if $data10 != @20-01-05 13:00:00.000@ then
 return -1
endi

if $data11 != 360 then
  return -1
endi

sql select server_status() union all select server_status()
if $rows != 2 then
  return -1
endi

if $data00 != 1 then
  return -1
endi

if $data10 != 1 then
  return -1
endi

sql select client_version() union all select server_version()
if $rows != 2 then
  return -1
endi

sql select database() union all select database()
if $rows != 2 then
  return -1
endi

if $data00 != @union_db0@ then
  return -1
endi

if $data10 != @union_db0@ then
  return -1
endi

D
fix bug  
dapan1121 已提交
424 425 426 427 428 429 430 431 432 433
sql select 'aaa' as option from union_tb1 where c1 < 0 limit 1 union all select 'bbb' as option from union_tb0 limit 1
if $rows != 1 then
  return -1
endi

if $data00 != @bbb@ then
  return -1
endi


H
Haojun Liao 已提交
434 435 436 437
sql_error show tables union all show tables
sql_error show stables union all show stables
sql_error show databases union all show databases

D
fix bug  
dapan1121 已提交
438
system sh/exec.sh -n dnode1 -s stop -x SIGINT