From: | "[Quipsy] Markus Karg" <karg(at)quipsy(dot)de> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org> |
Subject: | AW: WHERE column = X AND column = Y will always be zero matching rows |
Date: | 2023-08-04 06:12:55 |
Message-ID: | 0e20d207845f41609f91ce499c08c759@quipsy.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
Tom,
thanks a lot for your kind explanation, this was very interesting to read!
In fact, I have missed the "never executed" marks.
BTW, I did not "complain". I just noticed something and was unclear if this is a bug or not, and I clearly told so in the opening of my posting. It was definitively not my intention to bother or annoy anybody, actually. Sorry to have troubled so many in this mailing list.
-Markus
-----Ursprüngliche Nachricht-----
Von: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Gesendet: Donnerstag, 3. August 2023 19:59
An: [Quipsy] Markus Karg <karg(at)quipsy(dot)de>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Betreff: Re: WHERE column = X AND column = Y will always be zero matching rows
"[Quipsy] Markus Karg" <karg(at)quipsy(dot)de> writes:
> (In the following X and Y are literals; X <> Y) I noticed is that...
> EXPLAIN SELECT column FROM Table WHERE column = X AND column = Y
> ...says that PostgreSQL actually wants to perform a Scan!
You should learn to read plans before complaining about them.
What you actually get is something like
regression=# explain analyze select * from tenk1 where hundred = 42 and hundred = 99;
QUERY PLAN
-----------------------------------------------------------------------------------------------------
Result (cost=5.04..224.95 rows=1 width=244) (actual time=0.001..0.002 rows=0 loops=1)
One-Time Filter: false
-> Bitmap Heap Scan on tenk1 (cost=5.04..224.95 rows=1 width=244) (never executed)
Recheck Cond: (hundred = 42)
-> Bitmap Index Scan on tenk1_hundred (cost=0.00..5.04 rows=100 width=0) (never executed)
Index Cond: (hundred = 42) Planning Time: 0.148 ms Execution Time: 0.046 ms
(8 rows)
See the "never executed" markings? The one-time filter prevents anything below the Result from actually doing anything.
From memory, the reason it's like this is that it's the most straightforward extension of cases involving pseudoconstant conditions, that is parameters not known at plan time.
If you had something like "WHERE var = param1 AND var = const1"
then you might get something involving a "param1 = const1"
one-time filter, and below that a plan to retrieve rows with "var = const1", which would only be run when the run-time-supplied parameter happens to match the constant.
David's statement that we don't want to write code for such cases isn't completely true, but it is true that we don't want to expend code on producing a pretty-looking plan for them.
> BTW the same happens for column IS NULL AND column = Y.
That indeed is a case we haven't bothered with, and probably never will. The multiple-constants-equated-to-the-same-thing
situation is dealt with by the equivalence class machinery, which has many other purposes but happens to be able to detect that situation cheaply. But IS NULL is not an equivalence condition (as we define those, anyway). Likewise, we won't reduce something like "var > C1 AND var < C1" to constant-false; there's just not enough win probability to justify spending planner cycles looking for such cases.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Hamid Akhtar | 2023-08-04 11:22:55 | Re: BUG #18046: stats collection behaviour change is affecting the usability of information. |
Previous Message | PG Bug reporting form | 2023-08-04 05:22:29 | BUG #18049: dynamic_shared_memory_type's value `posix` doesn't have any effect, syscall shm_get executes |