Re: possible optimizations - pushing filter before aggregation

From: Douglas Doole <dougdoole(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: possible optimizations - pushing filter before aggregation
Date: 2016-11-19 02:59:34
Message-ID: CADE5jY+izr7SMGVDmhEr6ksRPnYRPOQ_=mXTLyQnT+bsL+T32g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Nov 18, 2016 at 12:47 AM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
wrote:

Isn't possible in this case push equivalence before aggregation?

If I'm understanding you correctly, that would lead to wrong results.
Here's a simple example:

CREATE VIEW v AS SELECT MIN(a) m FROM t;

and table T contains:

T:A
---
1
2
3

SELECT * FROM v WHERE m = 2

The minimum value of A is 1, so the query should return no rows.

However, if we filter first we'd be effectively doing the query:

SELECT MIN(a) m FROM
(SELECT a FROM t WHERE a=2) AS v(a)

The subquery is going to return an intermediate result of:

V:A
---
2

And the minimum of that is 2, which is the wrong answer.

- Doug
Salesforce

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2016-11-19 03:00:24 Re: Fix checkpoint skip logic on idle systems by tracking LSN progress
Previous Message Michael Paquier 2016-11-19 02:20:16 Re: Mail thread references in commits