forked from orioledb/orioledb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
subquery.out
257 lines (241 loc) · 6.88 KB
/
subquery.out
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
CREATE EXTENSION orioledb;
CREATE TABLE o_test_subquery
(
key bigint NOT NULL,
val int,
val2 int NOT NULL,
PRIMARY KEY (key)
) USING orioledb;
CREATE INDEX o_test_subquery_idx1 ON o_test_subquery (val);
INSERT INTO o_test_subquery SELECT 1000 + i, 2000 + i, 3000 + i FROM generate_series(1, 500) AS i;
CREATE INDEX o_test_subquery_idx2 ON o_test_subquery (val2);
analyze o_test_subquery;
-- index subscan; index only qual
SELECT smart_explain(
'EXPLAIN (COSTS off) WITH o_test_subquery_all AS (
SELECT * FROM o_test_subquery
WHERE val2 > 0 AND ABS(val2) IS NOT NULL
ORDER BY val2
) SELECT COUNT(*) FROM o_test_subquery_all;');
smart_explain
----------------------------------------------------------
Aggregate
-> Custom Scan (o_scan) on o_test_subquery
Filter: (abs(val2) IS NOT NULL)
Forward index only scan of: o_test_subquery_idx2
Conds: (val2 > 0)
(5 rows)
-- returns 500
WITH o_test_subquery_all AS (
SELECT * FROM o_test_subquery
WHERE val2 > 0 AND ABS(val2) IS NOT NULL
ORDER BY val2
) SELECT COUNT(*) FROM o_test_subquery_all;
count
-------
500
(1 row)
-- index subscan; index only qual; query rows
SELECT smart_explain(
'EXPLAIN (COSTS off) WITH o_test_subquery_all AS (
SELECT * FROM o_test_subquery
WHERE val2 > 0 AND ABS(val2) IS NOT NULL
ORDER BY val2
) SELECT * FROM o_test_subquery_all LIMIT 10;');
smart_explain
-----------------------------------------------------
Limit
-> Custom Scan (o_scan) on o_test_subquery
Filter: (abs(val2) IS NOT NULL)
Forward index scan of: o_test_subquery_idx2
Conds: (val2 > 0)
(5 rows)
WITH o_test_subquery_all AS (
SELECT * FROM o_test_subquery
WHERE val2 > 0 AND ABS(val2) IS NOT NULL
ORDER BY val2
) SELECT * FROM o_test_subquery_all LIMIT 10;
key | val | val2
------+------+------
1001 | 2001 | 3001
1002 | 2002 | 3002
1003 | 2003 | 3003
1004 | 2004 | 3004
1005 | 2005 | 3005
1006 | 2006 | 3006
1007 | 2007 | 3007
1008 | 2008 | 3008
1009 | 2009 | 3009
1010 | 2010 | 3010
(10 rows)
-- index subscan
SELECT smart_explain(
'EXPLAIN (COSTS off) WITH o_test_subquery_all AS (
SELECT * FROM o_test_subquery
WHERE val2 > 0 AND val > 0
ORDER BY val2
) SELECT COUNT(*) FROM o_test_subquery_all;');
smart_explain
-----------------------------------------------------
Aggregate
-> Custom Scan (o_scan) on o_test_subquery
Filter: (val > 0)
Forward index scan of: o_test_subquery_idx2
Conds: (val2 > 0)
(5 rows)
-- returns 500
WITH o_test_subquery_all AS (
SELECT * FROM o_test_subquery
WHERE val2 > 0 AND val > 0
ORDER BY val2
) SELECT COUNT(*) FROM o_test_subquery_all;
count
-------
500
(1 row)
-- index subscan; query rows
EXPLAIN (COSTS off) WITH o_test_subquery_all AS (
SELECT * FROM o_test_subquery
WHERE val2 > 0 AND val > 0
ORDER BY val2
) SELECT * FROM o_test_subquery_all LIMIT 10;
QUERY PLAN
-----------------------------------------------------
Limit
-> Custom Scan (o_scan) on o_test_subquery
Filter: (val > 0)
Forward index scan of: o_test_subquery_idx2
Conds: (val2 > 0)
(5 rows)
WITH o_test_subquery_all AS (
SELECT * FROM o_test_subquery
WHERE val2 > 0 AND val > 0
ORDER BY val2
) SELECT * FROM o_test_subquery_all LIMIT 10;
key | val | val2
------+------+------
1001 | 2001 | 3001
1002 | 2002 | 3002
1003 | 2003 | 3003
1004 | 2004 | 3004
1005 | 2005 | 3005
1006 | 2006 | 3006
1007 | 2007 | 3007
1008 | 2008 | 3008
1009 | 2009 | 3009
1010 | 2010 | 3010
(10 rows)
-- index only subscan; index only qual
EXPLAIN (COSTS off) WITH o_test_subquery_all AS (
SELECT val2 FROM o_test_subquery
WHERE val2 > 0 AND ABS(val2) IS NOT NULL
ORDER BY val2
) SELECT COUNT(o_test_subquery_all.val2) FROM o_test_subquery_all;
QUERY PLAN
----------------------------------------------------------
Aggregate
-> Custom Scan (o_scan) on o_test_subquery
Filter: (abs(val2) IS NOT NULL)
Forward index only scan of: o_test_subquery_idx2
Conds: (val2 > 0)
(5 rows)
-- returns 500
WITH o_test_subquery_all AS (
SELECT val2 FROM o_test_subquery
WHERE val2 > 0 AND ABS(val2) IS NOT NULL
ORDER BY val2
) SELECT COUNT(o_test_subquery_all.val2) FROM o_test_subquery_all;
count
-------
500
(1 row)
-- index only subscan; index only qual; query rows
EXPLAIN (COSTS off) WITH o_test_subquery_all AS (
SELECT val2 FROM o_test_subquery
WHERE val2 > 0 AND ABS(val2) IS NOT NULL
ORDER BY val2
) SELECT o_test_subquery_all.val2 FROM o_test_subquery_all LIMIT 10;
QUERY PLAN
----------------------------------------------------------
Limit
-> Custom Scan (o_scan) on o_test_subquery
Filter: (abs(val2) IS NOT NULL)
Forward index only scan of: o_test_subquery_idx2
Conds: (val2 > 0)
(5 rows)
WITH o_test_subquery_all AS (
SELECT val2 FROM o_test_subquery
WHERE val2 > 0 AND ABS(val2) IS NOT NULL
ORDER BY val2
) SELECT o_test_subquery_all.val2 FROM o_test_subquery_all LIMIT 10;
val2
------
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
(10 rows)
-- index only subscan
EXPLAIN (COSTS off) WITH o_test_subquery_all AS (
SELECT val2 FROM o_test_subquery
WHERE val2 > 0 AND val > 4
ORDER BY val2
) SELECT COUNT(o_test_subquery_all.val2) FROM o_test_subquery_all;
QUERY PLAN
-----------------------------------------------------
Aggregate
-> Custom Scan (o_scan) on o_test_subquery
Filter: (val > 4)
Forward index scan of: o_test_subquery_idx2
Conds: (val2 > 0)
(5 rows)
-- returns 500
WITH o_test_subquery_all AS (
SELECT val2 FROM o_test_subquery
WHERE val2 > 0 AND val > 4
ORDER BY val2
) SELECT COUNT(o_test_subquery_all.val2) FROM o_test_subquery_all;
count
-------
500
(1 row)
-- index only subscan; query rows
EXPLAIN (COSTS off) WITH o_test_subquery_all AS (
SELECT val2 FROM o_test_subquery
WHERE val2 > 0 AND val > 4
ORDER BY val2
) SELECT o_test_subquery_all.val2 FROM o_test_subquery_all LIMIT 10;
QUERY PLAN
-----------------------------------------------------
Limit
-> Custom Scan (o_scan) on o_test_subquery
Filter: (val > 4)
Forward index scan of: o_test_subquery_idx2
Conds: (val2 > 0)
(5 rows)
WITH o_test_subquery_all AS (
SELECT val2 FROM o_test_subquery
WHERE val2 > 0 AND val > 4
ORDER BY val2
) SELECT o_test_subquery_all.val2 FROM o_test_subquery_all LIMIT 10;
val2
------
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
(10 rows)
DROP EXTENSION orioledb CASCADE;
NOTICE: drop cascades to table o_test_subquery