From e7022704db259fef2b76a0cdc062e17e095d8258 Mon Sep 17 00:00:00 2001 From: Julien Rouhaud Date: Sat, 22 Feb 2020 13:51:50 +0100 Subject: [PATCH] Fix failure with hypo index on unexisting table for pg10+. --- expected/hypo_index.out | 4 ++++ hypopg_index.c | 7 ++++++- hypopg_table.c | 7 +++++-- test/sql/hypo_index.sql | 4 ++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/expected/hypo_index.out b/expected/hypo_index.out index 00015b3..ccd6a7f 100644 --- a/expected/hypo_index.out +++ b/expected/hypo_index.out @@ -1,4 +1,8 @@ -- Hypothetical index tests +-- Hypothetical index on unexisting table +SELECT COUNT(*) AS nb +FROM public.hypopg_create_index('CREATE INDEX ON notatable(meh);'); +ERROR: relation "notatable" does not exist CREATE TABLE hypo (id integer, val text); INSERT INTO hypo SELECT i, 'line ' || i FROM generate_series(1,100000) f(i); diff --git a/hypopg_index.c b/hypopg_index.c index 63da080..8f26e06 100644 --- a/hypopg_index.c +++ b/hypopg_index.c @@ -352,7 +352,12 @@ hypo_index_store_parsetree(IndexStmt *node, const char *queryString) hypoTable *table = hypo_table_name_get_entry(rv->relname); if (!table) - elog(ERROR, "hypopg: table %s does not exists", + /* + * We use the same error message as postgres so users (and + * regression tests) get a consistent message error before and + * after pg10. + */ + elog(ERROR, "relation \"%s\" does not exist", quote_identifier(rv->relname)); if (table->partkey) diff --git a/hypopg_table.c b/hypopg_table.c index 445b01d..8d5ee6d 100644 --- a/hypopg_table.c +++ b/hypopg_table.c @@ -1920,8 +1920,8 @@ hypo_find_table(Oid tableid, bool missing_ok) } /* - * Return the hypothetical oid if the given name is an hypothetical partition, - * otherwise return InvalidOid + * Return the hypothetical table if the given unqualified object name is an + * hypothetical partition, otherwise return NULL. */ hypoTable * hypo_table_name_get_entry(const char *name) @@ -1929,6 +1929,9 @@ hypo_table_name_get_entry(const char *name) HASH_SEQ_STATUS hash_seq; hypoTable *entry; + if (!hypoTables) + return NULL; + hash_seq_init(&hash_seq, hypoTables); while ((entry = hash_seq_search(&hash_seq)) != NULL) { diff --git a/test/sql/hypo_index.sql b/test/sql/hypo_index.sql index 63550ee..d99eba6 100644 --- a/test/sql/hypo_index.sql +++ b/test/sql/hypo_index.sql @@ -1,5 +1,9 @@ -- Hypothetical index tests +-- Hypothetical index on unexisting table +SELECT COUNT(*) AS nb +FROM public.hypopg_create_index('CREATE INDEX ON notatable(meh);'); + CREATE TABLE hypo (id integer, val text); INSERT INTO hypo SELECT i, 'line ' || i