Re: partial index on varchar-coloumn in 7.4.1

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Martin Hampl <Martin(dot)Hampl(at)gmx(dot)de>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: partial index on varchar-coloumn in 7.4.1
Date: 2004-01-07 22:35:52
Message-ID: 2040.1073514952@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I wrote:
> Martin Hampl <Martin(dot)Hampl(at)gmx(dot)de> writes:
>> Do partial indexes not work for varchar?

> You know and I know that "word = 'abc'" implies "not (word = 'the')",
> but the planner cannot make that deduction. The pred_test() routine
> doesn't really have any intelligence about conditions involving NOT.

Actually, this was easier to fix than I thought. As of CVS tip:

regression=# create table token(word varchar(30));
CREATE TABLE
regression=# CREATE INDEX word_idx on token (word) where not (word = 'the');
CREATE INDEX
regression=# explain select * from token where word = 'abc' ;
QUERY PLAN
------------------------------------------------------------------------
Index Scan using word_idx on token (cost=0.00..17.07 rows=5 width=33)
Index Cond: ((word)::text = 'abc'::text)
(2 rows)

regression=#

There's still no intelligence about NOT in the theorem prover, but it
turns out that it's not seeing NOT. By the time the expressions get to
the point of being compared, NOT (a=b) has been folded to a<>b, and it
turned out to be fairly straightforward to extend the existing logic to
reason about such cases. The above example requires a process like
"a = x implies a <> y if x <> y" (where x and y are constants, so the
"if" part can be checked). This fits right in with what the code could
do already, which was cases like "a > x implies a > y if x > y".
So it'll work more naturally in 7.5.

regards, tom lane

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Cath Lawrence 2004-01-08 01:05:07 Upgrade function problem - c language
Previous Message Tom Lane 2004-01-07 20:06:28 Re: See how many connections