projection_limit_offset.sim 11.8 KB
Newer Older
S
slguan 已提交
1
system sh/stop_dnodes.sh
S
slguan 已提交
2 3

system sh/deploy.sh -n dnode1 -i 1
H
hjxilinx 已提交
4
system sh/cfg.sh -n dnode1 -c walLevel -v 0
H
Haojun Liao 已提交
5
system sh/cfg.sh -n dnode1 -c maxtablespervnode -v 4
S
slguan 已提交
6
system sh/exec.sh -n dnode1 -s start
H
Haojun Liao 已提交
7
sleep 500
S
slguan 已提交
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
sql connect

$dbPrefix = group_db
$tbPrefix = group_tb
$mtPrefix = group_mt
$tbNum = 8
$rowNum = 10000
$totalNum = $tbNum * $rowNum

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

$tstart = 100000

H
Haojun Liao 已提交
24
sql drop database if exists $db -x step1
S
slguan 已提交
25
step1:
H
Haojun Liao 已提交
26
sql create database if not exists $db keep 36500
S
slguan 已提交
27 28 29 30
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, t2 binary(12))

$i = 0
H
Haojun Liao 已提交
31 32 33
$half = $tbNum / 2

while $i < $half
S
slguan 已提交
34 35 36
  $tb = $tbPrefix . $i
  $tg2 = ' . abc
  $tg2 = $tg2 . '
H
Haojun Liao 已提交
37 38 39 40 41

  $tbId = $i + $half

  $tb1 = $tbPrefix . $tbId

S
slguan 已提交
42
  sql create table $tb using $mt tags( $i , $tg2 )
H
Haojun Liao 已提交
43
  sql create table $tb1 using $mt tags( $i , $tg2 )
S
slguan 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59

  $x = 0
  while $x < $rowNum
    $ms = $x . m
    $c = $x / 100
    $c = $c * 100
    $c = $x - $c

    $binary = ' . binary
    $binary = $binary . $c
    $binary = $binary . '

    $nchar = ' . nchar
    $nchar = $nchar . $c
    $nchar = $nchar . '

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

  $i = $i + 1
  $tstart = 100000
endw

sleep 100

$i1 = 1
$i2 = 0

$db = $dbPrefix . $i
$mt = $mtPrefix . $i

$dbPrefix = group_db
$tbPrefix = group_tb
$mtPrefix = group_mt

$tb1 = $tbPrefix . $i1
$tb2 = $tbPrefix . $i2
$ts1 = $tb1 . .ts
$ts2 = $tb2 . .ts

#===============select * from super_table limit/offset[TBASE-691]=================================
sql select ts from group_mt0
print $rows

sql select ts from group_mt0 where ts>='1970-1-1 8:1:43' and ts<='1970-1-1 8:1:43.500' limit 8000 offset 0;
if $rows != 4008 then
H
Haojun Liao 已提交
92
  print expect 4008, actual:$rows
S
slguan 已提交
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
  return -1
endi

sql select ts from group_mt0 where ts>='1970-1-1 8:1:43' and ts<='1970-1-1 8:1:43.500' limit 8000 offset 1;
if $rows != 4007 then
  return -1
endi

sql select ts from group_mt0 where ts>='1970-1-1 8:1:43' and ts<='1970-1-1 8:1:43.500' limit 8000 offset 101;
print $rows
if $rows != 3907 then
  return -1
endi

if $data00 != @70-01-01 08:01:43.101@ then
  return -1
endi

sql select ts from group_mt0 where ts>='1970-1-1 8:1:43' and ts<='1970-1-1 8:1:43.500' limit 8000 offset 902;
if $rows != 3106 then
  return -1
endi

sql select ts from group_mt0 where ts>='1970-1-1 8:1:43' and ts<='1970-1-1 8:1:43.500' limit 8000 offset 400;
if $rows != 3608 then
  return -1
endi

sql select ts from group_mt0 where ts>='1970-1-1 8:1:43' and ts<='1970-1-1 8:1:43.500' limit 8000 offset 4007;
if $rows != 1 then
  return -1
