OR-of-ANDs dragon slain ... or at least seriously wounded ... - Mailing list pgsql-hackers

From Tom Lane
Subject OR-of-ANDs dragon slain ... or at least seriously wounded ...
Date
Msg-id 9327.949032603@sss.pgh.pa.us
Whole thread Raw
Responses Re: [HACKERS] OR-of-ANDs dragon slain ... or at least seriously wounded ...
List pgsql-hackers
I have just committed fixes that make use of an idea suggested by
Taral (see TODO.detail/cnfify, his message of 2-Oct-98).  The code
now makes a simple heuristic estimate of the size that the WHERE
clause will be after conversion to CNF or DNF format, and refrains
from attempting to canonicalize the clause if the cost looks too
high.

I was able to run this query plan:

explain
select unique1 from tenk1 where
(unique1 = 1 and unique2 =2) or
(unique1 = 2 and unique2 =3) or
(unique1 = 3 and unique2 =4) or
... ten thousand OR clauses ...
(unique1 = 9998 and unique2 =9999) or
(unique1 = 9999 and unique2 =10000) or
(unique1 = 10000 and unique2 =10001);

in about 15 seconds and 30MB memory consumption.  Which is still
more than I'd like, but the old code couldn't cope with twenty
clauses without exhausting one's swap space and/or patience.

I am probably not going to remove the KSQO hack just yet, because
it still seems to have a performance advantage for queries with
a few hundred or thousand OR clauses.  But KSQO is no longer
absolutely essential, AFAICT.

I'd be interested to get some feedback on this code from people
who are using KSQO currently.  The patch is in current CVS and
should be available in Friday morning's snapshot tarball.
        regards, tom lane


pgsql-hackers by date:

Previous
From: The Hermit Hacker
Date:
Subject: Re: [HACKERS] [6.5.3] 'attribute not found'
Next
From: Tom Lane
Date:
Subject: Re: [HACKERS] TID clarification