>>>>> "Ekta" == Ekta Khanna <ekha...@pivotal.io> writes:
Ekta> Hello PGSQL Hackers, Ekta> We have come across the following issue on Postgres Ekta> REL_10_STABLE. Below is the repro: [...] Ekta> In the plan, we see that planner merges the quals from FROM Ekta> clause and the WHERE clause in the same RESTRICTINFO. Is this the Ekta> expected behavior? Yes, it's entirely expected. You CANNOT make assumptions about the order of evaluation of quals; the planner will rearrange them freely, even across subquery boundaries (where the semantics allow). You can do this: WHERE CASE WHEN length(b) = 8 THEN to_date(b, 'YYYYMMDD') > '2018-05-04' ELSE false END since one of the few guarantees about execution order is that a CASE will evaluate its condition tests before any non-constant subexpressions in the corresponding THEN clause. (Another method is to put an OFFSET 0 in the subquery, but that's more of a hack) -- Andrew (irc:RhodiumToad)