diff --git a/expected/hypopg.out b/expected/hypopg.out index 990cb46..a00648f 100644 --- a/expected/hypopg.out +++ b/expected/hypopg.out @@ -105,6 +105,9 @@ ORDER BY indexrelid; f (3 rows) +-- Should detect invalid argument +SELECT hypopg_relation_size(1); +ERROR: oid 1 is not a hypothetical index -- locally disable hypoopg SET hypopg.enabled to false; -- no hypothetical index should be used diff --git a/hypopg_index.c b/hypopg_index.c index 204fc3e..e7a0b7a 100644 --- a/hypopg_index.c +++ b/hypopg_index.c @@ -1388,6 +1388,7 @@ hypopg_relation_size(PG_FUNCTION_ARGS) double tuples; Oid indexid = PG_GETARG_OID(0); ListCell *lc; + bool found = false; pages = 0; tuples = 0; @@ -1398,9 +1399,14 @@ hypopg_relation_size(PG_FUNCTION_ARGS) if (entry->oid == indexid) { hypo_estimate_index_simple(entry, &pages, &tuples); + found = true; + break; } } + if (!found) + elog(ERROR, "oid %u is not a hypothetical index", indexid); + PG_RETURN_INT64(pages * 1.0L * BLCKSZ); } diff --git a/test/sql/hypopg.sql b/test/sql/hypopg.sql index 28e3fcb..64cfcd5 100644 --- a/test/sql/hypopg.sql +++ b/test/sql/hypopg.sql @@ -70,6 +70,9 @@ SELECT hypopg_relation_size(indexrelid) = current_setting('block_size')::bigint FROM hypopg() ORDER BY indexrelid; +-- Should detect invalid argument +SELECT hypopg_relation_size(1); + -- locally disable hypoopg SET hypopg.enabled to false;