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