Re: Foreign keys and partial indexes

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Nichlas Löfdahl <crotalus(at)acc(dot)umu(dot)se>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Foreign keys and partial indexes
Date: 2005-04-13 16:05:01
Message-ID: 7849.1113408301@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Nichlas =?iso-8859-1?Q?L=F6fdahl?= <crotalus(at)acc(dot)umu(dot)se> writes:
> I have a partial index (btree(col) WHERE col > 0) on table2 ('col' contains alot of NULL-values).

> There's also a foreign key on the column pointing to the primary key of table1 (ON UPDATE CASCADE ON DELETE SET NULL). During update/delete, it seems like it cannot use the partial index to find corresponding rows matching the foreign key (doing a full seqscan instead)?

> Is there any special reason for not letting the planner use the partial index when appropriate?

It doesn't know it's appropriate. There's nothing constraining the FK
to be positive, after all.

regards, tom lane

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Mark Lewis 2005-04-13 16:42:29 Re: [PERFORM] Many connections lingering
Previous Message Nichlas Löfdahl 2005-04-13 15:45:46 Foreign keys and partial indexes