Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2026-04-30 9f2ef60949ced4fab4d077a7e1c6d913f3620c9b
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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
-- Tests for disable index hints
LOAD 'pg_hint_plan';
SET search_path TO public;
SET pg_hint_plan.debug_print TO on;
SET client_min_messages TO LOG;
SET pg_hint_plan.enable_hint TO on;
CREATE SCHEMA disable_index;
-- Single table
CREATE TABLE disable_index.t1 (c1 int, c2 int, PRIMARY KEY (c1));
CREATE INDEX t1_i1 ON disable_index.t1(c1);
INSERT INTO disable_index.t1 SELECT i, i % 10
  FROM (SELECT generate_series(0, 300) i) t;
-- Tables with inheritance with indexes
CREATE TABLE disable_index.p3 (c1 int, c2 int, c3 int, c4 int, PRIMARY KEY (c1));
CREATE TABLE disable_index.p3_1_100 (CHECK (c4 >= 1 AND c4 < 101))
  INHERITS (disable_index.p3);
CREATE TABLE disable_index.p3_100_200 (CHECK (c4 >= 101 AND c4 < 201))
  INHERITS (disable_index.p3);
CREATE TABLE disable_index.p3_200_300 (CHECK (c4 >= 201 AND c4 < 301))
  INHERITS (disable_index.p3);
INSERT INTO disable_index.p3 SELECT i, i, i % 10, i
  FROM (SELECT generate_series(0, 300) i) t;
CREATE INDEX p3_c1_idx ON disable_index.p3(c1);
CREATE INDEX p3_1_100_c1_c2_idx ON disable_index.p3_1_100(c1, c2);
CREATE INDEX p3_1_100_c1_idx ON disable_index.p3_1_100(c1);
CREATE INDEX p3_100_200_c1_idx ON disable_index.p3_100_200(c1);
CREATE INDEX p3_200_300_c1_idx ON disable_index.p3_200_300(c1);
-- Partitioned tables and partitions
CREATE TABLE disable_index.pt2 (c1 int, c2 int, c3 int, c4 text, PRIMARY KEY (c1, c2))
  PARTITION BY RANGE(c1);
CREATE TABLE disable_index.pt2_0_1 PARTITION OF disable_index.pt2
  FOR VALUES FROM (MINVALUE) TO (101) PARTITION BY RANGE (c2);
CREATE TABLE disable_index.pt2_0_2 PARTITION OF disable_index.pt2
  FOR VALUES FROM (101) TO (201) PARTITION BY RANGE (c2);
CREATE TABLE disable_index.pt2_0_3 PARTITION OF disable_index.pt2
  FOR VALUES FROM (201) TO (MAXVALUE) PARTITION BY RANGE (c2);
CREATE TABLE disable_index.pt2_1_1 PARTITION OF disable_index.pt2_0_1
  FOR VALUES FROM (MINVALUE) TO (151);
CREATE TABLE disable_index.pt2_1_2 PARTITION OF disable_index.pt2_0_1
  FOR VALUES FROM (151) TO (MAXVALUE);
CREATE TABLE disable_index.pt2_1_3 PARTITION OF disable_index.pt2_0_2
  FOR VALUES FROM (MINVALUE) TO (151);
CREATE TABLE disable_index.pt2_1_4 PARTITION OF disable_index.pt2_0_2
  FOR VALUES FROM (151) TO (MAXVALUE);
CREATE TABLE disable_index.pt2_1_5 PARTITION OF disable_index.pt2_0_3
  FOR VALUES FROM (MINVALUE) TO (151);
CREATE TABLE disable_index.pt2_1_6 PARTITION OF disable_index.pt2_0_3
  FOR VALUES FROM (151) TO (MAXVALUE);
INSERT INTO disable_index.pt2 SELECT i, i, i % 10, i
  FROM (SELECT generate_series(0, 300) i) t;
-- Extra index, created on all partitions.
CREATE INDEX pt2_c1_idx ON disable_index.pt2 (c1, c2);
-- Hint conflicts
/*+ DisableIndex(t1) */
EXPLAIN (COSTS false) SELECT * FROM disable_index.t1 WHERE c1 = 1;
INFO:  pg_hint_plan: hint syntax error at or near " "
DETAIL:  DisableIndex hint requires a relation and at least one index.
LOG:  pg_hint_plan:
used hint:
not used hint:
duplication hint:
error hint:
DisableIndex()
 
          QUERY PLAN          
------------------------------
 Index Scan using t1_i1 on t1
   Index Cond: (c1 = 1)
