Re: EXISTS clauses not being optimized in the face of 'one time pass' optimizable expressions

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: EXISTS clauses not being optimized in the face of 'one time pass' optimizable expressions
Date: 2016-07-01 15:27:34
Message-ID: CA+TgmoYBnWuJbEasHODB3WPmheW+ypWxUYzT=ugnQCqg9bmFKA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Jul 1, 2016 at 10:20 AM, Merlin Moncure <mmoncure(at)gmail(dot)com> wrote:
> Yeah. Also, even if you could parse out those cases, it's major
> optimization fence. Consider if you have an ORDER BY clause here:
>
> SELECT FROM foo WHERE a OR b ORDER BY c;
>
> ... by pushing inside a union, you're going to be in trouble in real
> world cases. That's just a mess and it would add a lot of runtime
> analysis of the alternative paths. It's hard for me to believe
> rewriting is easier and simpler than rewriting 'false OR x' to 'x'. I
> also thing that constant folding strategies are going to render much
> more sensible output to EXPLAIN.

I don't think that it's easier and simpler and didn't intend to say
otherwise. I do think that I've run across LOTS of queries over the
years where rewriting OR using UNION ALL was a lot faster, and I think
that case is more likely to occur in practice than FALSE OR WHATEVER.
But, I'm just throwing out opinions to see what sticks here; I'm not
deeply invested in this.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2016-07-01 15:32:25 Re: Postgres_fdw join pushdown - wrong results with whole-row reference
Previous Message Robert Haas 2016-07-01 15:25:42 Re: EXISTS clauses not being optimized in the face of 'one time pass' optimizable expressions