Bug 122933
Summary: | PostgreSQL 7.4 yields erroneous results when using nested SELECT CASE | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Product: | [Fedora] Fedora | Reporter: | Didier <d.bz-redhat> | ||||||||
Component: | postgresql | Assignee: | Tom Lane <tgl> | ||||||||
Status: | CLOSED NEXTRELEASE | QA Contact: | David Lawrence <dkl> | ||||||||
Severity: | high | Docs Contact: | |||||||||
Priority: | medium | ||||||||||
Version: | 2 | CC: | hhorak | ||||||||
Target Milestone: | --- | ||||||||||
Target Release: | --- | ||||||||||
Hardware: | All | ||||||||||
OS: | Linux | ||||||||||
Whiteboard: | |||||||||||
Fixed In Version: | Doc Type: | Bug Fix | |||||||||
Doc Text: | Story Points: | --- | |||||||||
Clone Of: | Environment: | ||||||||||
Last Closed: | 2004-05-11 02:45:56 UTC | Type: | --- | ||||||||
Regression: | --- | Mount Type: | --- | ||||||||
Documentation: | --- | CRM: | |||||||||
Verified Versions: | Category: | --- | |||||||||
oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |||||||||
Cloudforms Team: | --- | Target Upstream Version: | |||||||||
Embargoed: | |||||||||||
Attachments: |
|
Description
Didier
2004-05-10 15:49:22 UTC
Created attachment 100127 [details]
minimal test case example
Created attachment 100128 [details]
Correct output (PostgreSQL 7.3.4)
Created attachment 100129 [details]
Faulty output (PostgreSQL 7.4.2)
I haven't quite tracked down the problem yet, but it seems to be associated with nested sub-SELECTs not being recalculated when they need to be. A short-run workaround ... which would also make the query a good bit faster, I suspect ... is to eliminate the unnecessary sub-SELECTs. Everyplace you have "SELECT CASE" could be just "CASE". Anyway, I'll see that this gets fixed for 7.4.3. Ah, found it. The fix is committed in upstream CVS, and can be found here if you want to apply a source patch: http://developer.postgresql.org/cvsweb.cgi/pgsql-server/src/backend/optimizer/plan/planner.c.diff?r2=1.161.2.2&r1=1.161.2.1&f=c It will appear in 7.4.3, which I don't know the schedule for yet, but likely will be available in time for FC3. The failure only occurs with doubly nested sub-SELECTs in which the inner sub-SELECT refers to outer-query values not also used by the outer sub-SELECT, and furthermore doesn't refer to any outer-query values that are used by the outer sub-SELECT. In testing with your example, it seems to require triply nested sub-SELECTs (eliminating any one of the three SELECT keywords makes the bug go away), though I have not taken the time to figure out exactly why that happens; I think there may be related cases that fail with only double nesting. I guess this is a fairly uncommon combination, else we'd have heard about the bug before now. Anyway, I have adapted your example case as a regression test for Postgres, so hopefully we'll catch any similar errors sooner in future. I figure this is just another Bugzilla entry which qualifies as a prominent example for my IT decision making colleagues, an example of the sheer power of open source and the commitment of its participants. Thank you for the very swift reply, Tom. (I did not apply the patch, but removed the SELECTs). |