-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathopt_steps
275 lines (270 loc) · 12.3 KB
/
opt_steps
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
optsteps
SELECT 1
----
================================================================================
Initial expression
Cost: 0.05
================================================================================
project
├── columns: "?column?":1(int!null)
├── cardinality: [1 - 1]
├── key: ()
├── fd: ()-->(1)
├── values
│ ├── cardinality: [1 - 1]
│ ├── key: ()
│ └── tuple [type=tuple]
└── projections
└── const: 1 [type=int]
================================================================================
MergeProjectWithValues
Cost: 0.02
================================================================================
-project
+values
├── columns: "?column?":1(int!null)
├── cardinality: [1 - 1]
├── key: ()
├── fd: ()-->(1)
- ├── values
- │ ├── cardinality: [1 - 1]
- │ ├── key: ()
- │ └── tuple [type=tuple]
- └── projections
+ └── tuple [type=tuple{int}]
└── const: 1 [type=int]
================================================================================
Final best expression
Cost: 0.02
================================================================================
values
├── columns: "?column?":1(int!null)
├── cardinality: [1 - 1]
├── key: ()
├── fd: ()-->(1)
└── tuple [type=tuple{int}]
└── const: 1 [type=int]
exec-ddl
CREATE TABLE ab (a INT PRIMARY KEY, b INT, INDEX(b))
----
optsteps
SELECT * FROM ab WHERE b=1
----
================================================================================
Initial expression
Cost: 1050.03
================================================================================
select
├── columns: a:1(int!null) b:2(int!null)
├── key: (1)
├── fd: ()-->(2)
├── scan ab
│ ├── columns: a:1(int!null) b:2(int)
│ ├── key: (1)
│ └── fd: (1)-->(2)
└── filters
└── eq [type=bool, outer=(2), constraints=(/2: [/1 - /1]; tight), fd=()-->(2)]
├── variable: b [type=int]
└── const: 1 [type=int]
--------------------------------------------------------------------------------
GenerateIndexScans (higher cost)
--------------------------------------------------------------------------------
select
├── columns: a:1(int!null) b:2(int!null)
├── key: (1)
├── fd: ()-->(2)
- ├── scan ab
+ ├── scan ab@secondary
│ ├── columns: a:1(int!null) b:2(int)
│ ├── key: (1)
│ └── fd: (1)-->(2)
└── filters
└── eq [type=bool, outer=(2), constraints=(/2: [/1 - /1]; tight), fd=()-->(2)]
├── variable: b [type=int]
└── const: 1 [type=int]
--------------------------------------------------------------------------------
GenerateZigzagJoins (no changes)
--------------------------------------------------------------------------------
================================================================================
GenerateConstrainedScans
Cost: 10.41
================================================================================
-select
+scan ab@secondary
├── columns: a:1(int!null) b:2(int!null)
+ ├── constraint: /2/1: [/1 - /1]
├── key: (1)
- ├── fd: ()-->(2)
- ├── scan ab
- │ ├── columns: a:1(int!null) b:2(int)
- │ ├── key: (1)
- │ └── fd: (1)-->(2)
- └── filters
- └── eq [type=bool, outer=(2), constraints=(/2: [/1 - /1]; tight), fd=()-->(2)]
- ├── variable: b [type=int]
- └── const: 1 [type=int]
+ └── fd: ()-->(2)
================================================================================
Final best expression
Cost: 10.41
================================================================================
scan ab@secondary
├── columns: a:1(int!null) b:2(int!null)
├── constraint: /2/1: [/1 - /1]
├── key: (1)
└── fd: ()-->(2)
exec-ddl
CREATE TABLE customers (
id INT8 NOT NULL,
name STRING NOT NULL,
address STRING NULL,
CONSTRAINT "primary" PRIMARY KEY (id ASC),
FAMILY "primary" (id, name, address)
)
----
exec-ddl
CREATE TABLE orders (
id INT8 NOT NULL,
customer_id INT8 NULL,
status STRING NOT NULL,
CONSTRAINT "primary" PRIMARY KEY (id ASC),
CONSTRAINT fk_customer_id_ref_customers FOREIGN KEY (customer_id) REFERENCES customers(id),
INDEX orders_auto_index_fk_customer_id_ref_customers (customer_id ASC),
FAMILY "primary" (id, customer_id, status),
CONSTRAINT check_status CHECK (status IN ('open':::STRING, 'complete':::STRING, 'cancelled':::STRING))
)
----
# Verify that we don't crash when a normalization rule runs on a constraint
# expression that is attached to the TableMeta but otherwise not used.
# In this example, the rule is NormalizeInConst.
optsteps
SELECT * FROM orders LEFT JOIN customers ON customer_id = customers.id
----
================================================================================
Initial expression
Cost: 2160.05
================================================================================
left-join (hash)
├── columns: id:1(int!null) customer_id:2(int) status:3(string!null) id:4(int) name:5(string) address:6(string)
├── key: (1,4)
├── fd: (1)-->(2,3), (4)-->(5,6)
├── scan orders
│ ├── columns: orders.id:1(int!null) customer_id:2(int) status:3(string!null)
│ ├── key: (1)
│ └── fd: (1)-->(2,3)
├── scan customers
│ ├── columns: customers.id:4(int!null) name:5(string!null) address:6(string)
│ ├── key: (4)
│ └── fd: (4)-->(5,6)
└── filters
└── eq [type=bool, outer=(2,4), constraints=(/2: (/NULL - ]; /4: (/NULL - ]), fd=(2)==(4), (4)==(2)]
├── variable: customer_id [type=int]
└── variable: customers.id [type=int]
--------------------------------------------------------------------------------
NormalizeInConst (no changes)
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
GenerateIndexScans (no changes)
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
GenerateIndexScans (no changes)
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
CommuteLeftJoin (higher cost)
--------------------------------------------------------------------------------
-left-join (hash)
+right-join (hash)
├── columns: id:1(int!null) customer_id:2(int) status:3(string!null) id:4(int) name:5(string) address:6(string)
├── key: (1,4)
├── fd: (1)-->(2,3), (4)-->(5,6)
+ ├── scan customers
+ │ ├── columns: customers.id:4(int!null) name:5(string!null) address:6(string)
+ │ ├── key: (4)
+ │ └── fd: (4)-->(5,6)
├── scan orders
│ ├── columns: orders.id:1(int!null) customer_id:2(int) status:3(string!null)
│ ├── key: (1)
│ └── fd: (1)-->(2,3)
- ├── scan customers
- │ ├── columns: customers.id:4(int!null) name:5(string!null) address:6(string)
- │ ├── key: (4)
- │ └── fd: (4)-->(5,6)
└── filters
└── eq [type=bool, outer=(2,4), constraints=(/2: (/NULL - ]; /4: (/NULL - ]), fd=(2)==(4), (4)==(2)]
├── variable: customer_id [type=int]
└── variable: customers.id [type=int]
--------------------------------------------------------------------------------
GenerateMergeJoins (no changes)
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
GenerateLookupJoins (higher cost)
--------------------------------------------------------------------------------
-left-join (hash)
+left-join (lookup customers)
├── columns: id:1(int!null) customer_id:2(int) status:3(string!null) id:4(int) name:5(string) address:6(string)
+ ├── key columns: [2] = [4]
+ ├── lookup columns are key
├── key: (1,4)
├── fd: (1)-->(2,3), (4)-->(5,6)
├── scan orders
│ ├── columns: orders.id:1(int!null) customer_id:2(int) status:3(string!null)
│ ├── key: (1)
│ └── fd: (1)-->(2,3)
- ├── scan customers
- │ ├── columns: customers.id:4(int!null) name:5(string!null) address:6(string)
- │ ├── key: (4)
- │ └── fd: (4)-->(5,6)
- └── filters
- └── eq [type=bool, outer=(2,4), constraints=(/2: (/NULL - ]; /4: (/NULL - ]), fd=(2)==(4), (4)==(2)]
- ├── variable: customer_id [type=int]
- └── variable: customers.id [type=int]
+ └── filters (true)
--------------------------------------------------------------------------------
GenerateMergeJoins (higher cost)
--------------------------------------------------------------------------------
-left-join (lookup customers)
+right-join (merge)
├── columns: id:1(int!null) customer_id:2(int) status:3(string!null) id:4(int) name:5(string) address:6(string)
- ├── key columns: [2] = [4]
- ├── lookup columns are key
+ ├── left ordering: +4
+ ├── right ordering: +2
├── key: (1,4)
├── fd: (1)-->(2,3), (4)-->(5,6)
- ├── scan orders
+ ├── scan customers
+ │ ├── columns: customers.id:4(int!null) name:5(string!null) address:6(string)
+ │ ├── key: (4)
+ │ ├── fd: (4)-->(5,6)
+ │ └── ordering: +4
+ ├── sort
│ ├── columns: orders.id:1(int!null) customer_id:2(int) status:3(string!null)
│ ├── key: (1)
- │ └── fd: (1)-->(2,3)
+ │ ├── fd: (1)-->(2,3)
+ │ ├── ordering: +2
+ │ └── scan orders
+ │ ├── columns: orders.id:1(int!null) customer_id:2(int) status:3(string!null)
+ │ ├── key: (1)
+ │ └── fd: (1)-->(2,3)
└── filters (true)
================================================================================
Final best expression
Cost: 2160.05
================================================================================
left-join (hash)
├── columns: id:1(int!null) customer_id:2(int) status:3(string!null) id:4(int) name:5(string) address:6(string)
├── key: (1,4)
├── fd: (1)-->(2,3), (4)-->(5,6)
├── scan orders
│ ├── columns: orders.id:1(int!null) customer_id:2(int) status:3(string!null)
│ ├── key: (1)
│ └── fd: (1)-->(2,3)
├── scan customers
│ ├── columns: customers.id:4(int!null) name:5(string!null) address:6(string)
│ ├── key: (4)
│ └── fd: (4)-->(5,6)
└── filters
└── eq [type=bool, outer=(2,4), constraints=(/2: (/NULL - ]; /4: (/NULL - ]), fd=(2)==(4), (4)==(2)]
├── variable: customer_id [type=int]
└── variable: customers.id [type=int]