Hypothetical Indexes for PostgreSQL
Find a file
2019-04-08 23:35:44 +02:00
debian Version 1.1.2 2018-05-30 14:38:23 +02:00
docs Fix typo in documentation. 2018-12-04 09:43:03 +01:00
expected Check for (hypo) constraint compatibility with (hypo) partitioning 2018-12-09 11:25:53 +01:00
import Split imported code in multiple files in a dedicated directory 2019-04-08 23:35:44 +02:00
include Split imported code in multiple files in a dedicated directory 2019-04-08 23:35:44 +02:00
test/sql Check for (hypo) constraint compatibility with (hypo) partitioning 2018-12-09 11:25:53 +01:00
.gitignore Add some basic regression test. 2015-07-11 10:28:34 +02:00
CHANGELOG.md Add changelog for upcoming version 2.0.0 2018-12-04 09:10:37 +01:00
CONTRIBUTORS.md Use original postgresql license, thanks to Christoph Berg for noticing. 2018-03-26 15:33:31 +02:00
hypopg--1.1.2.sql Start working on version 1.1.2 2018-05-28 03:51:15 +02:00
hypopg--2.0.0beta.sql Stamp 2.0.0beta 2018-12-11 05:08:27 +01:00
hypopg.c Only use set_rel_pathlist_hook for pg10. 2018-11-24 11:26:54 +01:00
hypopg.control Stamp 2.0.0beta 2018-12-11 05:08:27 +01:00
hypopg_analyze.c Fix hypo_get_partition_constraints to follow upstream behavior. 2018-11-24 11:32:21 +01:00
hypopg_index.c Split imported code in multiple files in a dedicated directory 2019-04-08 23:35:44 +02:00
hypopg_table.c Check for (hypo) constraint compatibility with (hypo) partitioning 2018-12-09 11:25:53 +01:00
LICENSE Use original postgresql license, thanks to Christoph Berg for noticing. 2018-03-26 15:33:31 +02:00
Makefile Split imported code in multiple files in a dedicated directory 2019-04-08 23:35:44 +02:00
META.json Change all references to point to new upstream 2018-02-23 22:00:54 +01:00
README.md Mention the documentation in the main README file. 2018-03-24 14:52:23 +01:00
TODO.md Add a hypopg_get_indexdef(oid) function 2016-11-16 23:49:27 +01:00
typedefs.list Import and tweak typedefs.list, needed for pgindent. 2015-06-23 23:54:45 +02:00

HypoPG

HypoPG is a PostgreSQL extension adding support for hypothetical indexes.

An hypothetical, or virtual, index is an index that doesn't really exists, and thus doesn't cost CPU, disk or any resource to create. They're useful to know if specific indexes can increase performance for problematic queries, since you can know if PostgreSQL will use these indexes or not without having to spend resources to create them.

For more thorough informations, pease consult the oficial documentation.

For other general informations, you can also consult this blog post.

Installation

  • Compatible with PostgreSQL 9.2 and above
  • Needs PostgreSQL header files
  • decompress the tarball
  • sudo make install
  • In every needed database: CREATE EXTENSION hypopg;

Usage

NOTE: The hypothetical indexes are contained in a single backend. Therefore, if you add multiple hypothetical indexes, concurrent connexions doing EXPLAIN won't be bothered by your hypothetical indexes.

Assuming a simple test case:

rjuju=# CREATE TABLE hypo AS SELECT id, 'line ' || id AS val FROM generate_series(1,10000) id;
rjuju=# EXPLAIN SELECT * FROM hypo WHERE id = 1;
                      QUERY PLAN
-------------------------------------------------------
 Seq Scan on hypo  (cost=0.00..180.00 rows=1 width=13)
   Filter: (id = 1)
(2 rows)

The easiest way to create an hypothetical index is to use the hypopg_create_index functions with a regular CREATE INDEX statement as arg.

For instance:

rjuju=# SELECT * FROM hypopg_create_index('CREATE INDEX ON hypo (id)');

NOTE: Some information of the CREATE INDEX statement will be ignored, such as the index name if provided. Some of ignored informations will be handled in future release.

You can check the available hypothetical indexes in your own backend:

rjuju=# SELECT * FROM hypopg_list_indexes();
 indexrelid |                 indexname                 | nspname | relname | amname
 -----------+-------------------------------------------+---------+---------+--------
     205101 | <41072>btree_hypo_id                      | public  | hypo    | btree

If you need more technical informations on the hypothetical indexes, the hypopg() function will return the hypothetical indexes in a similar way as pg_index system catalog.

And now, let's see if your previous EXPLAIN statement would use such an index:

rjuju=# EXPLAIN SELECT * FROM hypo WHERE id = 1;
                                     QUERY PLAN
------------------------------------------------------------------------------------
 Index Scan using <41072>hypo_btree_hypo_id on hypo  (cost=0.29..8.30 rows=1 width=13)
   Index Cond: (id = 1)
(2 rows)

Of course, only EXPLAIN without analyze will use hypothetical indexes:

rjuju=# EXPLAIN ANALYZE SELECT * FROM hypo WHERE id = 1;
                                           QUERY PLAN
-------------------------------------------------------------------------------------------------
 Seq Scan on hypo  (cost=0.00..180.00 rows=1 width=13) (actual time=0.036..6.072 rows=1 loops=1)
   Filter: (id = 1)
   Rows Removed by Filter: 9999
 Planning time: 0.109 ms
 Execution time: 6.113 ms
(5 rows)

To remove your backend's hypothetical indexes, you can use the function hypopg_drop_index(indexrelid) with the OID that hypopg_list_indexes() function returns, call hypopg_reset() to remove all at once or just close your current connection.