mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-08-20 10:53:23 +02:00
The planner has to special-case indexes on boolean columns, because what we need for an indexscan on such a column is a qual of the shape of "boolvar = pseudoconstant". For plain bool constants, previous simplification will have reduced this to "boolvar" or "NOT boolvar", and we have to reverse that if we want to make an indexqual. There is existing code to do so, but it only fires when the index's opfamily is BOOL_BTREE_FAM_OID or BOOL_HASH_FAM_OID. Thus extension AMs, or extension opclasses such as contrib/btree_gin, are out in the cold. The reason for hard-wiring the set of relevant opfamilies was mostly to avoid a catalog lookup in a hot code path. We can improve matters while not taking much of a performance hit by relying on the hard-wired set when the opfamily OID is visibly built-in, and only checking the catalogs when dealing with an extension opfamily. While here, rename IsBooleanOpfamily to IsBuiltinBooleanOpfamily to remind future users of that macro of its limitations. At some point we might want to make indxpath.c's improved version of the test globally accessible, but it's not presently needed elsewhere. Zongliang Quan and Tom Lane Discussion: https://postgr.es/m/f293b91d-1d46-d386-b6bb-4b06ff5c667b@yeah.net
122 lines
2.5 KiB
Plaintext
122 lines
2.5 KiB
Plaintext
set enable_seqscan=off;
|
|
CREATE TABLE test_bool (
|
|
i boolean
|
|
);
|
|
INSERT INTO test_bool VALUES (false),(true),(null);
|
|
CREATE INDEX idx_bool ON test_bool USING gin (i);
|
|
SELECT * FROM test_bool WHERE i<true ORDER BY i;
|
|
i
|
|
---
|
|
f
|
|
(1 row)
|
|
|
|
SELECT * FROM test_bool WHERE i<=true ORDER BY i;
|
|
i
|
|
---
|
|
f
|
|
t
|
|
(2 rows)
|
|
|
|
SELECT * FROM test_bool WHERE i=true ORDER BY i;
|
|
i
|
|
---
|
|
t
|
|
(1 row)
|
|
|
|
SELECT * FROM test_bool WHERE i>=true ORDER BY i;
|
|
i
|
|
---
|
|
t
|
|
(1 row)
|
|
|
|
SELECT * FROM test_bool WHERE i>true ORDER BY i;
|
|
i
|
|
---
|
|
(0 rows)
|
|
|
|
SELECT * FROM test_bool WHERE i<false ORDER BY i;
|
|
i
|
|
---
|
|
(0 rows)
|
|
|
|
SELECT * FROM test_bool WHERE i<=false ORDER BY i;
|
|
i
|
|
---
|
|
f
|
|
(1 row)
|
|
|
|
SELECT * FROM test_bool WHERE i=false ORDER BY i;
|
|
i
|
|
---
|
|
f
|
|
(1 row)
|
|
|
|
SELECT * FROM test_bool WHERE i>=false ORDER BY i;
|
|
i
|
|
---
|
|
f
|
|
t
|
|
(2 rows)
|
|
|
|
SELECT * FROM test_bool WHERE i>false ORDER BY i;
|
|
i
|
|
---
|
|
t
|
|
(1 row)
|
|
|
|
EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i<true ORDER BY i;
|
|
QUERY PLAN
|
|
-------------------------------------------
|
|
Sort
|
|
Sort Key: i
|
|
-> Bitmap Heap Scan on test_bool
|
|
Recheck Cond: (i < true)
|
|
-> Bitmap Index Scan on idx_bool
|
|
Index Cond: (i < true)
|
|
(6 rows)
|
|
|
|
EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i<=true ORDER BY i;
|
|
QUERY PLAN
|
|
-------------------------------------------
|
|
Sort
|
|
Sort Key: i
|
|
-> Bitmap Heap Scan on test_bool
|
|
Recheck Cond: (i <= true)
|
|
-> Bitmap Index Scan on idx_bool
|
|
Index Cond: (i <= true)
|
|
(6 rows)
|
|
|
|
EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i=true ORDER BY i;
|
|
QUERY PLAN
|
|
-------------------------------------------
|
|
Sort
|
|
Sort Key: i
|
|
-> Bitmap Heap Scan on test_bool
|
|
Filter: i
|
|
-> Bitmap Index Scan on idx_bool
|
|
Index Cond: (i = true)
|
|
(6 rows)
|
|
|
|
EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i>=true ORDER BY i;
|
|
QUERY PLAN
|
|
-------------------------------------------
|
|
Sort
|
|
Sort Key: i
|
|
-> Bitmap Heap Scan on test_bool
|
|
Recheck Cond: (i >= true)
|
|
-> Bitmap Index Scan on idx_bool
|
|
Index Cond: (i >= true)
|
|
(6 rows)
|
|
|
|
EXPLAIN (COSTS OFF) SELECT * FROM test_bool WHERE i>true ORDER BY i;
|
|
QUERY PLAN
|
|
-------------------------------------------
|
|
Sort
|
|
Sort Key: i
|
|
-> Bitmap Heap Scan on test_bool
|
|
Recheck Cond: (i > true)
|
|
-> Bitmap Index Scan on idx_bool
|
|
Index Cond: (i > true)
|
|
(6 rows)
|
|
|