Re: Slow query postgres 8.3 - Mailing list pgsql-performance

From Kevin Grittner
Subject Re: Slow query postgres 8.3
Date
Msg-id 4DA2ED2F020000250003C657@gw.wicourts.gov
Whole thread Raw
In response to Re: Slow query postgres 8.3  ("Anne Rosset" <arosset@collab.net>)
Responses Re: Slow query postgres 8.3  (Claudio Freire <klaussfreire@gmail.com>)
List pgsql-performance
"Anne Rosset" <arosset@collab.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

pgsql-performance by date:

Previous
From: Greg Smith
Date:
Subject: Re: Multiple index builds on same table - in one sweep?
Next
From: Scott Marlowe
Date:
Subject: Re: Multiple index builds on same table - in one sweep?