Re: Planner regression in 8.0.x: WORKAROUND

From: "Dean Gibson (DB Administrator)" <postgresql4(at)ultimeth(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Planner regression in 8.0.x: WORKAROUND
Date: 2005-10-17 18:45:04
Message-ID: 4353F130.8080905@ultimeth.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

NOT TRUE!

The second query is effectively "(SELECT TRUE ...WHERE ... LIMIT 1) OR
(SELECT TRUE ...WHERE ... LIMIT 1) AS ..."

The first portion in parentheses can return either a single row of TRUE,
or no row (NULL). Ditto for the second portion. The OR means that you
logically combine TRUEs and/or NULLs into a SINGLE value. This can be
trivially verified by the following SELECT:

select (select true from anytable where TRUE limit 1) or (select true
from anytable where TRUE limit 1);

Vary the capitalized "TRUE"s each between true and false, and you will
see that EXACTLY ONE ROW IS RETURNED IN EACH CASE, having a resultant
(combined) value of either TRUE or NULL.

The real issue here is why the original query executes in a fraction of
a second under 7.4.x, and runs for hours on 8.0.4.

-- Dean

On 2005-10-17 11:17, Jim C. Nasby wrote:
> Those two queries aren't the same. The first one can only return 0 or 1 rows;
> the second one can return 0, 1, or 2 rows.
>
> An explain analyze of each should show why one is much faster than the
> other.
>
> On Mon, Oct 17, 2005 at 10:29:43AM -0700, Dean Gibson (DB Administrator) wrote:
>
>> In the query below, if I replace:
>>
>> (SELECT TRUE FROM archivejb WHERE ( (callsign = gen.callsign AND
>> license_status = 'A' AND prev_callsign = gen.vanity_callsign)
>> OR (callsign =
>> gen.vanity_callsign AND licensee_id =
>> gen.licensee_id))
>> AND grant_date < receipt_date LIMIT
>> 1) AS _verified,
>>
>> with:
>>
>> (SELECT TRUE FROM archivejb WHERE callsign = gen.callsign AND
>> license_status = 'A' AND prev_callsign = gen.vanity_callsign
>> AND grant_date < receipt_date LIMIT
>> 1) OR
>> (SELECT TRUE FROM archivejb WHERE callsign =
>> gen.vanity_callsign AND licensee_id = gen.licensee_id
>> AND grant_date < receipt_date LIMIT
>> 1) AS _verified,
>>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Matthew Peter 2005-10-17 18:47:15 Re: searching array
Previous Message Tom Lane 2005-10-17 18:44:24 Re: [pgsql-advocacy] Oracle buys Innobase