2021-02-03 16:16:30 +00:00
|
|
|
-- hypothetical indexes using INCLUDE keyword, pg11+
|
|
|
|
|
|
|
|
|
|
-- Remove all the hypothetical indexes if any
|
|
|
|
|
SELECT hypopg_reset();
|
|
|
|
|
|
|
|
|
|
-- Make sure stats and visibility map are up to date
|
|
|
|
|
VACUUM ANALYZE hypo;
|
|
|
|
|
|
|
|
|
|
-- Should not use hypothetical index
|
|
|
|
|
|
|
|
|
|
-- Create normal index
|
2021-02-28 09:02:49 +00:00
|
|
|
SELECT COUNT(*) AS NB
|
|
|
|
|
FROM hypopg_create_index('CREATE INDEX ON hypo (id)');
|
2021-02-03 16:16:30 +00:00
|
|
|
|
|
|
|
|
-- Should use hypothetical index using a regular Index Scan
|
|
|
|
|
SELECT COUNT(*) FROM do_explain('SELECT val FROM hypo WHERE id = 1') e
|
|
|
|
|
WHERE e ~ 'Index Scan.*<\d+>btree_hypo.*';
|
|
|
|
|
|
|
|
|
|
-- Remove all the hypothetical indexes
|
|
|
|
|
SELECT hypopg_reset();
|
|
|
|
|
|
|
|
|
|
-- Create INCLUDE index
|
2021-02-28 09:02:49 +00:00
|
|
|
SELECT COUNT(*) AS NB
|
2024-04-17 15:11:23 +00:00
|
|
|
FROM hypopg_create_index('CREATE INDEX ON hypo (id) INCLUDE (val, "Id2")');
|
2021-02-03 16:16:30 +00:00
|
|
|
|
|
|
|
|
-- Should use hypothetical index using an Index Only Scan
|
|
|
|
|
SELECT COUNT(*) FROM do_explain('SELECT val FROM hypo WHERE id = 1') e
|
|
|
|
|
WHERE e ~ 'Index Only Scan.*<\d+>btree_hypo.*';
|
|
|
|
|
|
|
|
|
|
-- Deparse the index DDL
|
|
|
|
|
SELECT hypopg_get_indexdef(indexrelid) FROM hypopg();
|