-- hypothetical indexes using INCLUDE keyword, pg11+ -- Remove all the hypothetical indexes if any SELECT hypopg_reset(); hypopg_reset -------------- (1 row) -- Make sure stats and visibility map are up to date VACUUM ANALYZE hypo; -- Should not use hypothetical index -- Create normal index SELECT hypopg_create_index('CREATE INDEX ON hypo (id)'); hypopg_create_index ------------------------------ (13719,<13719>btree_hypo_id) (1 row) -- 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.*'; count ------- 1 (1 row) -- Remove all the hypothetical indexes SELECT hypopg_reset(); hypopg_reset -------------- (1 row) -- Create INCLUDE index SELECT hypopg_create_index('CREATE INDEX ON hypo (id) INCLUDE (val)'); hypopg_create_index ---------------------------------- (13719,<13719>btree_hypo_id_val) (1 row) -- 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.*'; count ------- 1 (1 row) -- Deparse the index DDL SELECT hypopg_get_indexdef(indexrelid) FROM hypopg(); hypopg_get_indexdef ------------------------------------------------------------ CREATE INDEX ON public.hypo USING btree (id) INCLUDE (val) (1 row)