Skip to content

Commit

Permalink
opt: specify hash joins in EXPLAIN (OPT)
Browse files Browse the repository at this point in the history
In EXPLAIN (OPT), joins that have no mention (like `merge` or
`lookup`) are executed as hash joins. Make this explicit, for the
benefit of usage outside of the opt team.

Release note: None
  • Loading branch information
RaduBerinde committed Jul 11, 2019
1 parent d559a1c commit 5713aa6
Show file tree
Hide file tree
Showing 55 changed files with 759 additions and 755 deletions.
6 changes: 3 additions & 3 deletions pkg/sql/opt/exec/execbuilder/testdata/explain_env
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ ALTER TABLE test.public.y INJECT STATISTICS '[]';
·
SELECT text FROM [EXPLAIN (OPT, ENV) SELECT * FROM x, y WHERE b = 3] WHERE (text NOT LIKE '%Version%') OR (text LIKE '%EXPLAIN%');
----
inner-join
inner-join (hash)
├── scan y
├── scan x@x_b_idx
│ └── constraint: /2/1: [/3 - /3]
Expand Down Expand Up @@ -197,7 +197,7 @@ ALTER TABLE test.public.x INJECT STATISTICS '[
·
SELECT text FROM [EXPLAIN (OPT, ENV) SELECT * FROM x AS one, x AS two] WHERE (text NOT LIKE '%Version%') OR (text LIKE '%EXPLAIN%');
----
inner-join
inner-join (hash)
├── scan one
├── scan two
└── filters (true)
Expand Down Expand Up @@ -347,7 +347,7 @@ CREATE VIEW v (a, b, u, v) AS SELECT a, b, u, v FROM test.public.x, test.public.
·
SELECT text FROM [EXPLAIN (OPT, ENV) SELECT * FROM v] WHERE (text NOT LIKE '%Version%') OR (text LIKE '%EXPLAIN%');
----
inner-join
inner-join (hash)
├── scan test.public.y
├── scan test.public.x@x_b_idx
│ └── constraint: /2/1: [/3 - /3]
Expand Down
4 changes: 4 additions & 0 deletions pkg/sql/opt/memo/expr_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ func (f *ExprFmtCtx) formatRelational(e RelExpr, tp treeprinter.Node) {
}
default:
fmt.Fprintf(f.Buffer, "%v", e.Op())
if opt.IsJoinNonApplyOp(t) {
// All join ops that weren't handled above execute as a hash join.
f.Buffer.WriteString(" (hash)")
}
}

