From: Tom Lane <tgl@sss.pgh.pa.us>
To: David G Johnston <david.g.johnston@gmail.com>
Cc: pgsql-bugs@postgresql.org
Cc: Christian Pronovost <cpronovost@innvue.com>
Subject: Re: Re: BUG #11178: JSONB : The NOT operator applies to the <@ operator, even after casting to ::bool
Date: Mon, 18 Aug 2014 10:14:08 -0400
Message-ID: <18314.1408371248@sss.pgh.pa.us> (raw)
In-Reply-To: <1408370106705-5815230.post@n5.nabble.com>
References: <20140815211138.2543.16364@wrigleys.postgresql.org>
<1408147143170-5815058.post@n5.nabble.com>
<1408369143374-5815229.post@n5.nabble.com>
<1408370106705-5815230.post@n5.nabble.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
David G Johnston <david.g.johnston@gmail.com> writes:
> Apparently "NOT()" is both an operator itself (which acts on a boolean) and
> is also an optimization mechanic (which acts on an operator). Since the
> non-table version does not require any optimization the function behavior is
> taken and the correct answer is returned. In a table context - *even when
> the expression is not in a WHERE clause apparently* ... - the optimization
> code checks to see whether the associated operator has an associated negator
> function and then, if present, tries to compare a direct equality using the
> matched negator function. Since jsonb incorrectly had just such an
> operator, which indeed caused PostgreSQL to attempt to match equality using
> the "@>" operator, the behavior you saw was manifested.
Right, the transformation that's applied is
NOT (x op y) ==> x notop y
if operator "op" is declared to have a negator operator "notop".
Since <@ was incorrectly declared to have @> as its negator, the
expression simplification machinery was just doing what it was told.
The transformation that was *meant* to be applicable is the commutator
substitution,
x <@ y ==> y @> x
While that wouldn't be of any great value (and would not be used) in this
particular instance, it's essential to have commutator pairs for indexable
operators, because PG's indexing machinery can only cope with clauses in
which the indexed column is on the left.
Also, IIRC, the negator and commutator substitutions don't get considered
until after eval_const_expressions() is run; so something like
NOT('"1"'::jsonb <@ '["2"]')
will get folded to constant true before there's any opportunity for the
bug to manifest.
regards, tom lane
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
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, david.g.johnston@gmail.com, cpronovost@innvue.com
Subject: Re: BUG #11178: JSONB : The NOT operator applies to the <@ operator, even after casting to ::bool
In-Reply-To: <18314.1408371248@sss.pgh.pa.us>
References: <20140815211138.2543.16364@wrigleys.postgresql.org> <1408147143170-5815058.post@n5.nabble.com> <1408369143374-5815229.post@n5.nabble.com> <1408370106705-5815230.post@n5.nabble.com> <18314.1408371248@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