hypopg
Hypothetical indexes for PostgreSQL
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
hypopg | 1.4.2 | FEAT | PostgreSQL | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 2790 | hypopg | No | Yes | No | Yes | No | Yes | - |
| Related | index_advisor pg_qualstats powa pg_hint_plan auto_explain pg_stat_statements btree_gin pg_show_plans |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PGDG | 1.4.2 | 1817161514 | hypopg | - |
| RPM | PGDG | 1.4.2 | 1817161514 | hypopg_$v | - |
| DEB | PGDG | 1.4.2 | 1817161514 | postgresql-$v-hypopg | - |
Install
You can install hypopg directly. First, make sure the PGDG repository is added and enabled:
pig repo add pgdg -u # Add PGDG repo and update cache
Install the extension using pig or apt/yum/dnf:
pig install hypopg; # Install for current active PG version
pig ext install -y hypopg -v 18 # PG 18
pig ext install -y hypopg -v 17 # PG 17
pig ext install -y hypopg -v 16 # PG 16
pig ext install -y hypopg -v 15 # PG 15
pig ext install -y hypopg -v 14 # PG 14
dnf install -y hypopg_18 # PG 18
dnf install -y hypopg_17 # PG 17
dnf install -y hypopg_16 # PG 16
dnf install -y hypopg_15 # PG 15
dnf install -y hypopg_14 # PG 14
apt install -y postgresql-18-hypopg # PG 18
apt install -y postgresql-17-hypopg # PG 17
apt install -y postgresql-16-hypopg # PG 16
apt install -y postgresql-15-hypopg # PG 15
apt install -y postgresql-14-hypopg # PG 14
Create Extension:
CREATE EXTENSION hypopg;
Usage
HypoPG lets you create hypothetical (virtual) indexes that exist only in the current session and are considered by EXPLAIN (without ANALYZE) for query planning. This enables testing the impact of indexes without the cost of actually creating them.
Functions
| Function | Description |
|---|---|
hypopg_create_index(query text) | Create a hypothetical index using CREATE INDEX syntax |
hypopg_list_indexes() | List all hypothetical indexes in the session |
hypopg_drop_index(oid) | Drop a specific hypothetical index by OID |
hypopg_reset() | Drop all hypothetical indexes |
hypopg() | Return hypothetical indexes in pg_index-like format |
Workflow
Create a test table and check the baseline plan:
CREATE TABLE hypo AS SELECT id, 'line ' || id AS val FROM generate_series(1, 10000) id;
ANALYZE hypo;
EXPLAIN SELECT * FROM hypo WHERE id = 1;
-- Seq Scan on hypo (cost=0.00..170.00 rows=1 width=15)
Create a hypothetical index:
SELECT * FROM hypopg_create_index('CREATE INDEX ON hypo (id)');
-- indexrelid | indexname
-- ------------+----------------------
-- 13543 | <13543>btree_hypo_id
Check the plan with the hypothetical index:
EXPLAIN SELECT * FROM hypo WHERE id = 1;
-- Index Scan using <13543>btree_hypo_id on hypo (cost=0.04..8.06 rows=1 width=15)
List and manage hypothetical indexes:
SELECT * FROM hypopg_list_indexes();
SELECT * FROM hypopg_drop_index(13543);
SELECT * FROM hypopg_reset();
Limitations
- Only
EXPLAINwithoutANALYZEwill consider hypothetical indexes - Hypothetical indexes exist only in the current backend session
- Other concurrent connections are not affected
- Index names and some CREATE INDEX options are ignored
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.