From 9385d5e25e951dc9acf8e6bebca33dffc14e33f7 Mon Sep 17 00:00:00 2001 From: Julien Rouhaud Date: Thu, 23 Mar 2023 17:09:35 +0800 Subject: [PATCH] Fixup for index hiding patch. Fix compatibility for pg12- servers, and while at it remove some uncessary trailing whitespaces. --- README.md | 16 ++++++++-------- docs/index.rst | 2 +- docs/usage.rst | 24 ++++++++++++------------ hypopg_index.c | 6 +++++- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index f83549d..32fd3c9 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ Create two real indexes and run `EXPLAIN`: rjuju=# CREATE INDEX ON hypo(id); rjuju=# CREATE INDEX ON hypo(id, val); rjuju=# EXPLAIN SELECT * FROM hypo WHERE id = 1; - QUERY PLAN + QUERY PLAN ---------------------------------------------------------------------------------- Index Only Scan using hypo_id_val_idx on hypo (cost=0.29..8.30 rows=1 width=13) Index Cond: (id = 1) @@ -119,7 +119,7 @@ The query plan is using the `hypo_id_val_idx` index. Use `hypopg_hide_index(oid) rjuju=# SELECT hypopg_hide_index('hypo_id_val_idx'::REGCLASS); rjuju=# EXPLAIN SELECT * FROM hypo WHERE id = 1; - QUERY PLAN + QUERY PLAN ------------------------------------------------------------------------- Index Scan using hypo_id_idx on hypo (cost=0.29..8.30 rows=1 width=13) Index Cond: (id = 1) @@ -129,7 +129,7 @@ The query plan is using the other index `hypo_id_idx` now. Use `hypopg_hide_inde rjuju=# SELECT hypopg_hide_index('hypo_id_idx'::REGCLASS); rjuju=# EXPLAIN SELECT * FROM hypo WHERE id = 1; - QUERY PLAN + QUERY PLAN ------------------------------------------------------- Seq Scan on hypo (cost=0.00..180.00 rows=1 width=13) Filter: (id = 1) @@ -139,7 +139,7 @@ And now the query plan changes back to `Seq Scan`. Use `hypopg_unhide_index(oid) rjuju=# SELECT hypopg_unhide_index('hypo_id_idx'::regclass); rjuju=# EXPLAIN SELECT * FROM hypo WHERE id = 1; - QUERY PLAN + QUERY PLAN ------------------------------------------------------------------------- Index Scan using hypo_id_idx on hypo (cost=0.29..8.30 rows=1 width=13) Index Cond: (id = 1) @@ -149,7 +149,7 @@ Of course, you can also hide hypothetical indexes: rjuju=# SELECT hypopg_create_index('CREATE INDEX ON hypo(id)'); rjuju=# EXPLAIN SELECT * FROM hypo WHERE id = 1; - QUERY PLAN + QUERY PLAN ------------------------------------------------------------------------------------ Index Scan using "<12659>btree_hypo_id" on hypo (cost=0.04..8.05 rows=1 width=13) Index Cond: (id = 1) @@ -157,7 +157,7 @@ Of course, you can also hide hypothetical indexes: rjuju=# SELECT hypopg_hide_index(12659); rjuju=# EXPLAIN SELECT * FROM hypo WHERE id = 1; - QUERY PLAN + QUERY PLAN ------------------------------------------------------- Seq Scan on hypo (cost=0.00..180.00 rows=1 width=13) Filter: (id = 1) @@ -166,7 +166,7 @@ Of course, you can also hide hypothetical indexes: You can check which indexes are hidden using `hypopg_hidden_indexes()` or the `hypopg_hidden_indexes` view: rjuju=# SELECT * FROM hypopg_hidden_indexes(); - indexid + indexid --------- 526604 526603 @@ -183,4 +183,4 @@ You can check which indexes are hidden using `hypopg_hidden_indexes()` or the `h To restore all existing indexes, you can use the function `hypopg_unhide_all_indexes()`. Note that the functionality to hide existing indexes only applies to the EXPLAIN command in the current session -and will not affect other sessions. \ No newline at end of file +and will not affect other sessions. diff --git a/docs/index.rst b/docs/index.rst index 2f64e82..62ec24c 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -1,4 +1,4 @@ -.. title:: HypoPG: Hypothetical indexes for PostgreSQL +.. title:: HypoPG: Hypothetical indexes for PostgreSQL HypoPG ====== diff --git a/docs/usage.rst b/docs/usage.rst index 6d2cf27..7dae9cb 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -244,7 +244,7 @@ As a simple case, let's consider two indexes: :emphasize-lines: 4 EXPLAIN SELECT * FROM hypo WHERE id = 1; - QUERY PLAN + QUERY PLAN ---------------------------------------------------------------------------------- Index Only Scan using hypo_id_val_idx on hypo (cost=0.29..8.30 rows=1 width=13) Index Cond: (id = 1) @@ -259,13 +259,13 @@ The query plan is using the **hypo_id_val_idx** index now. :emphasize-lines: 10 SELECT hypopg_hide_index('hypo_id_val_idx'::REGCLASS); - hypopg_hide_index + hypopg_hide_index ------------------- t (1 row) - + EXPLAIN SELECT * FROM hypo WHERE id = 1; - QUERY PLAN + QUERY PLAN ------------------------------------------------------------------------- Index Scan using hypo_id_idx on hypo (cost=0.29..8.30 rows=1 width=13) Index Cond: (id = 1) @@ -278,13 +278,13 @@ To continue testing, use the **hypopg_hide_index(oid)** function to hide another :emphasize-lines: 10 SELECT hypopg_hide_index('hypo_id_idx'::REGCLASS); - hypopg_hide_index + hypopg_hide_index ------------------- t (1 row) EXPLAIN SELECT * FROM hypo WHERE id = 1; - QUERY PLAN + QUERY PLAN ------------------------------------------------------- Seq Scan on hypo (cost=0.00..180.00 rows=1 width=13) Filter: (id = 1) @@ -303,7 +303,7 @@ To continue testing, use the **hypopg_hide_index(oid)** function to hide another (1 row) EXPLAIN SELECT * FROM hypo WHERE id = 1; - QUERY PLAN + QUERY PLAN ------------------------------------------------------------------------- Index Scan using hypo_id_idx on hypo (cost=0.29..8.30 rows=1 width=13) Index Cond: (id = 1) @@ -316,7 +316,7 @@ To continue testing, use the **hypopg_hide_index(oid)** function to hide another .. code-block:: psql SELECT * FROM hypopg_hidden_indexes(); - indexid + indexid --------- 526604 (1 rows) @@ -339,13 +339,13 @@ To continue testing, use the **hypopg_hide_index(oid)** function to hide another :emphasize-lines: 10 SELECT hypopg_create_index('CREATE INDEX ON hypo(id)'); - hypopg_create_index + hypopg_create_index ------------------------------ (12659,<12659>btree_hypo_id) (1 row) EXPLAIN SELECT * FROM hypo WHERE id = 1; - QUERY PLAN + QUERY PLAN ------------------------------------------------------------------------------------ Index Scan using "<12659>btree_hypo_id" on hypo (cost=0.04..8.05 rows=1 width=13) Index Cond: (id = 1) @@ -363,7 +363,7 @@ Now that the hypothetical index is being used, we can try hiding it to see the c (1 row) EXPLAIN SELECT * FROM hypo WHERE id = 1; - QUERY PLAN + QUERY PLAN ------------------------------------------------------------------------- Index Scan using hypo_id_idx on hypo (cost=0.29..8.30 rows=1 width=13) Index Cond: (id = 1) @@ -389,4 +389,4 @@ Now that the hypothetical index is being used, we can try hiding it to see the c indexrelid | index_name | schema_name | table_name | am_name | is_hypo -------------+----------------------+-------------+------------+---------+--------- 526604 | hypo_id_val_idx | public | hypo | btree | f - (2 rows) \ No newline at end of file + (2 rows) diff --git a/hypopg_index.c b/hypopg_index.c index d77f584..a861a8b 100644 --- a/hypopg_index.c +++ b/hypopg_index.c @@ -1695,7 +1695,11 @@ hypopg_hidden_indexes(PG_FUNCTION_ARGS) oldcontext = MemoryContextSwitchTo(rsinfo->econtext->ecxt_per_query_memory); - tupdesc = CreateTemplateTupleDesc(1); + tupdesc = CreateTemplateTupleDesc(1 +#if PG_VERSION_NUM < 120000 + , false +#endif + ); TupleDescInitEntry(tupdesc, (AttrNumber) 1, "indexid", OIDOID, -1, 0); tupstore = tuplestore_begin_heap(true, false, work_mem);