-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathdistsql_auto_mode
160 lines (131 loc) · 4.69 KB
/
distsql_auto_mode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# LogicTest: local
#
# Tests that verify DistSQL support and auto mode determination.
# The cluster size or distsql mode aren't important for these tests.
#
# "local" logic test configuration overrides the DistSQL mode to 'off', but
# we're interested in behavior with 'auto' in this test file.
statement ok
SET distsql=auto
statement ok
CREATE TABLE kv (k INT PRIMARY KEY, v INT)
# Verify the JSON variant.
query T
EXPLAIN (DISTSQL, JSON) SELECT 1
----
{"sql":"EXPLAIN (DISTSQL, JSON) SELECT 1","nodeNames":["1"],"processors":[{"nodeIdx":0,"inputs":[],"core":{"title":"local values 0/0","details":[]},"outputs":[],"stage":1},{"nodeIdx":0,"inputs":[],"core":{"title":"Response","details":[]},"outputs":[],"stage":0}],"edges":[{"sourceProc":0,"sourceOutput":0,"destProc":1,"destInput":0}]}
# Full table scan - distribute.
query T
SELECT info FROM [EXPLAIN SELECT * FROM kv] WHERE info LIKE 'distribution%'
----
distribution: full
# Partial scan - don't distribute.
query T
SELECT info FROM [EXPLAIN SELECT * FROM kv WHERE k=1] WHERE info LIKE 'distribution%'
----
distribution: local
# Partial scan - don't distribute.
query T
SELECT info FROM [EXPLAIN SELECT * FROM kv WHERE k>1] WHERE info LIKE 'distribution%'
----
distribution: local
# Partial scan with filter - don't distribute.
query T
SELECT info FROM [EXPLAIN SELECT * FROM kv WHERE k>1 AND v=1] WHERE info LIKE 'distribution%'
----
distribution: local
# Sort - distribute.
query T
SELECT info FROM [EXPLAIN SELECT * FROM kv WHERE k>1 ORDER BY v] WHERE info LIKE 'distribution%'
----
distribution: full
# Aggregation - distribute.
query T
SELECT info FROM [EXPLAIN SELECT k, sum(v) FROM kv WHERE k>1 GROUP BY k] WHERE info LIKE 'distribution%'
----
distribution: full
# Hard limit in scan - distribute.
query T
SELECT info FROM [EXPLAIN SELECT * FROM kv LIMIT 1] WHERE info LIKE 'distribution%'
----
distribution: full
# Soft limit in scan - don't distribute.
# TODO(yuzefovich): soft limits are currently ignored in scans.
query T
SELECT info FROM [EXPLAIN SELECT * FROM kv UNION SELECT * FROM kv LIMIT 1] WHERE info LIKE 'distribution%'
----
distribution: full
# Limit after sort - distribute.
query T
SELECT info FROM [EXPLAIN SELECT * FROM kv WHERE k>1 ORDER BY v LIMIT 1] WHERE info LIKE 'distribution%'
----
distribution: full
# Limit after aggregation - distribute.
query T
SELECT info FROM [EXPLAIN SELECT k, sum(v) FROM kv WHERE k>1 GROUP BY k LIMIT 1] WHERE info LIKE 'distribution%'
----
distribution: full
statement ok
CREATE TABLE kw (k INT PRIMARY KEY, w INT)
# Join - distribute.
query T
SELECT info FROM [EXPLAIN SELECT * FROM kv NATURAL JOIN kw] WHERE info LIKE 'distribution%'
----
distribution: full
# Join with span - distribute.
query T
SELECT info FROM [EXPLAIN SELECT * FROM kv NATURAL JOIN kw WHERE k=1] WHERE info LIKE 'distribution%'
----
distribution: full
statement ok
CREATE TABLE abc (a INT PRIMARY KEY, b INT, c INT, INDEX b (b))
# Index join - don't distribute.
query T
SELECT info FROM [EXPLAIN SELECT * FROM abc WHERE b=1] WHERE info LIKE 'distribution%'
----
distribution: local
# Index join with filter on result - don't distribute.
query T
SELECT info FROM [EXPLAIN SELECT * FROM abc WHERE b=1 AND c%2=0] WHERE info LIKE 'distribution%'
----
distribution: local
# Index join with filter on index scan - don't distribute.
query T
SELECT info FROM [EXPLAIN SELECT * FROM abc WHERE b=1 AND a%2=0] WHERE info LIKE 'distribution%'
----
distribution: local
# Lookup join - distribute.
query T
SELECT info FROM [EXPLAIN SELECT a FROM abc INNER LOOKUP JOIN kv ON b = k WHERE k < 10] WHERE info LIKE 'distribution%'
----
distribution: full
# Lookup join on top of the full scan - distribute.
query T
SELECT info FROM [EXPLAIN SELECT a FROM abc INNER LOOKUP JOIN kv ON b = k] WHERE info LIKE 'distribution%'
----
distribution: full
statement ok
SET CLUSTER SETTING sql.distsql.prefer_local_execution.enabled = true;
# Limit after sort (i.e. top K sort) - don't distribute when preferring local
# execution.
query T
SELECT info FROM [EXPLAIN SELECT * FROM kv WHERE k>1 ORDER BY v LIMIT 1] WHERE info LIKE 'distribution%'
----
distribution: local
# General sort - distribute.
query T
SELECT info FROM [EXPLAIN SELECT * FROM kv WHERE k>1 ORDER BY v] WHERE info LIKE 'distribution%'
----
distribution: full
# Lookup join - don't distribute when preferring local execution.
query T
SELECT info FROM [EXPLAIN SELECT a FROM abc INNER LOOKUP JOIN kv ON b = k WHERE k < 10] WHERE info LIKE 'distribution%'
----
distribution: local
# Lookup join on top of the full scan - distribute.
query T
SELECT info FROM [EXPLAIN SELECT a FROM abc INNER LOOKUP JOIN kv ON b = k] WHERE info LIKE 'distribution%'
----
distribution: full
statement ok
RESET CLUSTER SETTING sql.distsql.prefer_local_execution.enabled;