endi

sql select ts from group_mt0 where ts>='1970-1-1 8:1:43' and ts<='1970-1-1 8:1:43.500' limit 2000 offset 4008;
if $rows != 0 then
  return -1
endi

#==================================order by desc, multi vnode, limit/offset===================================
sql select ts from group_mt0 where ts>='1970-1-1 8:1:43' and ts<='1970-1-1 8:1:43.500' order by ts desc limit 8000 offset 0;
if $rows != 4008 then
  return -1
endi

if $data00 != @70-01-01 08:01:43.500@ then
   return -1
endi

sql select ts from group_mt0 where ts>='1970-1-1 8:1:43' and ts<='1970-1-1 8:1:43.500' order by ts desc limit 8000 offset 1;
if $rows != 4007 then
  return -1
endi

H
Haojun Liao 已提交
146
if $data00 != @70-01-01 08:01:43.500@ then
S
slguan 已提交
147 148 149 150 151 152 153 154 155
   return -1
endi

sql select ts from group_mt0 where ts>='1970-1-1 8:1:43' and ts<='1970-1-1 8:1:43.500' order by ts desc limit 8000 offset 101;
print $rows
if $rows != 3907 then
  return -1
endi

H
Haojun Liao 已提交
156
if $data00 != @70-01-01 08:01:43.488@ then
S
slguan 已提交
157 158 159 160 161 162 163 164
   return -1
endi

sql select ts from group_mt0 where ts>='1970-1-1 8:1:43' and ts<='1970-1-1 8:1:43.500' order by ts desc limit 8000 offset 902;
if $rows != 3106 then
  return -1
endi

H
Haojun Liao 已提交
165
if $data00 != @70-01-01 08:01:43.388@ then
S
slguan 已提交
166 167 168 169 170 171 172 173
   return -1
endi

sql select ts from group_mt0 where ts>='1970-1-1 8:1:43' and ts<='1970-1-1 8:1:43.500' order by ts desc limit 8000 offset 400;
if $rows != 3608 then
  return -1
endi

H
Haojun Liao 已提交
174
if $data00 != @70-01-01 08:01:43.450@ then
S
slguan 已提交
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 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
   return -1
endi

sql select ts from group_mt0 where ts>='1970-1-1 8:1:43' and ts<='1970-1-1 8:1:43.500' order by ts desc limit 8000 offset 4007;
if $rows != 1 then
  return -1
endi

if $data00 != @70-01-01 08:01:43.000@ then
   return -1
endi

sql select ts from group_mt0 where ts>='1970-1-1 8:1:43' and ts<='1970-1-1 8:1:43.500' order by ts desc limit 2000 offset 4008;
if $rows != 0 then
  return -1
endi

#=================================single value filter======================================
sql select ts,tbname from group_mt0 where ts>='1970-1-1 8:1:43' and ts<='1970-1-1 8:1:43.00' order by ts asc limit 10 offset 0;
if $row != 8 then
   return -1
endi

if $data00 != @70-01-01 08:01:43.000@ then
  return -1
endi

sql select ts,tbname from group_mt0 where ts>='1970-1-1 8:1:43' and ts<='1970-1-1 8:1:43.00' order by ts asc limit 10 offset 1;
if $row != 7 then
   return -1
endi

sql select ts,tbname from group_mt0 where ts>='1970-1-1 8:1:43' and ts<='1970-1-1 8:1:43.00' order by ts asc limit 10 offset 2;
if $row != 6 then
   return -1
endi

sql select ts,tbname from group_mt0 where ts>='1970-1-1 8:1:43' and ts<='1970-1-1 8:1:43.00' order by ts asc limit 10 offset 4;
if $row != 4 then
   return -1
endi

sql select ts,tbname from group_mt0 where ts>='1970-1-1 8:1:43' and ts<='1970-1-1 8:1:43.00' order by ts asc limit 10 offset 7;
if $row != 1 then
   return -1
endi

