| From: | Alvaro Herrera <alvherre(at)commandprompt(dot)com> | 
|---|---|
| To: | adam terrey <a(dot)terrey(at)mackillop(dot)acu(dot)edu(dot)au> | 
| Cc: | pgsql-bugs(at)postgresql(dot)org | 
| Subject: | Re: Inconsistant SQL results - Suspected error with query planing or query optimisation. | 
| Date: | 2007-05-22 15:12:26 | 
| Message-ID: | 20070522151226.GC5193@alvh.no-ip.org | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-bugs pgsql-hackers | 
adam terrey wrote:
> The second setup (Listing C) is identicle to the first execpt that the 
> table "items" has an extra field and a primary key index. The goal of this 
> setup is to produce a cirtian query plan that I beleive is broken, where 
> it seems that the "Nested Loop Left Join" has forced the filter for "WHERE 
> number = 1" outside or (perhaps after) a join one of the more nested joins 
> causeing that  more nested join to cancel it self out. 
It's easy to confirm that the nested loop is the culprit here: if you
SET enable_nestloop to off, the query returns different results (the
expected two tuples).
8.1 seems to work OK, but both 8.2 and HEAD don't.
alvherre=# set enable_nestloop to off;
SET
alvherre=#  SELECT items.id
FROM items
LEFT JOIN (
        -- Query i.
        SELECT  items.id
        FROM items
        LEFT JOIN (
                -- Query ii.
                SELECT id FROM items WHERE number = 1
        ) AS moded_items USING (id)
        WHERE moded_items.id IS NULL
) AS sub_items USING (id)
WHERE sub_items.id IS NULL;
 id  
-----
 500
 600
(2 rows)
alvherre=# set enable_nestloop to on;
SET
alvherre=#  SELECT items.id
FROM items
LEFT JOIN (
        -- Query i.
        SELECT  items.id
        FROM items
        LEFT JOIN (
                -- Query ii.
                SELECT id FROM items WHERE number = 1
        ) AS moded_items USING (id)
        WHERE moded_items.id IS NULL
) AS sub_items USING (id)
WHERE sub_items.id IS NULL;
 id 
----
(0 rows)
-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2007-05-22 15:53:06 | Re: Inconsistant SQL results - Suspected error with query planing or query optimisation. | 
| Previous Message | ;John D. Tiedeman | 2007-05-22 14:57:53 | BUG #3297: psql won't open | 
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Richard Huxton | 2007-05-22 15:17:18 | Do we need a TODO? (was Re: Concurrently updating an updatable view) | 
| Previous Message | Shachar Shemesh | 2007-05-22 14:14:54 | Re: Re: [Oledb-dev] double precision error with pg linux server, but not with windows pg server |