Re: Suboptimal execution plan for simple query

From: "Markus Wollny" <Markus(dot)Wollny(at)computec(dot)de>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Suboptimal execution plan for simple query
Date: 2008-11-13 09:32:42
Message-ID: 28011CD60FB1724DBA4442E38277F6260AF98C30@hermes.computec.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi!

In preparation for my upcoming upgrade to PostgreSQL 8.3.5, I have taken the opportunity to try this scenario on a test machine with the latest PostgreSQL version. Unfortunately the result remains the same, though this database has been just reloaded from a dump and vacuum analyzed. select version() outputs "PostgreSQL 8.3.5 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)".

Kind regards

Markus

Just for reference:
> Now I've got this simple query
>
> SELECT image_id
> FROM image_relation
> WHERE entity_id = 69560::integer
> ORDER BY last_updated DESC
> LIMIT 1;
>
> which currently runs for something around 600ms. Here's the explain
> analyze output:
>
> "Limit (cost=0.00..144.78 rows=1 width=12) (actual
> time=599.745..599.747 rows=1 loops=1)" " -> Index Scan Backward
> using idx_image_relation_last_updated on image_relation
> (cost=0.00..39525.70 rows=273 width=12) (actual time=599.741..599.741
> rows=1 loops=1)" " Filter: (entity_id = 69560)" "Total
> runtime: 599.825 ms"

> SELECT image_id
> FROM image_relation
> WHERE entity_id = 69560
> AND entity_id = entity_id
> ORDER BY last_updated DESC
> LIMIT 1
>
> "Limit (cost=881.82..881.82 rows=1 width=12) (actual
> time=0.097..0.099 rows=1 loops=1)" " -> Sort (cost=881.82..881.82
> rows=1 width=12) (actual time=0.094..0.094 rows=1 loops=1)" "
> Sort Key: last_updated" " -> Index Scan using
> idx_image_relation_entity_id on image_relation (cost=0.00..881.81
> rows=1 width=12) (actual time=0.063..0.075 rows=3 loops=1)" "
> Index Cond: (entity_id = 69560)" " Filter: (entity_id =
> entity_id)" "Total runtime: 0.128 ms"

Computec Media AG
Sitz der Gesellschaft und Registergericht: Fürth (HRB 8818)
Vorstandsmitglieder: Johannes S. Gözalan (Vorsitzender) und Rainer Rosenbusch
Vorsitzender des Aufsichtsrates: Jürg Marquard
Umsatzsteuer-Identifikationsnummer: DE 812 575 276

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ivan Sergio Borgonovo 2008-11-13 09:33:32 Re: still gin index creation takes forever
Previous Message Russell Smith 2008-11-13 08:27:53 Re: can someone help me to make a sql more pretty and more concise?