mirror of
https://github.com/postgres/postgres.git
synced 2025-07-26 01:22:12 +03:00
config
contrib
amcheck
auth_delay
auto_explain
basebackup_to_shell
basic_archive
bloom
bool_plperl
btree_gin
btree_gist
data
expected
bit.out
bool.out
bytea.out
cash.out
char.out
char_1.out
cidr.out
date.out
enum.out
float4.out
float8.out
inet.out
init.out
int2.out
int4.out
int8.out
interval.out
macaddr.out
macaddr8.out
not_equal.out
numeric.out
oid.out
partitions.out
text.out
text_1.out
time.out
timestamp.out
timestamptz.out
timetz.out
uuid.out
varbit.out
varchar.out
varchar_1.out
sql
.gitignore
Makefile
btree_bit.c
btree_bool.c
btree_bytea.c
btree_cash.c
btree_date.c
btree_enum.c
btree_float4.c
btree_float8.c
btree_gist--1.0--1.1.sql
btree_gist--1.1--1.2.sql
btree_gist--1.2--1.3.sql
btree_gist--1.2.sql
btree_gist--1.3--1.4.sql
btree_gist--1.4--1.5.sql
btree_gist--1.5--1.6.sql
btree_gist--1.6--1.7.sql
btree_gist.c
btree_gist.control
btree_gist.h
btree_inet.c
btree_int2.c
btree_int4.c
btree_int8.c
btree_interval.c
btree_macaddr.c
btree_macaddr8.c
btree_numeric.c
btree_oid.c
btree_text.c
btree_time.c
btree_ts.c
btree_utils_num.c
btree_utils_num.h
btree_utils_var.c
btree_utils_var.h
btree_uuid.c
meson.build
citext
cube
dblink
dict_int
dict_xsyn
earthdistance
file_fdw
fuzzystrmatch
hstore
hstore_plperl
hstore_plpython
intagg
intarray
isn
jsonb_plperl
jsonb_plpython
lo
ltree
ltree_plpython
oid2name
pageinspect
passwordcheck
pg_buffercache
pg_freespacemap
pg_prewarm
pg_stat_statements
pg_surgery
pg_trgm
pg_visibility
pg_walinspect
pgcrypto
pgrowlocks
pgstattuple
postgres_fdw
seg
sepgsql
spi
sslinfo
start-scripts
tablefunc
tcn
test_decoding
tsm_system_rows
tsm_system_time
unaccent
uuid-ossp
vacuumlo
xml2
Makefile
README
contrib-global.mk
meson.build
doc
src
.cirrus.star
.cirrus.tasks.yml
.cirrus.yml
.dir-locals.el
.editorconfig
.git-blame-ignore-revs
.gitattributes
.gitignore
COPYRIGHT
GNUmakefile.in
HISTORY
Makefile
README.md
aclocal.m4
configure
configure.ac
meson.build
meson_options.txt
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
97 lines
1.5 KiB
Plaintext
97 lines
1.5 KiB
Plaintext
-- bool check
|
|
CREATE TABLE booltmp (a bool);
|
|
INSERT INTO booltmp VALUES (false), (true);
|
|
SET enable_seqscan=on;
|
|
SELECT count(*) FROM booltmp WHERE a < true;
|
|
count
|
|
-------
|
|
1
|
|
(1 row)
|
|
|
|
SELECT count(*) FROM booltmp WHERE a <= true;
|
|
count
|
|
-------
|
|
2
|
|
(1 row)
|
|
|
|
SELECT count(*) FROM booltmp WHERE a = true;
|
|
count
|
|
-------
|
|
1
|
|
(1 row)
|
|
|
|
SELECT count(*) FROM booltmp WHERE a >= true;
|
|
count
|
|
-------
|
|
1
|
|
(1 row)
|
|
|
|
SELECT count(*) FROM booltmp WHERE a > true;
|
|
count
|
|
-------
|
|
0
|
|
(1 row)
|
|
|
|
CREATE INDEX boolidx ON booltmp USING gist ( a );
|
|
SET enable_seqscan=off;
|
|
SELECT count(*) FROM booltmp WHERE a < true;
|
|
count
|
|
-------
|
|
1
|
|
(1 row)
|
|
|
|
SELECT count(*) FROM booltmp WHERE a <= true;
|
|
count
|
|
-------
|
|
2
|
|
(1 row)
|
|
|
|
SELECT count(*) FROM booltmp WHERE a = true;
|
|
count
|
|
-------
|
|
1
|
|
(1 row)
|
|
|
|
SELECT count(*) FROM booltmp WHERE a >= true;
|
|
count
|
|
-------
|
|
1
|
|
(1 row)
|
|
|
|
SELECT count(*) FROM booltmp WHERE a > true;
|
|
count
|
|
-------
|
|
0
|
|
(1 row)
|
|
|
|
-- Test index-only scans
|
|
SET enable_bitmapscan=off;
|
|
EXPLAIN (COSTS OFF)
|
|
SELECT * FROM booltmp WHERE a;
|
|
QUERY PLAN
|
|
------------------------------------------
|
|
Index Only Scan using boolidx on booltmp
|
|
Index Cond: (a = true)
|
|
(2 rows)
|
|
|
|
SELECT * FROM booltmp WHERE a;
|
|
a
|
|
---
|
|
t
|
|
(1 row)
|
|
|
|
EXPLAIN (COSTS OFF)
|
|
SELECT * FROM booltmp WHERE NOT a;
|
|
QUERY PLAN
|
|
------------------------------------------
|
|
Index Only Scan using boolidx on booltmp
|
|
Index Cond: (a = false)
|
|
(2 rows)
|
|
|
|
SELECT * FROM booltmp WHERE NOT a;
|
|
a
|
|
---
|
|
f
|
|
(1 row)
|
|
|