Re: optimizing impossible matches

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Merlin Moncure" <merlin(dot)moncure(at)rcsonline(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: optimizing impossible matches
Date: 2004-03-10 15:21:16
Message-ID: 6701.1078932076@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

"Merlin Moncure" <merlin(dot)moncure(at)rcsonline(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2004-03-10 16:00:39 Re: [PATCHES] log_line_info
Previous Message Tom Lane 2004-03-10 15:04:07 Re: PITR Functional Design v2 for 7.5