mirror of
https://github.com/HypoPG/hypopg
synced 2026-05-24 09:38:21 +00:00
Warn about broken hypothetical BRIN indexes in some minor versions.
Hypothetical BRIN indexes are broken in some minor versions of pg10, pg11 and pg12. Detect those versions and warn users with a useful error message recommending to update their minor versions of postgres. Also add regression tests to make sure that support BRIN hypothetical indexes doesn't get broken again.
This commit is contained in:
parent
e7022704db
commit
723adb4bb9
4 changed files with 69 additions and 0 deletions
3
Makefile
3
Makefile
|
|
@ -37,6 +37,9 @@ DATA = $(wildcard *--*.sql)
|
|||
PGXS := $(shell $(PG_CONFIG) --pgxs)
|
||||
include $(PGXS)
|
||||
|
||||
ifneq ($(MAJORVERSION),$(filter $(MAJORVERSION), 9.2 9.3 9.4))
|
||||
REGRESS += hypo_brin
|
||||
endif
|
||||
ifeq ($(MAJORVERSION),$(filter $(MAJORVERSION),9.2 9.3 9.4 9.5 9.6))
|
||||
REGRESS += hypo_no_table
|
||||
else
|
||||
|
|
|
|||
21
expected/hypo_brin.out
Normal file
21
expected/hypo_brin.out
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
-- Hypothetical BRIN index tests
|
||||
CREATE TABLE hypo_brin (id integer);
|
||||
INSERT INTO hypo_brin SELECT generate_series(1, 10000);
|
||||
ANALYZE hypo_brin;
|
||||
SELECT COUNT(*) AS nb
|
||||
FROM public.hypopg_create_index('CREATE INDEX ON hypo_brin USING brin (id);');
|
||||
nb
|
||||
----
|
||||
1
|
||||
(1 row)
|
||||
|
||||
-- Should use hypothetical index
|
||||
SET enable_seqscan = 0;
|
||||
SELECT COUNT(*) FROM do_explain('SELECT * FROM hypo_brin WHERE id = 1') e
|
||||
WHERE e ~ 'Bitmap Index Scan on <\d+>brin_hypo_brin.*';
|
||||
count
|
||||
-------
|
||||
1
|
||||
(1 row)
|
||||
|
||||
DROP TABLE hypo_brin;
|
||||
|
|
@ -339,6 +339,33 @@ hypo_index_store_parsetree(IndexStmt *node, const char *queryString)
|
|||
ListCell *lc;
|
||||
int attn;
|
||||
|
||||
/*
|
||||
* Support for hypothetical BRIN indexes is broken in some minor versions
|
||||
* of pg10, pg11 and pg12. For simplicity, check PG_VERSION_NUM rather
|
||||
* than the real instance version, which should should be right most of the
|
||||
* time. When it's not, the only effect is to have a less user-friendly
|
||||
* error message.
|
||||
*/
|
||||
#if ((PG_VERSION_NUM >= 100000 && PG_VERSION_NUM < 100012) || \
|
||||
(PG_VERSION_NUM >= 110000 && PG_VERSION_NUM < 110007) || \
|
||||
(PG_VERSION_NUM >= 120000 && PG_VERSION_NUM < 120002))
|
||||
if (get_am_oid(node->accessMethod, true) == BRIN_AM_OID)
|
||||
{
|
||||
elog(ERROR, "hypopg: BRIN hypothetical indexes are only supported"
|
||||
" with PostgreSQL "
|
||||
#if PG_VERSION_NUM >= 120000
|
||||
"12.2"
|
||||
#else
|
||||
#if PG_VERSION_NUM >= 110000
|
||||
"11.7"
|
||||
#else
|
||||
"10.12"
|
||||
#endif /* pg 11 */
|
||||
#endif /* pg 12 */
|
||||
" and later.");
|
||||
}
|
||||
#endif
|
||||
|
||||
#if PG_VERSION_NUM < 100000
|
||||
relid = RangeVarGetRelid(node->relation, AccessShareLock, false);
|
||||
#else
|
||||
|
|
|
|||
18
test/sql/hypo_brin.sql
Normal file
18
test/sql/hypo_brin.sql
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
-- Hypothetical BRIN index tests
|
||||
|
||||
CREATE TABLE hypo_brin (id integer);
|
||||
|
||||
INSERT INTO hypo_brin SELECT generate_series(1, 10000);
|
||||
|
||||
ANALYZE hypo_brin;
|
||||
|
||||
SELECT COUNT(*) AS nb
|
||||
FROM public.hypopg_create_index('CREATE INDEX ON hypo_brin USING brin (id);');
|
||||
|
||||
|
||||
-- Should use hypothetical index
|
||||
SET enable_seqscan = 0;
|
||||
SELECT COUNT(*) FROM do_explain('SELECT * FROM hypo_brin WHERE id = 1') e
|
||||
WHERE e ~ 'Bitmap Index Scan on <\d+>brin_hypo_brin.*';
|
||||
|
||||
DROP TABLE hypo_brin;
|
||||
Loading…
Reference in a new issue