Skip to content

Commit

Permalink
Fix failure with hypo index on unexisting table for pg10+.
Browse files Browse the repository at this point in the history
  • Loading branch information
rjuju committed Feb 22, 2020
1 parent b41bd64 commit e702270
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions expected/hypo_index.out
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
7 changes: 6 additions & 1 deletion hypopg_index.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions hypopg_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -1920,15 +1920,18 @@ 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)
{
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)
{
Expand Down
4 changes: 4 additions & 0 deletions test/sql/hypo_index.sql
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit e702270

Please sign in to comment.