(2 rows)
 
/*+DisableIndex(t1 t1_pkey)DisableIndex(t1 t1_i1)*/
EXPLAIN (COSTS false) SELECT * FROM disable_index.t1 WHERE c1 = 1;
INFO:  pg_hint_plan: hint syntax error at or near "DisableIndex(t1 t1_pkey)DisableIndex(t1 t1_i1)"
DETAIL:  Conflict disableindex hint.
LOG:  indexes disabled for DisableIndex(t1): t1_i1
LOG:  pg_hint_plan:
used hint:
DisableIndex(t1 t1_i1)
not used hint:
duplication hint:
DisableIndex(t1 t1_pkey)
error hint:
 
           QUERY PLAN           
--------------------------------
 Index Scan using t1_pkey on t1
   Index Cond: (c1 = 1)
(2 rows)
 
-- non-existent index
/*+ DisableIndex(pt2 non_existent) */
EXPLAIN (COSTS OFF) SELECT * FROM disable_index.pt2 WHERE c1 IN (1, 101, 201);
LOG:  indexes disabled for DisableIndex(pt2_1_1):
LOG:  indexes disabled for DisableIndex(pt2_1_2):
LOG:  indexes disabled for DisableIndex(pt2_1_3):
LOG:  indexes disabled for DisableIndex(pt2_1_4):
LOG:  indexes disabled for DisableIndex(pt2_1_5):
LOG:  indexes disabled for DisableIndex(pt2_1_6):
LOG:  pg_hint_plan:
used hint:
not used hint:
DisableIndex(pt2 non_existent)
duplication hint:
error hint:
 
                           QUERY PLAN                            
-----------------------------------------------------------------
 Append
   ->  Seq Scan on pt2_1_1 pt2_1
         Filter: (c1 = ANY ('{1,101,201}'::integer[]))
   ->  Bitmap Heap Scan on pt2_1_2 pt2_2
         Recheck Cond: (c1 = ANY ('{1,101,201}'::integer[]))
         ->  Bitmap Index Scan on pt2_1_2_c1_c2_idx
               Index Cond: (c1 = ANY ('{1,101,201}'::integer[]))
   ->  Seq Scan on pt2_1_3 pt2_3
         Filter: (c1 = ANY ('{1,101,201}'::integer[]))
   ->  Seq Scan on pt2_1_4 pt2_4
         Filter: (c1 = ANY ('{1,101,201}'::integer[]))
   ->  Bitmap Heap Scan on pt2_1_5 pt2_5
         Recheck Cond: (c1 = ANY ('{1,101,201}'::integer[]))
         ->  Bitmap Index Scan on pt2_1_5_c1_c2_idx
               Index Cond: (c1 = ANY ('{1,101,201}'::integer[]))
   ->  Seq Scan on pt2_1_6 pt2_6
         Filter: (c1 = ANY ('{1,101,201}'::integer[]))
(17 rows)
 
-- DisableIndex + Scan method hint
/*+
DisableIndex(t1 t1_i1)
IndexScan(t1 t1_i1)
*/
EXPLAIN (COSTS false) SELECT * FROM disable_index.t1 WHERE c1 = 1;
LOG:  indexes disabled for DisableIndex(t1): t1_i1
LOG:  available indexes for IndexScan(t1):
LOG:  pg_hint_plan:
used hint:
DisableIndex(t1 t1_i1)
not used hint:
IndexScan(t1 t1_i1)
duplication hint:
error hint:
 
           QUERY PLAN           
--------------------------------
 Index Scan using t1_pkey on t1
   Index Cond: (c1 = 1)
(2 rows)
 
/*+
DisableIndex(t1 t1_pkey)
NoIndexScan(t1)
*/
EXPLAIN (COSTS false) SELECT * FROM disable_index.t1 WHERE c1 = 1;
LOG:  indexes disabled for DisableIndex(t1): t1_pkey
LOG:  pg_hint_plan:
used hint:
NoIndexScan(t1)
DisableIndex(t1 t1_pkey)
not used hint:
duplication hint:
error hint:
 
            QUERY PLAN            
----------------------------------
 Bitmap Heap Scan on t1
   Recheck Cond: (c1 = 1)
   ->  Bitmap Index Scan on t1_i1
         Index Cond: (c1 = 1)
(4 rows)
 
-- Regular tables
/*+ DisableIndex(t1 t1_i1) */
EXPLAIN (COSTS false) SELECT * FROM disable_index.t1 WHERE c1 = 1;
LOG:  indexes disabled for DisableIndex(t1): t1_i1
LOG:  pg_hint_plan:
used hint:
DisableIndex(t1 t1_i1)
not used hint:
duplication hint:
error hint:
 
           QUERY PLAN           
