system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/exec.sh -n dnode1 -s start
sql connect

$dbPrefix = db
$tbPrefix1 = tba
$tbPrefix2 = tbb
$mtPrefix = stb
$tbNum = 10000
$rowNum = 2

print =============== step1
$i = 0
$db = $dbPrefix . $i
$mt1 = $mtPrefix . $i
$i = 1
$mt2 = $mtPrefix . $i

sql drop database $db -x step1
step1:
sql create database $db
sql use $db
sql create table $mt1 (ts timestamp, f1 int) TAGS(tag1 int, tag2 binary(500))
sql create table $mt2 (ts timestamp, f1 int) TAGS(tag1 int, tag2 binary(500))

print ====== start create child tables and insert data
$i = 0
while $i < $tbNum
  $tb = $tbPrefix1 . $i
  sql create table $tb using $mt1 tags( $i , 'aaaaaaaaaaaaaaaaaaaaaaaaaaa')

  $x = 0
  while $x < $rowNum
    $cc = $x * 60000
    $ms = 1601481600000 + $cc

    sql insert into $tb values ($ms , $x )
    $x = $x + 1
  endw

  $i = $i + 1
endw

print =============== step2
$i = 0
while $i < $tbNum
  $tb = $tbPrefix2 . $i
  sql create table $tb using $mt2 tags( $i , 'aaaaaaaaaaaaaaaaaaaaaaaaaaa')

  $x = 0
  while $x < $rowNum
    $cc = $x * 60000
    $ms = 1601481600000 + $cc

    sql insert into $tb values ($ms , $x )
    $x = $x + 1
  endw

  $i = $i + 1
endw

sql select * from tba0 t1, tbb0 t2 where t1.ts=t2.ts;
if $rows != 2 then
  return -1
endi
sql select * from stb0 t1, stb1 t2 where t1.ts=t2.ts and t1.tag2=t2.tag2;
if $rows != 200000000 then
  return -1
endi

system sh/exec.sh -n dnode1 -s stop -x SIGINT