sql select ts,tbname from group_mt0 where ts>='1970-1-1 8:1:43' and ts<='1970-1-1 8:1:43.00' order by ts asc limit 10 offset 8;
if $row != 0 then
   return -1
endi

sql select ts,tbname from group_mt0 where ts>='1970-1-1 8:1:43' and ts<='1970-1-1 8:1:43.00' order by ts asc limit 10 offset 9;
if $row != 0 then
   return -1
endi

#===============================single value filter, order by desc============================
sql select ts,tbname from group_mt0 where ts>='1970-1-1 8:1:43' and ts<='1970-1-1 8:1:43.00' order by ts desc limit 10 offset 0;
if $row != 8 then
   return -1
endi

if $data00 != @70-01-01 08:01:43.000@ then
  return -1
endi

sql select ts,tbname from group_mt0 where ts>='1970-1-1 8:1:43' and ts<='1970-1-1 8:1:43.00' order by ts desc limit 10 offset 1;
if $row != 7 then
   return -1
endi

sql select ts,tbname from group_mt0 where ts>='1970-1-1 8:1:43' and ts<='1970-1-1 8:1:43.00' order by ts desc limit 10 offset 2;
if $row != 6 then
   return -1
endi

sql select ts,tbname from group_mt0 where ts>='1970-1-1 8:1:43' and ts<='1970-1-1 8:1:43.00' order by ts desc limit 10 offset 4;
if $row != 4 then
   return -1
endi

sql select ts,tbname from group_mt0 where ts>='1970-1-1 8:1:43' and ts<='1970-1-1 8:1:43.00' order by ts desc limit 10 offset 7;
if $row != 1 then
   return -1
endi

if $data00 != @70-01-01 08:01:43.000@ then
  return -1
endi

sql select ts,tbname from group_mt0 where ts>='1970-1-1 8:1:43' and ts<='1970-1-1 8:1:43.00' order by ts desc limit 10 offset 8;
if $row != 0 then
   return -1
endi

sql select ts,tbname from group_mt0 where ts>='1970-1-1 8:1:43' and ts<='1970-1-1 8:1:43.00' order by ts desc limit 10 offset 9;
if $row != 0 then
   return -1
endi

#[tbase-695]
sql select ts,tbname from group_mt0 where ts>='1970-01-01 8:1:40' and ts<'1970-1-1 8:1:45' and c1<99999999 limit 100000 offset 5000
if $row != 35000 then
   return -1
endi

if $data00 != @70-01-01 08:01:40.000@ then
   return -1
endi

#=================================parse error sql==========================================
sql_error select ts,tbname from group_mt0 order by ts desc limit 100 offset -1;
sql_error select ts,tbname from group_mt0 order by c1 asc limit 100 offset -1;
sql_error select ts,tbname from group_mt0 order by ts desc limit -1, 100;
sql_error select ts,tbname from group_mt0 order by ts desc slimit -1, 100;
sql_error select ts,tbname from group_mt0 order by ts desc slimit 1 soffset 1;

#================================functions applys to sql===================================
sql_error select first(t1) from group_mt0;
sql_error select last(t1) from group_mt0;
sql_error select min(t1) from group_mt0;
sql_error select max(t1) from group_mt0;
sql_error select top(t1, 20) from group_mt0;
sql_error select bottom(t1, 20) from group_mt0;
sql_error select avg(t1) from group_mt0;
sql_error select percentile(t1, 50) from group_mt0;
sql_error select percentile(t1, 50) from group_mt0;
sql_error select percentile(t1, 50) from group_mt0;

#====================================tbase-722==============================================
print tbase-722
sql select spread(ts) from group_tb0;
print $data00

if $data00 != 9999.000000000 then
   return -1
endi

#====================================tbase-716==============================================
print tbase-716
sql_error select count(*) from group_tb0 where ts in ('2016-1-1 12:12:12');
sql_error select count(*) from group_tb0 where ts < '12:12:12';