--------------------------------
 Index Scan using t1_pkey on t1
   Index Cond: (c1 = 1)
(2 rows)
 
/*+ DisableIndex(t1 t1_pkey) */
EXPLAIN (COSTS false) SELECT * FROM disable_index.t1 WHERE c1 = 1;
LOG:  indexes disabled for DisableIndex(t1): t1_pkey
LOG:  pg_hint_plan:
used hint:
DisableIndex(t1 t1_pkey)
not used hint:
duplication hint:
error hint:
 
            QUERY PLAN            
----------------------------------
 Bitmap Heap Scan on t1
   Recheck Cond: (c1 = 1)
   ->  Bitmap Index Scan on t1_i1
         Index Cond: (c1 = 1)
(4 rows)
 
/*+ DisableIndex(t1 t1_pkey t1_i1) */
EXPLAIN (COSTS false) SELECT * FROM disable_index.t1 WHERE c1 = 1;
LOG:  indexes disabled for DisableIndex(t1): t1_i1 t1_pkey
LOG:  pg_hint_plan:
used hint:
DisableIndex(t1 t1_pkey t1_i1)
not used hint:
duplication hint:
error hint:
 
     QUERY PLAN     
--------------------
 Seq Scan on t1
   Filter: (c1 = 1)
(2 rows)
 
-- Partitioning
SET enable_bitmapscan = OFF;
SET enable_seqscan = OFF;
-- Disable parallelism.
SET max_parallel_workers_per_gather = 0;
-- Push down the parent hint
/*+ DisableIndex(pt2 pt2_c1_idx) */
EXPLAIN (COSTS OFF) SELECT * FROM disable_index.pt2 WHERE c1 IN (1, 101, 201);
LOG:  indexes disabled for DisableIndex(pt2_1_1): pt2_1_1_c1_c2_idx
LOG:  indexes disabled for DisableIndex(pt2_1_2): pt2_1_2_c1_c2_idx
LOG:  indexes disabled for DisableIndex(pt2_1_3): pt2_1_3_c1_c2_idx
LOG:  indexes disabled for DisableIndex(pt2_1_4): pt2_1_4_c1_c2_idx
LOG:  indexes disabled for DisableIndex(pt2_1_5): pt2_1_5_c1_c2_idx
LOG:  indexes disabled for DisableIndex(pt2_1_6): pt2_1_6_c1_c2_idx
LOG:  pg_hint_plan:
used hint:
DisableIndex(pt2 pt2_c1_idx)
not used hint:
duplication hint:
error hint:
 
                        QUERY PLAN                         
-----------------------------------------------------------
 Append
   ->  Index Scan using pt2_1_1_pkey on pt2_1_1 pt2_1
         Index Cond: (c1 = ANY ('{1,101,201}'::integer[]))
   ->  Index Scan using pt2_1_2_pkey on pt2_1_2 pt2_2
         Index Cond: (c1 = ANY ('{1,101,201}'::integer[]))
   ->  Index Scan using pt2_1_3_pkey on pt2_1_3 pt2_3
         Index Cond: (c1 = ANY ('{1,101,201}'::integer[]))
   ->  Index Scan using pt2_1_4_pkey on pt2_1_4 pt2_4
         Index Cond: (c1 = ANY ('{1,101,201}'::integer[]))
   ->  Index Scan using pt2_1_5_pkey on pt2_1_5 pt2_5
         Index Cond: (c1 = ANY ('{1,101,201}'::integer[]))
   ->  Index Scan using pt2_1_6_pkey on pt2_1_6 pt2_6
         Index Cond: (c1 = ANY ('{1,101,201}'::integer[]))
(13 rows)
 
/*+ DisableIndex(p3 p3_c1_idx) */
EXPLAIN (COSTS OFF) SELECT * FROM disable_index.p3 WHERE c1 IN (1, 101, 201);
LOG:  indexes disabled for DisableIndex(p3): p3_c1_idx
LOG:  indexes disabled for DisableIndex(p3_1_100): p3_1_100_c1_idx
LOG:  indexes disabled for DisableIndex(p3_100_200): p3_100_200_c1_idx
LOG:  indexes disabled for DisableIndex(p3_200_300): p3_200_300_c1_idx
LOG:  pg_hint_plan:
used hint:
DisableIndex(p3 p3_c1_idx)
not used hint:
duplication hint:
error hint:
 
                         QUERY PLAN                         
