pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Midge Brown <midgems@sbcglobal.net>
Cc: pgsql-performance@postgresql.org
Subject: Re: slow query, different plans
Date: Sat, 04 Aug 2012 02:26:42 -0400
Message-ID: <25289.1344061602@sss.pgh.pa.us> (raw)
In-Reply-To: <9CF5A680782142D794A085320949FED4@BERNICE>
References: <9CF5A680782142D794A085320949FED4@BERNICE>

"Midge Brown" <midgems@sbcglobal.net> writes:
> I'm having a problem with a query on our production server, but not on a laptop running a similar postgres version with a recent backup copy of the same table. I tried reindexing the table on the production server, but it didn't make any difference. Other queries on the same table are plenty fast. 

Reindexing won't help that.  The problem is a bad statistical estimate;
it thinks there are about 700 rows with applies2 = 256, when there's
really only one.  That means the "fast" plan is a lot faster than the
planner gives it credit for, and conversely the "slow" plan is a lot
slower than the planner is expecting.  Their estimated costs end up
nearly the same, which makes it a bit of a chance matter which one is
picked --- but the true costs are a lot different.  So you need to fix
that rowcount estimate.  Raising the stats target for the table might
help.

			regards, tom lane



view thread (5+ messages)  latest in thread

Message-ID: <25289.1344061602@sss.pgh.pa.us>
Permalink:  ../25289.1344061602@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/25289.1344061602@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, midgems@sbcglobal.net
  Subject: Re: slow query, different plans
  In-Reply-To: <25289.1344061602@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox