Re: Slow query postgres 8.3

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: "Anne Rosset" <arosset(at)collab(dot)net>,<tv(at)fuzzy(dot)cz>
Cc: <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Slow query postgres 8.3
Date: 2011-04-11 16:59:43
Message-ID: 4DA2ED2F020000250003C657@gw.wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

"Anne Rosset" <arosset(at)collab(dot)net> wrote:

> -> Index Scan using role_oper_obj_oper
> on role_operation (cost=0.00..93.20 rows=45 width=9) (actual
> time=0.236..71.291 rows=6108 loops=1)
> Index Cond:
> (((object_type_id)::text = 'SfMain.Project'::text) AND
> ((operation_category)::text = 'admin'::text) AND
> ((operation_name)::text = 'admin'::text))

This looks like another case where there is a correlation among
multiple values used for selection. The optimizer assumes, for
example, that category = 'admin' will be true no more often for rows
with operation_name = 'admin' than for other values of
operation_name. There has been much talk lately about how to make
it smarter about that, but right now there's no general solution,
and workarounds can be tricky.

In more recent versions you could probably work around this with a
Common Table Expression (CTE) (using a WITH clause). In 8.3 the
best idea which comes immediately to mind is to select from the
role_operation table into a temporary table using whichever of those
three criteria is most selective, and then join that temporary table
into the rest of the query. Maybe someone else can think of
something better.

-Kevin

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Kevin Grittner 2011-04-11 18:09:15 Re: Linux: more cores = less concurrency.
Previous Message Anne Rosset 2011-04-11 16:07:45 Re: Slow query postgres 8.3