------------------------------------------------------------
 Append
   ->  Index Scan using p3_pkey on p3 p3_1
         Index Cond: (c1 = ANY ('{1,101,201}'::integer[]))
   ->  Index Scan using p3_1_100_c1_c2_idx on p3_1_100 p3_2
         Index Cond: (c1 = ANY ('{1,101,201}'::integer[]))
   ->  Seq Scan on p3_100_200 p3_3
         Disabled: true
         Filter: (c1 = ANY ('{1,101,201}'::integer[]))
   ->  Seq Scan on p3_200_300 p3_4
         Disabled: true
         Filter: (c1 = ANY ('{1,101,201}'::integer[]))
(11 rows)
 
-- Specific partition
/*+
DisableIndex(pt2_1_1 pt2_1_1_c1_c2_idx)
DisableIndex(pt2_1_6 pt2_1_6_c1_c2_idx)
*/
EXPLAIN (COSTS OFF) SELECT * FROM disable_index.pt2 WHERE c1 IN (1, 101, 201);
LOG:  indexes disabled for DisableIndex(pt2_1_1): pt2_1_1_c1_c2_idx
LOG:  indexes disabled for DisableIndex(pt2_1_6): pt2_1_6_c1_c2_idx
LOG:  pg_hint_plan:
used hint:
DisableIndex(pt2_1_1 pt2_1_1_c1_c2_idx)
DisableIndex(pt2_1_6 pt2_1_6_c1_c2_idx)
not used hint:
duplication hint:
error hint:
 
                        QUERY PLAN                         
-----------------------------------------------------------
 Append
   ->  Index Scan using pt2_1_1_pkey on pt2_1_1 pt2_1
         Index Cond: (c1 = ANY ('{1,101,201}'::integer[]))
   ->  Index Scan using pt2_1_2_c1_c2_idx on pt2_1_2 pt2_2
         Index Cond: (c1 = ANY ('{1,101,201}'::integer[]))
   ->  Index Scan using pt2_1_3_c1_c2_idx on pt2_1_3 pt2_3
         Index Cond: (c1 = ANY ('{1,101,201}'::integer[]))
   ->  Index Scan using pt2_1_4_c1_c2_idx on pt2_1_4 pt2_4
         Index Cond: (c1 = ANY ('{1,101,201}'::integer[]))
   ->  Index Scan using pt2_1_5_c1_c2_idx on pt2_1_5 pt2_5
         Index Cond: (c1 = ANY ('{1,101,201}'::integer[]))
   ->  Index Scan using pt2_1_6_pkey on pt2_1_6 pt2_6
         Index Cond: (c1 = ANY ('{1,101,201}'::integer[]))
(13 rows)
 
/*+
DisableIndex(p3_1_100 p3_1_100_c1_c2_idx)
*/
EXPLAIN (COSTS OFF) SELECT * FROM disable_index.p3 WHERE c1 IN (1, 101, 201);
LOG:  indexes disabled for DisableIndex(p3_1_100): p3_1_100_c1_c2_idx
LOG:  pg_hint_plan:
used hint:
DisableIndex(p3_1_100 p3_1_100_c1_c2_idx)
not used hint:
duplication hint:
error hint:
 
                         QUERY PLAN                          
-------------------------------------------------------------
 Append
   ->  Index Scan using p3_c1_idx on p3 p3_1
         Index Cond: (c1 = ANY ('{1,101,201}'::integer[]))
   ->  Index Scan using p3_1_100_c1_idx on p3_1_100 p3_2
         Index Cond: (c1 = ANY ('{1,101,201}'::integer[]))
   ->  Index Scan using p3_100_200_c1_idx on p3_100_200 p3_3
         Index Cond: (c1 = ANY ('{1,101,201}'::integer[]))
   ->  Index Scan using p3_200_300_c1_idx on p3_200_300 p3_4
         Index Cond: (c1 = ANY ('{1,101,201}'::integer[]))
(9 rows)
 
RESET enable_bitmapscan;
RESET enable_seqscan;
RESET max_parallel_workers_per_gather;
-- Cleanup
DROP SCHEMA disable_index CASCADE;
NOTICE:  drop cascades to 6 other objects
DETAIL:  drop cascades to table disable_index.t1
drop cascades to table disable_index.p3
drop cascades to table disable_index.p3_1_100
drop cascades to table disable_index.p3_100_200
drop cascades to table disable_index.p3_200_300
drop cascades to table disable_index.pt2