Re: BUG #16356: Can't perform json operations on casted text in where clause when a join is used. WHERE is too early

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: valefbonetwo(at)gmail(dot)com
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)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: 2020-04-10 21:12:38
Message-ID: 1819.1586553158@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message David G. Johnston 2020-04-10 21:13:49 Re: BUG #16356: Can't perform json operations on casted text in where clause when a join is used. WHERE is too early
Previous Message PG Bug reporting form 2020-04-10 20:33:41 BUG #16356: Can't perform json operations on casted text in where clause when a join is used. WHERE is too early