pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: valefbonetwo@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #16356: Can't perform json operations on casted text in where clause when a join is used. WHERE is too early
Date: Fri, 10 Apr 2020 17:12:38 -0400
Message-ID: <1819.1586553158@sss.pgh.pa.us> (raw)
In-Reply-To: <16356-871a3cce0a87d34e@postgresql.org>
References: <16356-871a3cce0a87d34e@postgresql.org>

PG Bug reporting form <noreply@postgresql.org> writes:
> It's somehow resurrected the value of 'a' that was well-eliminated prior to
> this where clause. So what gives? Why does the join cause it to apply the
> last where clause (which should happen logically last) too early?

The documentation explicitly disclaims any specific evaluation order for
WHERE clauses, cf

https://www.postgresql.org/docs/current/sql-expressions.html#SYNTAX-EXPRESS-EVAL

If you really need to, you can force the matter by putting some type of
optimization fence into the sub-select ("OFFSET 0" is the traditional
way, or you can use WITH ... AS MATERIALIZED in v12 and up).  This is
typically disastrous for performance, of course.  Not being able to
filter rows before joining would make the join much slower.

I'll just note that the sort of EAV schema that you have here is widely
agreed to be an anti-pattern in database design.

			regards, tom lane





view thread (2+ messages)  latest in thread

Message-ID: <1819.1586553158@sss.pgh.pa.us>
Permalink:  ../1819.1586553158@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1819.1586553158@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, valefbonetwo@gmail.com
  Subject: Re: BUG #16356: Can't perform json operations on casted text in where clause when a join is used. WHERE is too early
  In-Reply-To: <1819.1586553158@sss.pgh.pa.us>
  References: <16356-871a3cce0a87d34e@postgresql.org> <1819.1586553158@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