3 -- test retrieval of min/max keys for each index
15 WHERE b.seqno >= 9999;
31 WHERE b.seqno < '1'::name;
39 WHERE b.seqno >= '9999'::name;
47 WHERE b.seqno = '4500'::name;
55 WHERE b.seqno < '1'::text;
63 WHERE b.seqno >= '9999'::text;
71 WHERE b.seqno = '4500'::text;
79 WHERE b.seqno < '1'::float8;
87 WHERE b.seqno >= '9999'::float8;
95 WHERE b.seqno = '4500'::float8;
102 -- Check correct optimization of LIKE (special index operator support)
103 -- for both indexscan and bitmapscan cases
105 set enable_seqscan to false;
106 set enable_indexscan to true;
107 set enable_bitmapscan to false;
109 select proname from pg_proc where proname like E'RI\\_FKey%del' order by 1;
111 ------------------------------------------------------------------------------
112 Index Only Scan using pg_proc_proname_args_nsp_index on pg_proc
113 Index Cond: ((proname >= 'RI_FKey'::text) AND (proname < 'RI_FKez'::text))
114 Filter: (proname ~~ 'RI\_FKey%del'::text)
117 select proname from pg_proc where proname like E'RI\\_FKey%del' order by 1;
119 ------------------------
123 RI_FKey_setdefault_del
128 select proname from pg_proc where proname ilike '00%foo' order by 1;
130 --------------------------------------------------------------------
131 Index Only Scan using pg_proc_proname_args_nsp_index on pg_proc
132 Index Cond: ((proname >= '00'::text) AND (proname < '01'::text))
133 Filter: (proname ~~* '00%foo'::text)
136 select proname from pg_proc where proname ilike '00%foo' order by 1;
142 select proname from pg_proc where proname ilike 'ri%foo' order by 1;
144 -----------------------------------------------------------------
145 Index Only Scan using pg_proc_proname_args_nsp_index on pg_proc
146 Filter: (proname ~~* 'ri%foo'::text)
149 set enable_indexscan to false;
150 set enable_bitmapscan to true;
152 select proname from pg_proc where proname like E'RI\\_FKey%del' order by 1;
154 ------------------------------------------------------------------------------------------
157 -> Bitmap Heap Scan on pg_proc
158 Filter: (proname ~~ 'RI\_FKey%del'::text)
159 -> Bitmap Index Scan on pg_proc_proname_args_nsp_index
160 Index Cond: ((proname >= 'RI_FKey'::text) AND (proname < 'RI_FKez'::text))
163 select proname from pg_proc where proname like E'RI\\_FKey%del' order by 1;
165 ------------------------
169 RI_FKey_setdefault_del
174 select proname from pg_proc where proname ilike '00%foo' order by 1;
176 --------------------------------------------------------------------------------
179 -> Bitmap Heap Scan on pg_proc
180 Filter: (proname ~~* '00%foo'::text)
181 -> Bitmap Index Scan on pg_proc_proname_args_nsp_index
182 Index Cond: ((proname >= '00'::text) AND (proname < '01'::text))
185 select proname from pg_proc where proname ilike '00%foo' order by 1;
191 select proname from pg_proc where proname ilike 'ri%foo' order by 1;
193 -----------------------------------------------------------------
194 Index Only Scan using pg_proc_proname_args_nsp_index on pg_proc
195 Filter: (proname ~~* 'ri%foo'::text)
198 reset enable_seqscan;
199 reset enable_indexscan;
200 reset enable_bitmapscan;
201 -- Also check LIKE optimization with binary-compatible cases
202 create temp table btree_bpchar (f1 text collate "C");
203 create index on btree_bpchar(f1 bpchar_ops) WITH (deduplicate_items=on);
204 insert into btree_bpchar values ('foo'), ('fool'), ('bar'), ('quux');
205 -- doesn't match index:
207 select * from btree_bpchar where f1 like 'foo';
209 -------------------------------
210 Seq Scan on btree_bpchar
211 Filter: (f1 ~~ 'foo'::text)
214 select * from btree_bpchar where f1 like 'foo';
221 select * from btree_bpchar where f1 like 'foo%';
223 --------------------------------
224 Seq Scan on btree_bpchar
225 Filter: (f1 ~~ 'foo%'::text)
228 select * from btree_bpchar where f1 like 'foo%';
235 -- these do match the index:
237 select * from btree_bpchar where f1::bpchar like 'foo';
239 ----------------------------------------------------
240 Bitmap Heap Scan on btree_bpchar
241 Filter: ((f1)::bpchar ~~ 'foo'::text)
242 -> Bitmap Index Scan on btree_bpchar_f1_idx
243 Index Cond: ((f1)::bpchar = 'foo'::bpchar)
246 select * from btree_bpchar where f1::bpchar like 'foo';
253 select * from btree_bpchar where f1::bpchar like 'foo%';
255 ------------------------------------------------------------------------------------------
256 Bitmap Heap Scan on btree_bpchar
257 Filter: ((f1)::bpchar ~~ 'foo%'::text)
258 -> Bitmap Index Scan on btree_bpchar_f1_idx
259 Index Cond: (((f1)::bpchar >= 'foo'::bpchar) AND ((f1)::bpchar < 'fop'::bpchar))
262 select * from btree_bpchar where f1::bpchar like 'foo%';
269 -- get test coverage for "single value" deduplication strategy:
270 insert into btree_bpchar select 'foo' from generate_series(1,1500);
272 -- Perform unique checking, with and without the use of deduplication
274 CREATE TABLE dedup_unique_test_table (a int) WITH (autovacuum_enabled=false);
275 CREATE UNIQUE INDEX dedup_unique ON dedup_unique_test_table (a) WITH (deduplicate_items=on);
276 CREATE UNIQUE INDEX plain_unique ON dedup_unique_test_table (a) WITH (deduplicate_items=off);
277 -- Generate enough garbage tuples in index to ensure that even the unique index
278 -- with deduplication enabled has to check multiple leaf pages during unique
279 -- checking (at least with a BLCKSZ of 8192 or less)
282 FOR r IN 1..1350 LOOP
283 DELETE FROM dedup_unique_test_table;
284 INSERT INTO dedup_unique_test_table SELECT 1;
287 -- Exercise the LP_DEAD-bit-set tuple deletion code with a posting list tuple.
288 -- The implementation prefers deleting existing items to merging any duplicate
289 -- tuples into a posting list, so we need an explicit test to make sure we get
290 -- coverage (note that this test also assumes BLCKSZ is 8192 or less):
291 DROP INDEX plain_unique;
292 DELETE FROM dedup_unique_test_table WHERE a = 1;
293 INSERT INTO dedup_unique_test_table SELECT i FROM generate_series(0,450) i;
295 -- Test B-tree fast path (cache rightmost leaf page) optimization.
297 -- First create a tree that's at least three levels deep (i.e. has one level
298 -- between the root and leaf levels). The text inserted is long. It won't be
299 -- TOAST compressed because we use plain storage in the table. Only a few
300 -- index tuples fit on each internal page, allowing us to get a tall tree with
301 -- few pages. (A tall tree is required to trigger caching.)
303 -- The text column must be the leading column in the index, since suffix
304 -- truncation would otherwise truncate tuples on internal pages, leaving us
305 -- with a short tree.
306 create table btree_tall_tbl(id int4, t text);
307 alter table btree_tall_tbl alter COLUMN t set storage plain;
308 create index btree_tall_idx on btree_tall_tbl (t, id) with (fillfactor = 10);
309 insert into btree_tall_tbl select g, repeat('x', 250)
310 from generate_series(1, 130) g;
312 -- Test for multilevel page deletion
314 CREATE TABLE delete_test_table (a bigint, b bigint, c bigint, d bigint);
315 INSERT INTO delete_test_table SELECT i, 1, 2, 3 FROM generate_series(1,80000) i;
316 ALTER TABLE delete_test_table ADD PRIMARY KEY (a,b,c,d);
317 -- Delete most entries, and vacuum, deleting internal pages and creating "fast
319 DELETE FROM delete_test_table WHERE a < 79990;
320 VACUUM delete_test_table;
322 -- Test B-tree insertion with a metapage update (XLOG_BTREE_INSERT_META
323 -- WAL record type). This happens when a "fast root" page is split. This
324 -- also creates coverage for nbtree FSM page recycling.
326 -- The vacuum above should've turned the leaf page into a fast root. We just
327 -- need to insert some rows to cause the fast root page to split.
328 INSERT INTO delete_test_table SELECT i, 1, 2, 3 FROM generate_series(1,1000) i;
329 -- Test unsupported btree opclass parameters
330 create index on btree_tall_tbl (id int4_ops(foo=1));
331 ERROR: operator class int4_ops has no options