• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1create table t1(
2  ts BIG INT,
3  dur BIG INT,
4  a BIG INT,
5  PRIMARY KEY (ts)
6) without rowid;
7
8create table t2(
9  ts BIG INT,
10  dur BIG INT,
11  b BIG INT,
12  part BIG INT,
13  PRIMARY KEY (part, ts)
14) without rowid;
15
16-- Insert some rows into t2 which are in part 0 and 1 but before t1's rows.
17INSERT INTO t2(ts, dur, part, b)
18VALUES
19(0, 25, 0, 111),
20(50, 50, 0, 222),
21(0, 40, 1, 333);
22
23-- Then insert some rows into t1 in part 1, 3, 4 and 5.
24INSERT INTO t1(ts, dur, a)
25VALUES
26(100, 400, 111),
27(500, 50, 222),
28(600, 100, 333),
29(900, 100, 444);
30
31-- Insert a row into t2 which should be split up by t1's first row.
32INSERT INTO t2(ts, dur, part, b) VALUES (50, 200, 1, 444);
33
34-- Insert a row into t2 should should be completely covered by t1's first row.
35INSERT INTO t2(ts, dur, part, b) VALUES (300, 100, 1, 555);
36
37-- Insert a row into t2 which should span between t1's first and second rows.
38INSERT INTO t2(ts, dur, part, b) VALUES (400, 250, 1, 666);
39
40-- Insert a row into t2 in partition 2.
41INSERT INTO t2(ts, dur, part, b) VALUES (100, 1000, 2, 777);
42
43-- Insert a row into t2 before t1's first row in partition 4.
44INSERT INTO t2(ts, dur, part, b) VALUES (50, 50, 4, 888);
45
46-- Insert a row into t2 which perfectly matches the second row in partition 4.
47INSERT INTO t2(ts, dur, part, b) VALUES (500, 50, 4, 999);
48
49-- Insert a row into t2 which intersects the first row of partition 5.
50INSERT INTO t2(ts, dur, part, b) VALUES (50, 75, 5, 1111);
51
52-- Insert a row into t2 which intersects the third row of partition 5.
53INSERT INTO t2(ts, dur, part, b) VALUES (525, 75, 5, 2222);
54
55-- Insert a row into t2 which misses everything in partition 6.
56INSERT INTO t2(ts, dur, part, b) VALUES (0, 100, 6, 2222);
57
58create virtual table sp using span_left_join(t1, t2 PARTITIONED part);
59
60select * from sp;
61