Re: INSERT/UPDATE statements sometimes choosing not to use PK index?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Matt <bsg075(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: INSERT/UPDATE statements sometimes choosing not to use PK index?
Date: 2013-10-29 13:45:11
Message-ID: 32040.1383054311@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Matt <bsg075(at)gmail(dot)com> writes:
> In most cases, EXPLAIN and runtime tell me the index is utilized. However,
> sometime on back to back runs (5 minute intervals) the runtime explodes and
> EXPLAIN shows me that the PK index is not used, as both the staging table
> and destination table a sequentially scanned.

You haven't explained what you do with the "staging table", but maybe you
need to ANALYZE it after you've loaded fresh data into it. The stats for
the main table are presumably somewhat stable, but the stats for the
staging table maybe not. The apparent correlation to consecutive runs
lends some support to this theory, as that would reduce the time window
for auto-ANALYZE to fix it for you.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2013-10-29 14:06:22 Re: json datatype and table bloat?
Previous Message Chris Travers 2013-10-29 10:38:43 Re: json datatype and table bloat?