0003-PATCH-3-5-Extend-expected-output-for-bitmapops-test.patch
text/x-patch
Filename: 0003-PATCH-3-5-Extend-expected-output-for-bitmapops-test.patch
Type: text/x-patch
Part: 2
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch 0003
Subject: [PATCH 3/5] Extend expected output for bitmapops test
| File | + | − |
|---|---|---|
| src/test/regress/expected/bitmapops.out | 115 | 0 |
From a3964ca366b5621cf3ea34d7c45584e254a771ee Mon Sep 17 00:00:00 2001
From: Jim Vanns <james.vanns@gmail.com>
Date: Sun, 1 Mar 2026 11:10:04 +0000
Subject: [PATCH 3/5] [PATCH 3/5] Extend expected output for bitmapops test
We now include the expected output from the new SAOP
BitmapOr optimisation.
diff --git a/src/test/regress/expected/bitmapops.out b/src/test/regress/expected/bitmapops.out
index 64068e0469c..2d632edfab1 100644
--- a/src/test/regress/expected/bitmapops.out
+++ b/src/test/regress/expected/bitmapops.out
@@ -46,3 +46,118 @@ SELECT count(*) FROM bmscantest WHERE a = 1 OR b = 1;
-- clean up
DROP TABLE bmscantest;
+-- Test ScalarArrayOpExpr (SAOP) for partial indexes
+-- Generate enough data that we can test the use of an index
+CREATE TABLE ipairs(
+ key INT,
+ value INT
+)
+WITH (autovacuum_enabled = false);
+-- Install the partial index on these values
+CREATE INDEX ipairs_key_idx1 ON ipairs(key) WHERE key = 507;
+CREATE INDEX ipairs_key_idx2 ON ipairs(key) WHERE key = 508;
+CREATE INDEX ipairs_key_idx3 ON ipairs(key) WHERE key = 509;
+CREATE INDEX ipairs_key_idx4 ON ipairs(key) WHERE key <= 508; -- Give planner a choice
+-- Dummy data to surround ours
+INSERT INTO ipairs(key, value)
+SELECT n, -n
+FROM generate_series(1, 1000) AS tmp(n);
+-- Update statistics
+VACUUM (ANALYZE) ipairs;
+-- Our specific test data to force the partial index
+EXPLAIN (ANALYZE, COSTS OFF, BUFFERS OFF, SUMMARY OFF, TIMING OFF)
+UPDATE ipairs
+SET value = 0
+WHERE key IN (507,508,509);
+ QUERY PLAN
+-----------------------------------------------------------------------------------
+ Update on ipairs (actual rows=0.00 loops=1)
+ -> Bitmap Heap Scan on ipairs (actual rows=3.00 loops=1)
+ Recheck Cond: ((key = 507) OR (key = 508) OR (key = 509))
+ Heap Blocks: exact=1
+ -> BitmapOr (actual rows=0.00 loops=1)
+ -> Bitmap Index Scan on ipairs_key_idx1 (actual rows=1.00 loops=1)
+ Index Cond: (key = 507)
+ Index Searches: 1
+ -> Bitmap Index Scan on ipairs_key_idx2 (actual rows=1.00 loops=1)
+ Index Cond: (key = 508)
+ Index Searches: 1
+ -> Bitmap Index Scan on ipairs_key_idx3 (actual rows=1.00 loops=1)
+ Index Cond: (key = 509)
+ Index Searches: 1
+(14 rows)
+
+-- We want ensure that an index use is always attempted - just for the test
+SET enable_seqscan=false;
+-- Variant 1 (works without the SAOP optimiser patch)
+EXPLAIN (COSTS OFF)
+SELECT value = 0
+FROM ipairs
+WHERE
+ key = 507 OR
+ key = 508 OR
+ key = 509;
+ QUERY PLAN
+-------------------------------------------------------------
+ Bitmap Heap Scan on ipairs
+ Recheck Cond: ((key = 507) OR (key = 508) OR (key = 509))
+ -> BitmapOr
+ -> Bitmap Index Scan on ipairs_key_idx1
+ Index Cond: (key = 507)
+ -> Bitmap Index Scan on ipairs_key_idx2
+ Index Cond: (key = 508)
+ -> Bitmap Index Scan on ipairs_key_idx3
+ Index Cond: (key = 509)
+(9 rows)
+
+-- Variant 2 (works only with the SAOP optimiser patch)
+EXPLAIN (COSTS OFF)
+SELECT value = 0
+FROM ipairs
+WHERE key IN (507, 508, 509);
+ QUERY PLAN
+-------------------------------------------------------------
+ Bitmap Heap Scan on ipairs
+ Recheck Cond: ((key = 507) OR (key = 508) OR (key = 509))
+ -> BitmapOr
+ -> Bitmap Index Scan on ipairs_key_idx1
+ Index Cond: (key = 507)
+ -> Bitmap Index Scan on ipairs_key_idx2
+ Index Cond: (key = 508)
+ -> Bitmap Index Scan on ipairs_key_idx3
+ Index Cond: (key = 509)
+(9 rows)
+
+-- Variant 3 (as above)
+EXPLAIN (COSTS OFF)
+SELECT value = 0
+FROM ipairs
+WHERE key = ANY('{507,508,509}'::INT[]);
+ QUERY PLAN
+-------------------------------------------------------------
+ Bitmap Heap Scan on ipairs
+ Recheck Cond: ((key = 507) OR (key = 508) OR (key = 509))
+ -> BitmapOr
+ -> Bitmap Index Scan on ipairs_key_idx1
+ Index Cond: (key = 507)
+ -> Bitmap Index Scan on ipairs_key_idx2
+ Index Cond: (key = 508)
+ -> Bitmap Index Scan on ipairs_key_idx3
+ Index Cond: (key = 509)
+(9 rows)
+
+-- Variant 5 (should use only ipairs_key_idx4)
+EXPLAIN (COSTS OFF)
+SELECT value = 0
+FROM ipairs
+WHERE key < ANY('{508}'::INT[]);
+ QUERY PLAN
+------------------------------------------------------
+ Bitmap Heap Scan on ipairs
+ Recheck Cond: (key < ANY ('{508}'::integer[]))
+ -> Bitmap Index Scan on ipairs_key_idx4
+ Index Cond: (key < ANY ('{508}'::integer[]))
+(4 rows)
+
+-- Clean up
+DROP TABLE ipairs;
--
2.43.0