Re: Delete query takes exorbitant amount of time

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Karim A Nassar <Karim(dot)Nassar(at)NAU(dot)EDU>
Cc: Simon Riggs <simon(at)2ndquadrant(dot)com>, Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Christopher Kings-Lynne <chriskl(at)familyhealth(dot)com(dot)au>, pgsql-performance(at)postgresql(dot)org
Subject: Re: Delete query takes exorbitant amount of time
Date: 2005-04-03 12:18:20
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-performance

On Tue, Mar 29, 2005 at 01:48:48 -0700,
Karim A Nassar <Karim(dot)Nassar(at)NAU(dot)EDU> wrote:
> For this FK check, there only need be one referring id to invalidate the
> delete. ISTM that for any delete with a FK reference, the index could
> always be used to search for a single value in the referring table
> (excepting very small tables). Why then must a sequential scan be
> performed in this case, and/or in general?

First the index needs to exist. It isn't created automatically because not
everyone wants such an index. Second, you need to have analyzed the
referencing table so that the planner will know it is big enough that
using an indexed search is worthwhile. The planner is getting better
about dealing with size changes without reanalyzing, but it seems there
are still some gotchas in 8.0.

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Bruno Wolff III 2005-04-03 13:04:11 Re: coalesce alternative
Previous Message PFC 2005-04-03 08:01:13 Re: Query Optimizer Failure / Possible Bug