From a0d7faefc25c73075bc9071b34a7325a755fff56 Mon Sep 17 00:00:00 2001 From: Julien Rouhaud Date: Sat, 17 Nov 2018 12:33:30 +0100 Subject: [PATCH] Check for real table first in hypopg_add_partition() For now, hypo_table_name_get_entry() can be quite slow if many hypoTable are present, so perform cheaper check before it. --- hypopg_table.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hypopg_table.c b/hypopg_table.c index ba14265..fcc6db9 100644 --- a/hypopg_table.c +++ b/hypopg_table.c @@ -3291,14 +3291,14 @@ HYPO_PARTITION_NOT_SUPPORTED(); if (!PG_ARGISNULL(2)) partition_by = TextDatumGetCString(PG_GETARG_TEXT_PP(2)); - if (hypo_table_name_get_entry(partname) != NULL) - elog(ERROR, "hypopg: hypothetical table %s already exists", - quote_identifier(partname)); - if (RelnameGetRelid(partname) != InvalidOid) elog(ERROR, "hypopg: real table %s already exists", quote_identifier(partname)); + if (hypo_table_name_get_entry(partname) != NULL) + elog(ERROR, "hypopg: hypothetical table %s already exists", + quote_identifier(partname)); + tupdesc = CreateTemplateTupleDesc(HYPO_ADD_PART_COLS, false); TupleDescInitEntry(tupdesc, (AttrNumber) ++i, "relid", OIDOID, -1, 0); TupleDescInitEntry(tupdesc, (AttrNumber) ++i, "tablename", TEXTOID, -1, 0);