Skip to content

Commit

Permalink
refactor(optimizer): add lookup table to batch lookup join explain (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
chenzl25 authored Nov 8, 2023
1 parent 285296d commit 901d9b0
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
select * from t join t2 on t.b = t2.d;
batch_plan: |-
BatchExchange { order: [], dist: Single }
└─BatchLookupJoin { type: Inner, predicate: t.b = idx.d, output: all }
└─BatchLookupJoin { type: Inner, predicate: t.b = idx.d, output: all, lookup table: idx }
└─BatchExchange { order: [], dist: UpstreamHashShard(t.b) }
└─BatchScan { table: t, columns: [t.a, t.b], distribution: SomeShard }
- sql: |
Expand All @@ -18,7 +18,7 @@
select * from t join t2 on t.a = t2.c and t.b = t2.d;
batch_plan: |-
BatchExchange { order: [], dist: Single }
└─BatchLookupJoin { type: Inner, predicate: t.a = idx2.c AND t.b = idx2.d, output: all }
└─BatchLookupJoin { type: Inner, predicate: t.a = idx2.c AND t.b = idx2.d, output: all, lookup table: idx2 }
└─BatchExchange { order: [], dist: UpstreamHashShard(t.a) }
└─BatchScan { table: t, columns: [t.a, t.b], distribution: SomeShard }
- sql: |
Expand All @@ -28,7 +28,7 @@
select * from t join t2 on t.b = t2.d;
batch_plan: |-
BatchExchange { order: [], dist: Single }
└─BatchLookupJoin { type: Inner, predicate: t.b = idx.d, output: all }
└─BatchLookupJoin { type: Inner, predicate: t.b = idx.d, output: all, lookup table: idx }
└─BatchExchange { order: [], dist: UpstreamHashShard(t.b) }
└─BatchScan { table: t, columns: [t.a, t.b], distribution: SomeShard }
- name: test index join predicate reorder
Expand All @@ -39,7 +39,7 @@
select * from t join t2 on t.b = t2.d and t.a = t2.c;
batch_plan: |-
BatchExchange { order: [], dist: Single }
└─BatchLookupJoin { type: Inner, predicate: t.a = idx.c AND t.b = idx.d, output: all }
└─BatchLookupJoin { type: Inner, predicate: t.a = idx.c AND t.b = idx.d, output: all, lookup table: idx }
└─BatchExchange { order: [], dist: UpstreamHashShard(t.a) }
└─BatchScan { table: t, columns: [t.a, t.b], distribution: SomeShard }
- name: test index join prefix lookup
Expand All @@ -50,7 +50,7 @@
select * from t join t2 on t.a = t2.c;
batch_plan: |-
BatchExchange { order: [], dist: Single }
└─BatchLookupJoin { type: Inner, predicate: t.a = idx.c, output: all }
└─BatchLookupJoin { type: Inner, predicate: t.a = idx.c, output: all, lookup table: idx }
└─BatchExchange { order: [], dist: UpstreamHashShard(t.a) }
└─BatchScan { table: t, columns: [t.a, t.b], distribution: SomeShard }
- name: test index join distribution derive
Expand All @@ -63,7 +63,7 @@
└─BatchHashAgg { group_key: [internal_last_seen_value(t2.c)], aggs: [internal_last_seen_value(internal_last_seen_value(t2.d)), count(t.a)] }
└─BatchExchange { order: [], dist: HashShard(internal_last_seen_value(t2.c)) }
└─BatchHashAgg { group_key: [t.a], aggs: [internal_last_seen_value(t2.c), internal_last_seen_value(t2.d)] }
└─BatchLookupJoin { type: Inner, predicate: t.a = t2.c, output: [t2.c, t2.d, t.a] }
└─BatchLookupJoin { type: Inner, predicate: t.a = t2.c, output: [t2.c, t2.d, t.a], lookup table: t2 }
└─BatchExchange { order: [], dist: UpstreamHashShard(t.a) }
└─BatchScan { table: t, columns: [t.a], distribution: SomeShard }
- sql: |
Expand All @@ -73,7 +73,7 @@
select * from t1 join idx on t1.a = idx.c and t1.b = idx.d;
batch_plan: |-
BatchExchange { order: [], dist: Single }
└─BatchLookupJoin { type: Inner, predicate: t1.a = idx.c AND t1.b = idx.d, output: all }
└─BatchLookupJoin { type: Inner, predicate: t1.a = idx.c AND t1.b = idx.d, output: all, lookup table: idx }
└─BatchExchange { order: [], dist: UpstreamHashShard(t1.a) }
└─BatchScan { table: t1, columns: [t1.a, t1.b], distribution: SomeShard }
- name: shouldn't be a lookup join
Expand Down
76 changes: 38 additions & 38 deletions src/frontend/planner_test/tests/testdata/output/ch_benchmark.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
select * from t1 natural join t2;
batch_plan: |-
BatchExchange { order: [], dist: Single }
└─BatchLookupJoin { type: Inner, predicate: t1.a = idx.a AND t1.b = idx.b AND t1.c = idx.c, output: [t1.c, t1.b, t1.a] }
└─BatchLookupJoin { type: Inner, predicate: t1.a = idx.a AND t1.b = idx.b AND t1.c = idx.c, output: [t1.c, t1.b, t1.a], lookup table: idx }
└─BatchExchange { order: [], dist: UpstreamHashShard(t1.a) }
└─BatchScan { table: t1, columns: [t1.a, t1.b, t1.c], distribution: SomeShard }
- id: fix https://github.com/risingwavelabs/risingwave/issues/10721
Expand All @@ -18,7 +18,7 @@
select * from t1 natural join t2;
batch_plan: |-
BatchExchange { order: [], dist: Single }
└─BatchLookupJoin { type: Inner, predicate: t1.b = idx.b AND t1.a = idx.a AND t1.c = idx.c, output: [t1.c, t1.b, t1.a] }
└─BatchLookupJoin { type: Inner, predicate: t1.b = idx.b AND t1.a = idx.a AND t1.c = idx.c, output: [t1.c, t1.b, t1.a], lookup table: idx }
└─BatchExchange { order: [], dist: UpstreamHashShard(t1.b) }
└─BatchScan { table: t1, columns: [t1.a, t1.b, t1.c], distribution: SomeShard }
- id: fix https://github.com/risingwavelabs/risingwave/issues/10721
Expand All @@ -29,7 +29,7 @@
select * from t1 natural join t2;
batch_plan: |-
BatchExchange { order: [], dist: Single }
└─BatchLookupJoin { type: Inner, predicate: t1.c = idx.c AND t1.b = idx.b AND t1.a = idx.a, output: [t1.c, t1.b, t1.a] }
└─BatchLookupJoin { type: Inner, predicate: t1.c = idx.c AND t1.b = idx.b AND t1.a = idx.a, output: [t1.c, t1.b, t1.a], lookup table: idx }
└─BatchExchange { order: [], dist: UpstreamHashShard(t1.c, t1.b) }
└─BatchScan { table: t1, columns: [t1.a, t1.b, t1.c], distribution: SomeShard }
- id: fix https://github.com/risingwavelabs/risingwave/issues/10721
Expand All @@ -40,6 +40,6 @@
select * from t1 natural join t2;
batch_plan: |-
BatchExchange { order: [], dist: Single }
└─BatchLookupJoin { type: Inner, predicate: t1.c = idx.c AND t1.b = idx.b AND t1.a = idx.a, output: [t1.c, t1.b, t1.a] }
└─BatchLookupJoin { type: Inner, predicate: t1.c = idx.c AND t1.b = idx.b AND t1.a = idx.a, output: [t1.c, t1.b, t1.a], lookup table: idx }
└─BatchExchange { order: [], dist: UpstreamHashShard(t1.c, t1.b, t1.a) }
└─BatchScan { table: t1, columns: [t1.a, t1.b, t1.c], distribution: SomeShard }
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
sql: select A.v, B.v as Bv from A join B using(k1);
batch_plan: |-
BatchExchange { order: [], dist: Single }
└─BatchLookupJoin { type: Inner, predicate: a.k1 = bk1.k1, output: [a.v, bk1.v] }
└─BatchLookupJoin { type: Inner, predicate: a.k1 = bk1.k1, output: [a.v, bk1.v], lookup table: bk1 }
└─BatchExchange { order: [], dist: UpstreamHashShard(a.k1) }
└─BatchScan { table: a, columns: [a.k1, a.v], distribution: SomeShard }
stream_plan: |-
Expand Down Expand Up @@ -65,7 +65,7 @@
sql: select A.v, B.v as Bv from Ak1 as A join B using(k1)
batch_plan: |-
BatchExchange { order: [], dist: Single }
└─BatchLookupJoin { type: Inner, predicate: ak1.k1 = bk1.k1, output: [ak1.v, bk1.v] }
└─BatchLookupJoin { type: Inner, predicate: ak1.k1 = bk1.k1, output: [ak1.v, bk1.v], lookup table: bk1 }
└─BatchExchange { order: [], dist: UpstreamHashShard(ak1.k1) }
└─BatchScan { table: ak1, columns: [ak1.k1, ak1.v], distribution: UpstreamHashShard(ak1.k1) }
stream_plan: |-
Expand Down Expand Up @@ -117,7 +117,7 @@
sql: select A.v, B.v as Bv from A join Bk1 as B using(k1)
batch_plan: |-
BatchExchange { order: [], dist: Single }
└─BatchLookupJoin { type: Inner, predicate: a.k1 = bk1.k1, output: [a.v, bk1.v] }
└─BatchLookupJoin { type: Inner, predicate: a.k1 = bk1.k1, output: [a.v, bk1.v], lookup table: bk1 }
└─BatchExchange { order: [], dist: UpstreamHashShard(a.k1) }
└─BatchScan { table: a, columns: [a.k1, a.v], distribution: SomeShard }
stream_plan: |-
Expand Down Expand Up @@ -169,7 +169,7 @@
sql: select A.v, B.v as Bv from Ak1 as A join Bk1 as B using(k1)
batch_plan: |-
BatchExchange { order: [], dist: Single }
└─BatchLookupJoin { type: Inner, predicate: ak1.k1 = bk1.k1, output: [ak1.v, bk1.v] }
└─BatchLookupJoin { type: Inner, predicate: ak1.k1 = bk1.k1, output: [ak1.v, bk1.v], lookup table: bk1 }
└─BatchExchange { order: [], dist: UpstreamHashShard(ak1.k1) }
└─BatchScan { table: ak1, columns: [ak1.k1, ak1.v], distribution: UpstreamHashShard(ak1.k1) }
stream_plan: |-
Expand Down Expand Up @@ -1038,7 +1038,7 @@
└─LogicalScan { table: ak1, columns: [ak1.k1, ak1.k2, ak1.k3, ak1.v, ak1.a._row_id] }
batch_plan: |-
BatchExchange { order: [], dist: Single }
└─BatchLookupJoin { type: Inner, predicate: a.k1 = ak1.k1, output: [ak1.v, count] }
└─BatchLookupJoin { type: Inner, predicate: a.k1 = ak1.k1, output: [ak1.v, count], lookup table: ak1 }
└─BatchExchange { order: [], dist: UpstreamHashShard(a.k1) }
└─BatchHashAgg { group_key: [a.k1], aggs: [count] }
└─BatchExchange { order: [], dist: HashShard(a.k1) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
batch_plan: |-
BatchExchange { order: [], dist: Single }
└─BatchHashAgg { group_key: [t1.a], aggs: [internal_last_seen_value(t1.b), internal_last_seen_value(t1.c)] }
└─BatchLookupJoin { type: LeftAnti, predicate: t1.a IS NOT DISTINCT FROM t2.a AND t1.b IS NOT DISTINCT FROM t2.b AND t1.c IS NOT DISTINCT FROM t2.c, output: all }
└─BatchLookupJoin { type: LeftAnti, predicate: t1.a IS NOT DISTINCT FROM t2.a AND t1.b IS NOT DISTINCT FROM t2.b AND t1.c IS NOT DISTINCT FROM t2.c, output: all, lookup table: t2 }
└─BatchExchange { order: [], dist: UpstreamHashShard(t1.a) }
└─BatchScan { table: t1, columns: [t1.a, t1.b, t1.c], distribution: UpstreamHashShard(t1.a) }
stream_plan: |-
Expand Down
Loading

0 comments on commit 901d9b0

Please sign in to comment.