pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: piuschan <pchan@contigo.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: stored procedure suddenly runs slowly in HOT STANDBY but fast in primary
Date: Sat, 05 Jul 2014 00:31:36 -0400
Message-ID: <19691.1404534696@sss.pgh.pa.us> (raw)
In-Reply-To: <1404507888516-5810599.post@n5.nabble.com>
References: <1404507888516-5810599.post@n5.nabble.com>
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-performance>

piuschan <pchan@contigo.com> writes:
> PostgreSQL: 9.1.11

> Since July 1, one SP suddenly runs slowly in HOT STANDBY server. After
> investigation, I can narrow the problem to one particular query in SP.

>    SELECT MIN(locate_id) INTO v_min_locate_id
>    FROM   event_startstop
>    WHERE  beacon_id = p_beacon_id
>    AND    locate_id IS NOT NULL
>    AND    network_timestamp BETWEEN p_rpt_start_ts AND p_rpt_end_ts;

> (6) the event_startstop is a parent table with 406 children tables

TBH, the astonishing part of this report is not that it's slow, but
that it ever was not slow.  9.1 is not capable of avoiding scanning
the other 405 child tables when given a parameterized query such as
this one.  (You haven't said, but I suppose that the child tables
are partitioned on beacon_id and/or network_timestamp, so that knowledge
of the constants these columns are being compared to is essential for
doing constraint exclusion.)

You could work around that by inserting constants into the query with
EXECUTE, but a better answer would be to update to 9.2 or later.

			regards, tom lane


-- 
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance



view thread (3+ messages)  latest in thread

Message-ID: <19691.1404534696@sss.pgh.pa.us>
Permalink:  ../19691.1404534696@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/19691.1404534696@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, pchan@contigo.com
  Subject: Re: stored procedure suddenly runs slowly in HOT STANDBY but fast in primary
  In-Reply-To: <19691.1404534696@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