Thread

Commits

  1. Remove useless asserts in report_namespace_conflict()

  1. [PATCH] Remove redundant Assert() calls in report_namespace_conflict()

    zengman <zengman@halodbtech.com> — 2026-01-16T14:24:56Z

    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
  2. Re: [PATCH] Remove redundant Assert() calls in report_namespace_conflict()

    Kirill Reshke <reshkekirill@gmail.com> — 2026-01-16T21:57:00Z

    On Fri, 16 Jan 2026, 19:25 zengman, <zengman@halodbtech.com> wrote:
    
    > 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
    
    
    
    Hi!
    
    Yes, this patch looks valid
    
  3. Re: [PATCH] Remove redundant Assert() calls in report_namespace_conflict()

    Michael Paquier <michael@paquier.xyz> — 2026-01-17T00:38:49Z

    On Sat, Jan 17, 2026 at 02:57:00AM +0500, Kirill Reshke wrote:
    > Yes, this patch looks valid
    
    It looks to me just a copy-pasto when this code has been written.
    Let's clean up that.
    --
    Michael
    
  4. Re: [PATCH] Remove redundant Assert() calls in report_namespace_conflict()

    zengman <zengman@halodbtech.com> — 2026-01-17T04:51:17Z

    Hi,
    
    > > Yes, this patch looks valid
    
    > It looks to me just a copy-pasto when this code has been written.
    > Let's clean up that.
    
    Thanks for your comment. I thought so too.
    
    --
    Regards,
    Man Zeng
    www.openhalo.org
  5. Re: [PATCH] Remove redundant Assert() calls in report_namespace_conflict()

    Michael Paquier <michael@paquier.xyz> — 2026-01-18T07:17:31Z

    On Sat, Jan 17, 2026 at 12:51:17PM +0800, zengman wrote:
    > Thanks for your comment. I thought so too.
    
    Applied as 2a6ce34b55e1.
    --
    Michael