#===============================sql for twa==========================================
sql_error select twa(c1) from group_tb0;
sql_error select twa(c1) from group_stb0;
sql_error select twa(c2) from group_stb0 where ts<now and ts>now-1h group by t1;
sql_error select twa(c2) from group_stb0 where ts<now and ts>now-1h group by tbname,t1;
sql_error select twa(c2) from group_stb0 group by tbname,t1;
sql_error select twa(c2) from group_stb0 group by tbname;
sql_error select twa(c2) from group_stb0 group by t1;
sql_error select twa(c2) from group_stb0 where ts<now and ts>now-1h group by t1,tbname;

#================================first/last error check================================
sql create table m1 (ts timestamp, k int) tags(a int);
sql create table tm0 using m1 tags(1);
sql create table tm1 using m1 tags(2);

sql insert into tm0 values(10000, 1) (20000, 2)(30000, 3) (40000, NULL) (50000, 2) tm1 values(10001, 2)(20000,4)(90000,9);

H
Haojun Liao 已提交
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
#=============================tbase-1205
sql select count(*) from tm1 where ts<now and ts>= now -1d interval(1h) fill(NULL);

print ===================>TD-1834
sql select * from tm0 where ts>11000 and ts< 20000 order by ts asc
if $rows != 0 then
  return -1
endi

sql select * from tm0 where ts>11000 and ts< 20000 order by ts desc
if $rows != 0 then
  return -1
endi

sql select count(*),first(k),last(k) from m1 where tbname in ('tm0') interval(1s) order by ts desc;
S
slguan 已提交
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
if $row != 5 then
    return -1
endi

if $data00 != @70-01-01 08:00:50.000@ then
    return -1
endi

if $data01 != 1 then
   return -1
endi

if $data02 != 2 then
   return -1
endi

if $data11 != 1 then
   return -1
endi

H
Haojun Liao 已提交
371
if $data12 != NULL then
S
slguan 已提交
372 373 374
   return -1
endi

H
Haojun Liao 已提交
375
if $data13 != NULL then
S
slguan 已提交
376 377 378 379 380 381 382 383 384
   return -1
endi

print =============tbase-1324
sql select a, k-k from m1
if $row != 8 then
   return -1
endi

H
Haojun Liao 已提交
385 386 387 388 389 390 391 392 393
sql select diff(k) from tm0
if $row != 3 then
   return -1
endi

if $data21 != -1 then
   return -1
endi

S
slguan 已提交
394 395
#error sql
sql_error select * from 1;
H
Haojun Liao 已提交
396
#sql_error select 1;  // equals to select server_status();
S
slguan 已提交
397 398 399 400 401 402 403 404 405 406
sql_error select k+k;
sql_error select k+1;
sql_error select abc();
sql_error select 1 where 1=2;
sql_error select 1 limit 1;
sql_error select 1 slimit 1;
sql_error select 1 interval(1h);
sql_error select count(*);
sql_error select sum(k);
sql_error select 'abc';
H
Haojun Liao 已提交
407 408 409
sql_error select k+1,sum(k) from tm0;
sql_error select k, sum(k) from tm0;
sql_error select k, sum(k)+1 from tm0;
S
slguan 已提交
410

H
Haojun Liao 已提交
411 412
print ================== restart server to commit data into disk
system sh/exec.sh -n dnode1 -s stop -x SIGINT
H
Haojun Liao 已提交
413
sleep 3000
H
Haojun Liao 已提交
414 415 416
system sh/exec.sh -n dnode1 -s start
print ================== server restart completed

S
slguan 已提交
417 418 419
#=============================tbase-1205
sql select count(*) from tm1 where ts<now and ts>= now -1d interval(1h) fill(NULL);

H
Haojun Liao 已提交
420 421 422 423 424 425 426 427 428 429 430 431
print ===================>TD-1834
sql select * from tm0 where ts>11000 and ts< 20000 order by ts asc
if $rows != 0 then
  return -1
endi

sql select * from tm0 where ts>11000 and ts< 20000 order by ts desc
if $rows != 0 then
  return -1
endi


H
Haojun Liao 已提交
432