Re: optimizing impossible matches - Mailing list pgsql-hackers

From Tom Lane
Subject Re: optimizing impossible matches
Date
Msg-id 6701.1078932076@sss.pgh.pa.us
Whole thread Raw
In response to optimizing impossible matches  ("Merlin Moncure" <merlin.moncure@rcsonline.com>)
List pgsql-hackers
"Merlin Moncure" <merlin.moncure@rcsonline.com> writes:
> Is this really as simple as it seems?

No.

The optimizer has no knowledge of specific operators except what it
finds in the system catalogs.  It has no way in general to determine
that a comparison involving nonconstant values must always fail.
Even if we could do it, I am dubious that it would be worth expending
the cycles on every query to determine whether the situation holds.
AFAICS those would be wasted cycles on the huge majority of queries.

BTW, your claim here is simply false:

> also, for the typical case for indexed field f,
>     select * from t where f = f' or false
> generates an index scan
> but 
>     select * from t where f = f' or f = f''
> generates a seq. scan with default settings.

Depending on the statistics of the column f, the optimizer might think
that a seqscan is better than a double indexscan, but it's not some kind
of hardwired behavior.  I don't even think it's "typical" behavior.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: PITR Functional Design v2 for 7.5
Next
From: Fabien COELHO
Date:
Subject: Re: question about char/wchar/mb utils