Re: query has huge variance in execution times

From: David Wilson <david(dot)t(dot)wilson(at)gmail(dot)com>
To: Brian Cox <brian(dot)cox(at)ca(dot)com>
Cc: "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: query has huge variance in execution times
Date: 2010-03-31 04:37:40
Message-ID: x2oe7f9235d1003302137p2f41110bu97dd919cdd4772b@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Wed, Mar 31, 2010 at 12:11 AM, Brian Cox <brian(dot)cox(at)ca(dot)com> wrote:

>
> 2010-03-30 18:41:11.685261-07 | select b.ts_id from
> ts_stats_tranunit_user_daily b, ts_stats_tranunit_user_interval c where
> b.ts_transet_incarnation_id = c.ts_transet_incarnation_id and
> b.ts_tranunit_id = c.ts_tranunit_id and b.ts_user_incarnation_id =
> c.ts_user_incarnation_id and c.ts_interval_start_time >= $1 and
> c.ts_interval_start_time < $2 and b.ts_interval_start_time >= $3 and
> b.ts_interval_start_time < $4
> (1 row)
>
> about 5 mins later, I, suspecting problems, do (the values are the same as
> for $1 et al above; EXPLAIN was done on purpose to keep stats [hopefully]
> the same as when pid 10022 started; there are 80,000 rows in each of the 2
> tables at the time of this EXPLAIN and when 10022 started):
>
> cemdb=> explain select b.ts_id from ts_stats_tranunit_user_daily b,
> ts_stats_tranunit_user_interval c where b.ts_transet_incarnation_id =
> c.ts_transet_incarnation_id and b.ts_tranunit_id = c.ts_tranunit_id and
> b.ts_user_incarnation_id = c.ts_user_incarnation_id and
> c.ts_interval_start_time >= '2010-3-29 01:00' and c.ts_interval_start_time <
> '2010-3-29 02:00' and b.ts_interval_start_time >= '2010-3-29' and
> b.ts_interval_start_time < '2010-3-30';
>
>
These won't necessarily get the same plan. If you want to see what plan the
prepared query is getting, you'll need to prepare it ("prepare foo as
<query>") and then explain *that* via "explain execute foo".

The prepared version likely has a much more generic plan, whereas the
regular query gets optimized for the actual values provided.

--
- David T. Wilson
david(dot)t(dot)wilson(at)gmail(dot)com

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Artiom Makarov 2010-03-31 07:42:29 Re: temp table "on commit delete rows": transaction overhead
Previous Message Brian Cox 2010-03-31 04:11:36 query has huge variance in execution times