pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Robert Haas <robertmhaas@gmail.com>
To: Sebastjan Trepca <trepca@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Problems with ordering (can't force query planner to use an index)
Date: Tue, 3 Mar 2009 15:27:12 -0500
Message-ID: <603c8f070903031227p4e849d02peea05784f4b3d1f5@mail.gmail.com> (raw)
In-Reply-To: <cd329af80903031116r1b55085ehaa73e4f1fe93eebe@mail.gmail.com>
References: <cd329af80903030905y2efa15bdt123779ee8877df4a@mail.gmail.com>
	<603c8f070903030912t36c541ebr50b4576c7a9a5b65@mail.gmail.com>
	<cd329af80903030920x7ccb7b10l7a279a464cab5bd4@mail.gmail.com>
	<603c8f070903030940n3fb1e9eay53666d06cf489469@mail.gmail.com>
	<cd329af80903031105o754b328aid9c1ecdd60b44278@mail.gmail.com>
	<cd329af80903031116r1b55085ehaa73e4f1fe93eebe@mail.gmail.com>

On Tue, Mar 3, 2009 at 2:16 PM, Sebastjan Trepca <trepca@gmail.com> wrote:
> Maybe this is useful, I removed the JOIN and it uses other
> index(core_accessor_date_idx indexes (date_posted, nooximity)), but
> its still hardly any better:
>
> noovo-new=# explain analyze SELECT * FROM "core_accessor" WHERE
> (("core_accessor"."slot_type_id" = 119
> noovo-new(#  AND "core_accessor"."slot_id" = 472 AND
> "core_accessor"."label" = E'' AND "core_accessor"."publish_state" >=
> 60 AND
> noovo-new(#  "core_accessor"."role" IN (0) AND
> "core_accessor"."user_id" = 0)) ORDER BY "core_accessor"."date_posted"
> DESC, "core_accessor"."nooximity" DESC LIMIT 5
> noovo-new-# ;
>
>       QUERY PLAN
> ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
>  Limit  (cost=0.00..3709.56 rows=5 width=178) (actual
> time=4593.867..4597.587 rows=5 loops=1)
>   ->  Index Scan Backward using core_accessor_date_idx on
> core_accessor  (cost=0.00..1810265.67 rows=2440 width=178) (actual
> time=4593.866..4597.583 rows=5 loops=1)
>         Filter: ((publish_state >= 60) AND (slot_type_id = 119) AND
> (slot_id = 472) AND (label = ''::text) AND (role = 0) AND (user_id =
> 0))
>  Total runtime: 4597.632 ms
> (4 rows)
>
>
> Sebastjan

Well, in that case, you are being bitten by the fact that our
multi-column selectivity estimates are not very good.  The planner has
good information on how each column behaves in isolation, but not how
they act together.  I've found this to be a very difficult problem to
fix.

Which of the parameters in this query vary and which ones are
typically always the same?  Sometimes you can improve things by
creating an appropriate partial index.

...Robert



view thread (10+ messages)  latest in thread

Message-ID: <603c8f070903031227p4e849d02peea05784f4b3d1f5@mail.gmail.com>
Permalink:  ../603c8f070903031227p4e849d02peea05784f4b3d1f5@mail.gmail.com/
Also on:    postgresql.org/message-id/603c8f070903031227p4e849d02peea05784f4b3d1f5@mail.gmail.com

 · 

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: robertmhaas@gmail.com, trepca@gmail.com
  Subject: Re: Problems with ordering (can't force query planner to use an index)
  In-Reply-To: <603c8f070903031227p4e849d02peea05784f4b3d1f5@mail.gmail.com>

* 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