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.
This commit is contained in:
Julien Rouhaud 2018-11-17 12:33:30 +01:00
parent aa8948d579
commit a0d7faefc2

View file

@ -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);