nestquery.sim 4.1 KB
Newer Older
H
Haojun Liao 已提交
1 2 3 4 5 6 7 8 9 10 11
system sh/stop_dnodes.sh

system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c walLevel -v 1
system sh/exec.sh -n dnode1 -s start

sleep 100
sql connect

print ======================== dnode1 start

H
Haojun Liao 已提交
12
$dbPrefix = nest_db
H
Haojun Liao 已提交
13 14 15 16 17 18 19 20 21 22 23
$tbPrefix = nest_tb
$mtPrefix = nest_mt
$tbNum = 10
$rowNum = 10000
$totalNum = $tbNum * $rowNum

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

H
Haojun Liao 已提交
24
sql drop database if exists $db
H
Haojun Liao 已提交
25
sql create database if not exists $db
H
Haojun Liao 已提交
26

H
Haojun Liao 已提交
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
sql use $db
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)

$half = $tbNum / 2

$i = 0
while $i < $half
  $tb = $tbPrefix . $i

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

  sql create table $tb using $mt tags( $i )
  sql create table $tb1 using $mt tags( $nextSuffix )

  $x = 0
  while $x < $rowNum
    $y = $x * 60000
    $ms = 1600099200000 + $y
    $c = $x / 100
    $c = $c * 100
    $c = $x - $c
    $binary = 'binary . $c
    $binary = $binary . '
    $nchar = 'nchar . $c
    $nchar = $nchar . '
    sql insert into $tb values ($ms , $c , $c , $c , $c , $c , $c , $c , $binary , $nchar )  $tb1 values ($ms , $c , $c , $c , $c , $c , $c , $c , $binary , $nchar )
    $x = $x + 1
  endw

  $i = $i + 1
endw

sleep 100

$i = 1
$tb = $tbPrefix . $i
H
Haojun Liao 已提交
64

H
Haojun Liao 已提交
65 66
print ==============> simple nest query test
sql select count(*) from (select count(*) from nest_mt0)
H
Haojun Liao 已提交
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
if $rows != 1 then
 return -1
endi

if $data00 != 1 then
  return -1
endi

sql select count(*) from (select count(*) from nest_mt0 group by tbname)
if $rows != 1 then
  return -1
endi

if $data00 != 10 then
  return -1
endi

sql select count(*) from (select count(*) from nest_mt0 interval(10h) group by tbname)
if $rows != 1 then
  return -1
endi

H
Haojun Liao 已提交
89 90 91 92 93 94 95 96 97 98
if $data00 != 170 then
  return -1
endi

sql select sum(a) from (select count(*) a from nest_mt0 interval(10h) group by tbname)
if $rows != 1 then
  return -1
endi

if $data00 != 100000 then
H
Haojun Liao 已提交
99 100 101 102
  return -1
endi

print =================> alias name test
H
Haojun Liao 已提交
103 104 105 106 107 108 109 110 111
sql select ts from (select count(*) a from nest_tb0 interval(1h))
if $rows != 167 then
  return -1
endi

if $data00 != @20-09-15 00:00:00.000@ then
  return -1
endi

H
Haojun Liao 已提交
112 113 114 115 116
sql select count(a) from (select count(*) a from nest_tb0 interval(1h))
if $rows != 1 then
  return -1
endi

H
Haojun Liao 已提交
117
if $data00 != 167 then
H
Haojun Liao 已提交
118 119
   return -1
endi
H
Haojun Liao 已提交
120

H
Haojun Liao 已提交
121
print ================>master query + filter
122
sql select t.* from (select count(*) a from nest_tb0 interval(10h)) t where t.a <= 520;
H
Haojun Liao 已提交
123 124 125 126
if $rows != 2 then
  return -1
endi

127 128 129 130 131 132
sql select * from (select count(*) a from nest_mt0 group by tbname) t where t.a<0
if $rows != 0 then
  return -1
endi


H
Haojun Liao 已提交
133

134
print ===================> nest query interval
H
Haojun Liao 已提交
135 136 137



138
print ===================> complex query
H
Haojun Liao 已提交
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
print ===================> group by + having





print =========================> nest query join
sql select a.ts,a.k,b.ts from (select count(*) k from nest_tb0 interval(30a)) a, (select count(*) f from nest_tb1 interval(30a)) b where a.ts = b.ts ;
if $rows != 10000 then
  return -1
endi

if $data00 != @20-09-15 00:00:00.000@ then
  return -1
endi

if $data01 != 1 then
  return -1
endi

if $data02 != @20-09-15 00:00:00.000@ then
  return -1
endi

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

if $data11 != 1 then
  return -1
endi
H
Haojun Liao 已提交
173

174 175 176 177 178 179 180 181 182 183 184 185
if $data12 != @20-09-15 00:01:00.000@ then
  return -1
endi

sql select sum(a.k), sum(b.f) from (select count(*) k from nest_tb0 interval(30a)) a, (select count(*) f from nest_tb1 interval(30a)) b where a.ts = b.ts ;
if $rows != 1 then
  return -1
endi

if $data00 != 10000 then
  return -1
endi
H
Haojun Liao 已提交
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
if $data01 != 10000 then
  return -1
endi

sql select a.ts,a.k,b.ts,c.ts,c.ts,c.x from (select count(*) k from nest_tb0 interval(30a)) a, (select count(*) f from nest_tb1 interval(30a)) b, (select count(*) x from nest_tb2 interval(30a)) c where a.ts = b.ts and a.ts = c.ts
if $rows != 10000 then
  return -1
endi

if $data00 != @20-09-15 00:00:00.000@ then
  return -1
endi

if $data01 != 1 then
  return -1
endi

if $data02 != @20-09-15 00:00:00.000@ then
  return -1
endi

if $data03 != @20-09-15 00:00:00.000@ then
  return -1
endi
H
Haojun Liao 已提交
211

H
Haojun Liao 已提交
212
system sh/exec.sh -n dnode1 -s stop -x SIGINT