| From: | zengman <zengman(at)halodbtech(dot)com> |
|---|---|
| To: | pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | [PATCH] Remove redundant Assert() calls in report_namespace_conflict() |
| Date: | 2026-01-16 14:24:56 |
| Message-ID: | tencent_40F8C1D82E2EE28065009AAA@qq.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi all,
I noticed that report_namespace_conflict() has Assert(OidIsValid(nspOid)) at the function entry, and the same assertion is repeated in each switch case. These duplicate assertions are redundant since the check at the top already covers all cases.
Attached patch removes the 6 redundant assertions to make the code a bit cleaner.
```
static void
report_namespace_conflict(Oid classId, const char *name, Oid nspOid)
{
char *msgfmt;
Assert(OidIsValid(nspOid));
switch (classId)
{
case ConversionRelationId:
Assert(OidIsValid(nspOid));
msgfmt = gettext_noop("conversion \"%s\" already exists in schema \"%s\"");
break;
case StatisticExtRelationId:
Assert(OidIsValid(nspOid));
msgfmt = gettext_noop("statistics object \"%s\" already exists in schema \"%s\"");
break;
case TSParserRelationId:
Assert(OidIsValid(nspOid));
msgfmt = gettext_noop("text search parser \"%s\" already exists in schema \"%s\"");
break;
case TSDictionaryRelationId:
Assert(OidIsValid(nspOid));
msgfmt = gettext_noop("text search dictionary \"%s\" already exists in schema \"%s\"");
break;
case TSTemplateRelationId:
Assert(OidIsValid(nspOid));
msgfmt = gettext_noop("text search template \"%s\" already exists in schema \"%s\"");
break;
case TSConfigRelationId:
Assert(OidIsValid(nspOid));
msgfmt = gettext_noop("text search configuration \"%s\" already exists in schema \"%s\"");
break;
default:
elog(ERROR, "unsupported object class: %u", classId);
break;
}
ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_OBJECT),
errmsg(msgfmt, name, get_namespace_name(nspOid))));
}
```
--
Regards,
Man Zeng
www.openhalo.org
| Attachment | Content-Type | Size |
|---|---|---|
| 0001-Remove-unnecessary-Oid-validity-assertions-in-report.patch | application/octet-stream | 1.6 KB |
| From | Date | Subject | |
|---|---|---|---|
| Previous Message | Anders Åstrand | 2026-01-16 14:22:11 | [patch] Add support for connection strings to createuser and dropuser |