From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
Cc: | Peter Koukoulis <pkoukoulis(at)gmail(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: hard parse? |
Date: | 2017-09-21 15:50:55 |
Message-ID: | 20231.1506009055@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> On Thu, Sep 21, 2017 at 5:48 AM, Peter Koukoulis <pkoukoulis(at)gmail(dot)com>
> wrote:
>> I have a query where a filter would always be negative, how many steps,
>> out these:
>>
>> - parsing and syntax check
>> - semantic analysis
>> - transformation process (query rewrite based on system or
>> user-defined rules)
>> - query optimization
>> - execution
>>
>> would be performed or not? Also, where in the documentation can I found
>> out which of the above phases would be performed?
> All of them.
Yeah. The question is more usefully formulated as "how much will the
query optimizer collapse a query with a constant-false condition"?
You can answer that with EXPLAIN, eg.
regression=# create table test1 (x int, y int);
CREATE TABLE
regression=# explain select x,y from test1 where 1=0;
QUERY PLAN
------------------------------------------
Result (cost=0.00..0.00 rows=0 width=8)
One-Time Filter: false
(2 rows)
In this case the answer is "pretty far" --- you get a valid but
dummy plan, which will just exit without returning any rows.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | George Neuner | 2017-09-21 16:35:04 | Re: VM-Ware Backup of VM safe? |
Previous Message | David G. Johnston | 2017-09-21 15:10:04 | Re: hard parse? |