pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Cc: ranier_gyn@hotmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: [BUG FIX] Uninitialized var fargtypes used.
Date: Tue, 12 Nov 2019 11:07:10 -0500
Message-ID: <6298.1573574830@sss.pgh.pa.us> (raw)
In-Reply-To: <20191112140129.GA7283@alvherre.pgsql>
References: <20191112140129.GA7283@alvherre.pgsql>

Alvaro Herrera <alvherre@2ndquadrant.com> writes:
> On 2019-Nov-12, Kyotaro Horiguchi wrote:
>> We can change the condition with "nargs <= 0" and it should return the
>> only element in clist. If the catalog is broken we may get
>> FUNCLOOKUP_AMBIGUOUS but it seems rather the correct behavior.

> Yeah, essentially this reverts 0a52d378b03b.  Here's another version of
> this I wrote last night.

I really dislike the s/nargs < 0/nargs <= 0/ aspect of these proposals.
That's conflating two fundamentally different corner cases.  We have

(1) for the nargs<0 case, there must not be more than one match,
else it's a user mistake (and not an unlikely one).

(2) for the nargs==0 case, if there's more than one match, we either
have corrupted catalogs or some kind of software bug.

The argument for changing the code like this seems to be "we'll
assume the possibility of a bug/corruption is so small that it's
okay to treat it as a user mistake".  I reject that line of thinking.
And I especially reject conflating the two cases without bothering
to fix the adjacent comment that describes only case 1.

If we're going to revert 0a52d378b03b we should just treat the
problem straightforwardly.  I was imagining

-        if (memcmp(argtypes, clist->args, nargs * sizeof(Oid)) == 0)
+        /* if nargs==0, argtypes can be null; don't pass that to memcmp */
+        if (nargs == 0 ||
+            memcmp(argtypes, clist->args, nargs * sizeof(Oid)) == 0)

It's really stretching credulity to imagine that one more test-and-branch
in this loop costs anything worth noticing, especially compared to the
costs of having built the list to begin with.  So I'm now feeling that
0a52d378b03b was penny-wise and pound-foolish.

Or, in other words: the OP's complaint here is basically that the
existing code isn't being straightforward about how it handles this
scenario.  Changing to a different non-straightforward fix isn't
much of an improvement.

			regards, tom lane





view thread (8+ messages)  latest in thread

Message-ID: <6298.1573574830@sss.pgh.pa.us>
Permalink:  ../6298.1573574830@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/6298.1573574830@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, alvherre@2ndquadrant.com, horikyota.ntt@gmail.com, ranier_gyn@hotmail.com
  Subject: Re: [BUG FIX] Uninitialized var fargtypes used.
  In-Reply-To: <6298.1573574830@sss.pgh.pa.us>
  References: <20191112140129.GA7283@alvherre.pgsql> <6298.1573574830@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox