From 74a6fa8fd4b767d28bc221199cb1429ccbc5ede5 Mon Sep 17 00:00:00 2001 From: Julien Rouhaud Date: Sat, 3 Mar 2018 11:40:32 +0100 Subject: [PATCH] Add a hypopg_reset_index() SQL wrapper. --- hypopg--2.0.0dev.sql | 5 +++++ hypopg_index.c | 11 +++++++++++ include/hypopg_index.h | 1 + 3 files changed, 17 insertions(+) diff --git a/hypopg--2.0.0dev.sql b/hypopg--2.0.0dev.sql index 946ad5b..b269ad3 100644 --- a/hypopg--2.0.0dev.sql +++ b/hypopg--2.0.0dev.sql @@ -8,6 +8,11 @@ SET client_encoding = 'UTF8'; +CREATE FUNCTION hypopg_reset_index() + RETURNS void + LANGUAGE C VOLATILE COST 100 +AS '$libdir/hypopg', 'hypopg_reset_index'; + CREATE FUNCTION hypopg_reset() RETURNS void LANGUAGE C VOLATILE COST 100 diff --git a/hypopg_index.c b/hypopg_index.c index a3e466c..2f99fbb 100644 --- a/hypopg_index.c +++ b/hypopg_index.c @@ -79,6 +79,7 @@ PG_FUNCTION_INFO_V1(hypopg_create_index); PG_FUNCTION_INFO_V1(hypopg_drop_index); PG_FUNCTION_INFO_V1(hypopg_relation_size); PG_FUNCTION_INFO_V1(hypopg_get_indexdef); +PG_FUNCTION_INFO_V1(hypopg_reset_index); static void hypo_addIndex(hypoIndex *entry); @@ -1338,6 +1339,16 @@ hypopg_get_indexdef(PG_FUNCTION_ARGS) PG_RETURN_TEXT_P(cstring_to_text(buf.data)); } +/* + * SQL wrapper to remove all declared hypothetical indexes. + */ +Datum +hypopg_reset_index(PG_FUNCTION_ARGS) +{ + hypo_index_reset(); + PG_RETURN_VOID(); +} + /* Simple function to set the indexname, dealing with max name length, and the * ending \0 diff --git a/include/hypopg_index.h b/include/hypopg_index.h index 6209791..b2bb17b 100644 --- a/include/hypopg_index.h +++ b/include/hypopg_index.h @@ -112,6 +112,7 @@ Datum hypopg_create_index(PG_FUNCTION_ARGS); Datum hypopg_drop_index(PG_FUNCTION_ARGS); Datum hypopg_relation_size(PG_FUNCTION_ARGS); Datum hypopg_get_indexdef(PG_FUNCTION_ARGS); +Datum hypopg_reset_index(PG_FUNCTION_ARGS); extern explain_get_index_name_hook_type prev_explain_get_index_name_hook; const char *hypo_explain_get_index_name_hook(Oid indexId);