tp = tp.Child(f.Buffer.String())
Expand Down
60 changes: 30 additions & 30 deletions pkg/sql/opt/memo/testdata/logprops/join
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ CREATE TABLE mn (m INT PRIMARY KEY, n INT, UNIQUE (n))
build
SELECT *, rowid FROM xysd INNER JOIN uv ON x=u
----
inner-join
inner-join (hash)
├── columns: x:1(int!null) y:2(int) s:3(string) d:4(decimal!null) u:5(int!null) v:6(int!null) rowid:7(int!null)
├── key: (7)
├── fd: (1)-->(2-4), (3,4)~~>(1,2), (7)-->(5,6), (1)==(5), (5)==(1)
Expand Down Expand Up @@ -126,7 +126,7 @@ project
│ ├── outer: (1)
│ ├── fd: ()-->(6)
│ ├── prune: (6)
│ └── inner-join
│ └── inner-join (hash)
│ ├── columns: v:6(int!null) n:9(int!null)
│ ├── outer: (1)
│ ├── fd: ()-->(6,9)
Expand Down Expand Up @@ -184,7 +184,7 @@ project
│ ├── columns: v:6(int!null)
│ ├── outer: (1,2)
│ ├── prune: (6)
│ └── inner-join
│ └── inner-join (hash)
│ ├── columns: v:6(int!null) m:8(int!null)
│ ├── outer: (1,2)
│ ├── fd: ()-->(8)
Expand Down Expand Up @@ -214,7 +214,7 @@ project
build
SELECT *, rowid FROM xysd LEFT JOIN uv ON x=u
----
left-join
left-join (hash)
├── columns: x:1(int!null) y:2(int) s:3(string) d:4(decimal!null) u:5(int) v:6(int) rowid:7(int)
├── key: (1,7)
├── fd: (1)-->(2-4), (3,4)~~>(1,2), (7)-->(5,6)
Expand Down Expand Up @@ -294,7 +294,7 @@ project
build
SELECT *, rowid FROM xysd RIGHT JOIN uv ON x=u
----
right-join
right-join (hash)
├── columns: x:1(int) y:2(int) s:3(string) d:4(decimal) u:5(int) v:6(int!null) rowid:7(int!null)
├── key: (1,7)
├── fd: (1)-->(2-4), (3,4)~~>(1,2), (7)-->(5,6)
Expand Down Expand Up @@ -322,7 +322,7 @@ right-join
opt
SELECT * FROM xysd RIGHT JOIN uv ON (SELECT u FROM uv WHERE u=x OFFSET 1) IS NULL
----
right-join
right-join (hash)
├── columns: x:1(int) y:2(int) s:3(string) d:4(decimal) u:5(int) v:6(int!null)
├── fd: (1)-->(2-4), (3,4)~~>(1,2)
├── prune: (1-6)
Expand Down Expand Up @@ -389,7 +389,7 @@ right-join
build
SELECT *, rowid FROM xysd FULL JOIN uv ON x=u
----
full-join
full-join (hash)
├── columns: x:1(int) y:2(int) s:3(string) d:4(decimal) u:5(int) v:6(int) rowid:7(int)
├── key: (1,7)
├── fd: (1)-->(2-4), (3,4)~~>(1,2), (7)-->(5,6)
Expand Down Expand Up @@ -434,7 +434,7 @@ project
│ ├── fd: (1)-->(2-4), (3,4)~~>(1,2)
│ ├── prune: (1-4)
│ └── interesting orderings: (+1) (-3,+4,+1)
├── left-join
├── left-join (hash)
│ ├── columns: u:5(int) v:6(int!null) u:8(int)
│ ├── outer: (1)
│ ├── fd: ()~~>(8)
Expand Down Expand Up @@ -475,7 +475,7 @@ project
opt
SELECT * FROM xysd WHERE EXISTS(SELECT * FROM uv WHERE x=u)
----
semi-join
semi-join (hash)
├── columns: x:1(int!null) y:2(int) s:3(string) d:4(decimal!null)
├── key: (1)
├── fd: (1)-->(2-4), (3,4)~~>(1,2)
Expand Down Expand Up @@ -547,7 +547,7 @@ semi-join-apply
│ ├── fd: (1)-->(2-4), (3,4)~~>(1,2)
│ ├── prune: (1-4)
│ └── interesting orderings: (+1) (-3,+4,+1)
├── semi-join
├── semi-join (hash)
│ ├── columns: u:5(int) v:6(int!null)
│ ├── outer: (1)
│ ├── fd: ()-->(6)
Expand All @@ -574,7 +574,7 @@ semi-join-apply
opt
SELECT * FROM xysd WHERE NOT EXISTS(SELECT * FROM uv WHERE x=u)
----
anti-join
anti-join (hash)
├── columns: x:1(int!null) y:2(int) s:3(string) d:4(decimal!null)
├── key: (1)
├── fd: (1)-->(2-4), (3,4)~~>(1,2)
Expand Down Expand Up @@ -639,7 +639,7 @@ project
├── fd: (1)-->(2-4), (3,4)~~>(1,2)
├── prune: (1-6)
├── interesting orderings: (+1) (-3,+4,+1)
└── inner-join
└── inner-join (hash)
├── columns: x:1(int!null) y:2(int) s:3(string) d:4(decimal!null) u:5(int) v:6(int!null) rowid:7(int!null)
├── key: (1,7)
├── fd: (1)-->(2-4), (3,4)~~>(1,2), (7)-->(5,6)
Expand All @@ -663,7 +663,7 @@ project
build
SELECT * FROM xysd, xysd AS xysd
----
inner-join
inner-join (hash)
├── columns: x:1(int!null) y:2(int) s:3(string) d:4(decimal!null) x:5(int!null) y:6(int) s:7(string) d:8(decimal!null)
├── key: (1,5)
├── fd: (1)-->(2-4), (3,4)~~>(1,2), (5)-->(6-8), (7,8)~~>(5,6)
Expand Down Expand Up @@ -701,7 +701,7 @@ select
│ └── interesting orderings: (+1) (-3,+4,+1)
└── filters
└── exists [type=bool, outer=(1-3), correlated-subquery]
└── inner-join
└── inner-join (hash)
├── columns: x:5(int) y:6(int)
├── outer: (1-3)
├── cardinality: [0 - 1]
Expand Down Expand Up @@ -744,7 +744,7 @@ select
opt
SELECT * FROM (SELECT count(*) cnt FROM xysd) WHERE EXISTS(SELECT * FROM uv WHERE cnt=1)
----
semi-join
semi-join (hash)
├── columns: cnt:5(int!null)
├── cardinality: [0 - 1]
├── key: ()
Expand Down Expand Up @@ -815,7 +815,7 @@ semi-join-apply
opt
SELECT * FROM (SELECT * FROM (VALUES (1), (2))) WHERE NOT EXISTS(SELECT * FROM uv WHERE u=column1)
----
anti-join
anti-join (hash)
├── columns: column1:1(int!null)
├── cardinality: [0 - 2]
├── values
Expand Down Expand Up @@ -877,7 +877,7 @@ anti-join-apply
build
SELECT * FROM (VALUES (1), (2)) INNER JOIN (SELECT * FROM uv LIMIT 2) ON True
----
inner-join
inner-join (hash)
├── columns: column1:1(int!null) u:2(int) v:3(int!null)
├── cardinality: [0 - 4]
├── prune: (1-3)
Expand Down Expand Up @@ -910,7 +910,7 @@ inner-join
build
SELECT * FROM (VALUES (1), (2), (3)) LEFT JOIN (SELECT * FROM uv LIMIT 2) ON True
----
left-join
left-join (hash)
├── columns: column1:1(int!null) u:2(int) v:3(int)
├── cardinality: [3 - 6]
├── prune: (1-3)
Expand Down Expand Up @@ -946,7 +946,7 @@ left-join
build
SELECT * FROM (SELECT * FROM uv LIMIT 2) RIGHT JOIN (VALUES (1), (2), (3)) ON True
----
right-join
right-join (hash)
├── columns: u:1(int) v:2(int) column1:4(int!null)
├── cardinality: [3 - 6]
├── prune: (1,2,4)
Expand Down Expand Up @@ -982,7 +982,7 @@ right-join
build
SELECT * FROM (VALUES (NULL), (NULL)) a FULL JOIN (VALUES (NULL), (NULL)) b ON True
----
full-join
full-join (hash)
├── columns: column1:1(unknown) column1:2(unknown)
├── cardinality: [2 - 4]
├── prune: (1,2)
Expand Down Expand Up @@ -1010,7 +1010,7 @@ full-join
build
SELECT * FROM (VALUES (NULL), (NULL)) a FULL JOIN (VALUES (NULL), (NULL)) b ON a.column1=b.column1
----
full-join
full-join (hash)
├── columns: column1:1(unknown) column1:2(unknown)
├── cardinality: [2 - 4]
├── prune: (1,2)
Expand Down Expand Up @@ -1039,7 +1039,7 @@ full-join
build
SELECT * FROM xysd FULL JOIN (SELECT * FROM (VALUES (1), (2))) ON True
----
full-join
full-join (hash)
├── columns: x:1(int) y:2(int) s:3(string) d:4(decimal) column1:5(int)
├── cardinality: [2 - ]
├── fd: (1)-->(2-4), (3,4)~~>(1,2)
Expand Down Expand Up @@ -1067,7 +1067,7 @@ full-join
build
SELECT * FROM (SELECT * FROM xysd LIMIT 1) FULL JOIN (SELECT * FROM xysd LIMIT 1) ON True
----
full-join
full-join (hash)
├── columns: x:1(int) y:2(int) s:3(string) d:4(decimal) x:5(int) y:6(int) s:7(string) d:8(decimal)
├── cardinality: [0 - 1]
├── key: ()
Expand Down Expand Up @@ -1110,7 +1110,7 @@ full-join
build
SELECT * FROM xysd LEFT JOIN (SELECT u, sum(v) FROM uv GROUP BY u) ON u IS NOT NULL
----
left-join
left-join (hash)
├── columns: x:1(int!null) y:2(int) s:3(string) d:4(decimal!null) u:5(int) sum:8(decimal)
├── key: (1,5)
├── fd: (1)-->(2-4), (3,4)~~>(1,2), (5)~~>(8), (1,5)-->(8)
Expand Down Expand Up @@ -1150,7 +1150,7 @@ left-join
build
SELECT * FROM xysd LEFT JOIN (SELECT u, sum(v) FROM uv WHERE u IS NOT NULL GROUP BY u) ON True
----
left-join
left-join (hash)
├── columns: x:1(int!null) y:2(int) s:3(string) d:4(decimal!null) u:5(int) sum:8(decimal)
├── key: (1,5)
├── fd: (1)-->(2-4), (3,4)~~>(1,2), (5)-->(8)
Expand Down Expand Up @@ -1198,7 +1198,7 @@ left-join
build
SELECT * FROM (SELECT u, sum(v) FROM uv GROUP BY u) RIGHT JOIN xysd ON u IS NOT NULL
----
right-join
right-join (hash)
├── columns: u:1(int) sum:4(decimal) x:5(int!null) y:6(int) s:7(string) d:8(decimal!null)
├── key: (1,5)
├── fd: (5)-->(6-8), (7,8)~~>(5,6), (1)~~>(4), (1,5)-->(4)
Expand Down Expand Up @@ -1238,7 +1238,7 @@ right-join
build
SELECT * FROM (SELECT u, sum(v) FROM uv WHERE u IS NOT NULL GROUP BY u) RIGHT JOIN xysd ON True
----
right-join
right-join (hash)
├── columns: u:1(int) sum:4(decimal) x:5(int!null) y:6(int) s:7(string) d:8(decimal!null)
├── key: (1,5)
├── fd: (1)-->(4), (5)-->(6-8), (7,8)~~>(5,6)
Expand Down Expand Up @@ -1286,7 +1286,7 @@ right-join
build
SELECT * FROM xysd FULL JOIN (SELECT u, sum(v) FROM uv GROUP BY u) ON u IS NOT NULL
----
full-join
full-join (hash)
├── columns: x:1(int) y:2(int) s:3(string) d:4(decimal) u:5(int) sum:8(decimal)
├── key: (1,5)
├── fd: (1)-->(2-4), (3,4)~~>(1,2), (5)~~>(8), (1,5)-->(8)
Expand Down Expand Up @@ -1326,7 +1326,7 @@ full-join
build
SELECT * FROM (SELECT u, sum(v) FROM uv GROUP BY u) FULL JOIN xysd ON u IS NOT NULL
----
full-join
full-join (hash)
├── columns: u:1(int) sum:4(decimal) x:5(int) y:6(int) s:7(string) d:8(decimal)
├── key: (1,5)
├── fd: (5)-->(6-8), (7,8)~~>(5,6), (1)~~>(4), (1,5)-->(4)
Expand Down Expand Up @@ -1501,7 +1501,7 @@ project
│ ├── scan uv
│ │ ├── columns: u:1(int)
│ │ └── prune: (1)
│ ├── inner-join
│ ├── inner-join (hash)
│ │ ├── columns: u:4(int!null) v:5(int!null) rowid:6(int!null) mn.m:13(int!null)
│ │ ├── outer: (1)
│ │ ├── cardinality: [0 - 0]
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/opt/memo/testdata/logprops/scalar
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ SELECT xy.x + 1 = length('foo') + xy.y AS a, uv.rowid * xy.x AS b FROM xy, uv
project
├── columns: a:6(bool) b:7(int)
├── prune: (6,7)
├── inner-join
├── inner-join (hash)
│ ├── columns: x:1(int!null) y:2(int) u:3(int) v:4(int!null) rowid:5(int!null)
│ ├── key: (1,5)
│ ├── fd: (1)-->(2), (5)-->(3,4)
Expand Down Expand Up @@ -196,7 +196,7 @@ group-by
│ ├── fd: (1)-->(3)
│ ├── prune: (1,3)
│ ├── interesting orderings: (+1)
│ └── inner-join
│ └── inner-join (hash)
│ ├── columns: x:1(int!null) y:2(int) div:3(decimal) u:4(int!null) v:5(int!null)
│ ├── side-effects
│ ├── fd: (1)-->(2,3), (1)==(4), (4)==(1)
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/opt/memo/testdata/logprops/select
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ select
├── fd: (1)-->(2), (3)-->(4,5), (1)==(3), (3)==(1)
├── prune: (2,4,5)
├── interesting orderings: (+1) (+3)
├── inner-join
├── inner-join (hash)
│ ├── columns: x:1(int!null) y:2(int) k:3(int!null) u:4(float) v:5(string)
│ ├── key: (1,3)
│ ├── fd: (1)-->(2), (3)-->(4,5)
Expand Down
10 changes: 5 additions & 5 deletions pkg/sql/opt/memo/testdata/logprops/upsert
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ project
│ │ ├── fd: ()-->(6,9,14), (5)-->(8), (13)-->(10-12), (10)-->(11-13), (11,12)~~>(10,13), (12)-->(15)
│ │ ├── prune: (5,6,8-15)
│ │ ├── interesting orderings: (+5) (+6) (+13) (+10) (+11,+12,+13)
│ │ ├── left-join
│ │ ├── left-join (hash)
│ │ │ ├── columns: x:5(int!null) y:6(int!null) column8:8(int) column9:9(int) a:10(int) b:11(int) c:12(int) rowid:13(int)
│ │ │ ├── side-effects
│ │ │ ├── key: (5,13)
Expand Down Expand Up @@ -213,7 +213,7 @@ project
├── fd: ()-->(18-21), (5)-->(6,8), (6)-->(9)
├── prune: (5,8,18)
├── interesting orderings: (+5) (+6) (+21) (+18) (+19,+20,+21)
├── left-join
├── left-join (hash)
│ ├── columns: x:5(int!null) y:6(int) column8:8(int) column9:9(int) a:18(int) b:19(int) c:20(int) rowid:21(int)
│ ├── side-effects
│ ├── key: (5,21)
Expand All @@ -235,7 +235,7 @@ project
│ │ ├── fd: ()-->(14-17), (5)-->(6,8), (6)-->(9)
│ │ ├── prune: (6,8,9,15-17)
│ │ ├── interesting orderings: (+5) (+6) (+17) (+14) (+15,+16,+17)
│ │ ├── left-join
│ │ ├── left-join (hash)
│ │ │ ├── columns: x:5(int!null) y:6(int) column8:8(int) column9:9(int) a:14(int) b:15(int) c:16(int) rowid:17(int)
│ │ │ ├── side-effects
│ │ │ ├── key: (5,17)
Expand All @@ -257,7 +257,7 @@ project
│ │ │ │ ├── fd: ()-->(10-13), (5)-->(6,8), (6)-->(9)
│ │ │ │ ├── prune: (5,6,9-12)
│ │ │ │ ├── interesting orderings: (+5) (+6) (+13) (+10) (+11,+12,+13)
│ │ │ │ ├── left-join
│ │ │ │ ├── left-join (hash)
│ │ │ │ │ ├── columns: x:5(int!null) y:6(int) column8:8(int) column9:9(int) a:10(int) b:11(int) c:12(int) rowid:13(int)
│ │ │ │ │ ├── side-effects
│ │ │ │ │ ├── key: (5,13)
Expand Down Expand Up @@ -385,7 +385,7 @@ project
│ │ ├── fd: ()-->(6,8), (12)-->(9-11), (9)-->(10-12), (10,11)~~>(9,12), (10)-->(13)
│ │ ├── prune: (5-13)
│ │ ├── interesting orderings: (+12) (+9) (+10,+11,+12)
│ │ ├── left-join
│ │ ├── left-join (hash)
│ │ │ ├── columns: column1:5(int!null) column6:6(int!null) column7:7(int) column8:8(int) a:9(int) b:10(int) c:11(int) rowid:12(int)
│ │ │ ├── cardinality: [2 - ]
│ │ │ ├── side-effects
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/opt/memo/testdata/logprops/virtual-scan
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ON CATALOG_NAME=TABLE_CATALOG AND SCHEMA_NAME=TABLE_SCHEMA
project
├── columns: catalog_name:1(string) sql_path:4(string)
├── prune: (1,4)
└── left-join
└── left-join (hash)
├── columns: catalog_name:1(string) schema_name:2(string!null) default_character_set_name:3(string) sql_path:4(string) table_catalog:5(string) table_schema:6(string) table_name:7(string) table_type:8(string) is_insertable_into:9(string) version:10(int)
├── fd: ()-->(2)
├── reject-nulls: (5-10)
Expand Down
Loading

0 comments on commit 5713aa6

Please sign in to comment.