-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
scan
231 lines (205 loc) · 4.85 KB
/
scan
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
exec-ddl
CREATE TABLE kv (k INT PRIMARY KEY, v INT)
----
exec-ddl
CREATE TABLE abcd (
a INT,
b INT,
c INT,
d INT,
INDEX (a,b) STORING (c),
INDEX (c,b,a) STORING (d),
INDEX (d,c,a),
INDEX (d,c,b)
)
----
placeholder-fast-path
SELECT * FROM kv WHERE k = $1
----
placeholder-scan kv
├── columns: k:1!null v:2
├── has-placeholder
├── key: (1)
├── fd: (1)-->(2)
└── span
└── $1
placeholder-fast-path
SELECT * FROM kv WHERE k = $1 FOR UPDATE
----
placeholder-scan kv
├── columns: k:1!null v:2
├── locking: for-update
├── volatile, has-placeholder
├── key: (1)
├── fd: (1)-->(2)
└── span
└── $1
placeholder-fast-path
SELECT k FROM kv WHERE k = $1
----
placeholder-scan kv
├── columns: k:1!null
├── has-placeholder
├── key: (1)
└── span
└── $1
placeholder-fast-path
SELECT k FROM kv WHERE k IN ($1)
----
placeholder-scan kv
├── columns: k:1!null
├── has-placeholder
├── key: (1)
└── span
└── $1
placeholder-fast-path
SELECT v FROM kv WHERE k = $1
----
placeholder-scan kv
├── columns: v:2
├── has-placeholder
└── span
└── $1
# Fast path not available when we're projecting a new expression.
placeholder-fast-path
SELECT v+1 FROM kv WHERE k = $1
----
no fast path
placeholder-fast-path
SELECT a, b, c FROM abcd WHERE a=$1 AND b=$2
----
placeholder-scan abcd@secondary
├── columns: a:1!null b:2!null c:3
├── has-placeholder
└── span
├── $1
└── $2
placeholder-fast-path
SELECT a, b, c FROM abcd WHERE b=$1 AND a=$2
----
placeholder-scan abcd@secondary
├── columns: a:1!null b:2!null c:3
├── has-placeholder
└── span
├── $2
└── $1
# One constant value, one placeholder.
placeholder-fast-path
SELECT a, b, c FROM abcd WHERE a=0 AND b=$1
----
placeholder-scan abcd@secondary
├── columns: a:1!null b:2!null c:3
├── has-placeholder
├── fd: ()-->(1)
└── span
├── 0
└── $1
placeholder-fast-path
SELECT a, b, c FROM abcd WHERE a=$1 AND b=0
----
placeholder-scan abcd@secondary
├── columns: a:1!null b:2!null c:3
├── has-placeholder
├── fd: ()-->(2)
└── span
├── $1
└── 0
# Constant folding is allowed (for immutable operators).
placeholder-fast-path
SELECT a, b, c FROM abcd WHERE a=1+2 AND b=$1
----
placeholder-scan abcd@secondary
├── columns: a:1!null b:2!null c:3
├── has-placeholder
├── fd: ()-->(1)
└── span
├── 3
└── $1
placeholder-fast-path
SELECT a, b, c FROM abcd WHERE a=fnv32a('foo') AND b=$1
----
placeholder-scan abcd@secondary
├── columns: a:1!null b:2!null c:3
├── has-placeholder
├── fd: ()-->(1)
└── span
├── 2851307223
└── $1
# Fast path not available when value is not constant-foldable.
placeholder-fast-path
SELECT a, b, c FROM abcd WHERE a=now()::string::int AND b=$1
----
no fast path
placeholder-fast-path
SELECT a, b, c FROM abcd WHERE a=0 AND b=$1+1
----
no fast path
# Fast path not available when we have an ordering requirement.
placeholder-fast-path
SELECT a, b, c FROM abcd WHERE a=$1 AND b=$2 ORDER BY c
----
no fast path
# Fast path not available when we have a limit.
placeholder-fast-path
SELECT a, b, c FROM abcd WHERE a=$1 AND b=$2 LIMIT 1
----
no fast path
# Fast path not available when index is not covering.
placeholder-fast-path
SELECT a, b, c, d FROM abcd WHERE a=$1 AND b=$2
----
no fast path
# Fast path not available when two indexes are possible.
placeholder-fast-path
SELECT d FROM abcd WHERE d=$1 AND c=$2
----
no fast path
# Now we have only one covering index.
placeholder-fast-path
SELECT a, d FROM abcd WHERE d=$1 AND c=$2
----
placeholder-scan abcd@secondary
├── columns: a:1 d:4!null
├── has-placeholder
└── span
├── $1
└── $2
exec-ddl
CREATE TABLE kj (
k INT PRIMARY KEY,
j JSON,
INVERTED INDEX(j)
)
----
# Verify that we don't incorrectly use an inverted index.
placeholder-fast-path
SELECT j FROM kj WHERE j = '{"foo": "bar"}'::JSON
----
no fast path
exec-ddl
CREATE TABLE partial1 (
k INT PRIMARY KEY,
a INT,
b INT,
c INT,
INDEX (a, b) WHERE (c = 0),
INDEX (c, a, b),
INDEX (a, b) WHERE (1 = 1)
)
----
# Make sure the fast path doesn't choose the (c,a,b) index, getting in the way
# of using a partial index.
placeholder-fast-path
SELECT a, b FROM partial1 WHERE c = 0
----
no fast path
# Ok to ignore the partial index when the filters don't involve predicate
# columns; and, ok to use a pseudo-partial index.
placeholder-fast-path
SELECT a, b FROM partial1 WHERE a = 0
----
placeholder-scan partial1@secondary,partial
├── columns: a:2!null b:3
├── fd: ()-->(2)
└── span
└── 0