Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 52580634957 for ; Tue, 3 Mar 2009 16:27:26 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 29360-07 for ; Tue, 3 Mar 2009 16:27:21 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from yx-out-2324.google.com (yx-out-2324.google.com [74.125.44.29]) by mail.postgresql.org (Postfix) with ESMTP id 570626344A7 for ; Tue, 3 Mar 2009 16:27:21 -0400 (AST) Received: by yx-out-2324.google.com with SMTP id 3so1704900yxj.73 for ; Tue, 03 Mar 2009 12:27:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=5i88VDqpIv+WROfivg45QpOOeZaYK9ePC44q3/K2Ia0=; b=DGWHHoSmiYAy/mN3AbvG70MuRTr/P2Cghc7UDKftRW5uY0KVNXRRQGg486HNy4EtOw UQhyTCcK7u4t+IGahV43BQ2ZcNTZBRzkTxD3V+LY1msv0YF3AJRB2S2jdK0hPZUyiafs OznTcuOS7Rw9YMjKRVmRiWdzWLr+n93PFgR8Y= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=v49qK4msPae2N2eFImgOh3L/wb3ZC6306rF/VwWLtt1UdGEnpZ6lSh/8JwfCju399F IdEWoPFFt4kefO+BAhAGabp5gu21JFzRMCEV2DXw8EZo0U/YWJs7WHFxPWQxHnkCCt7K RBXq7ALlbslaLmf4B0cbT2FDYuWXq4th9gWVE= MIME-Version: 1.0 Received: by 10.220.46.136 with SMTP id j8mr2573441vcf.72.1236112039242; Tue, 03 Mar 2009 12:27:19 -0800 (PST) In-Reply-To: References: <603c8f070903030912t36c541ebr50b4576c7a9a5b65@mail.gmail.com> <603c8f070903030940n3fb1e9eay53666d06cf489469@mail.gmail.com> Date: Tue, 3 Mar 2009 15:27:12 -0500 Message-ID: <603c8f070903031227p4e849d02peea05784f4b3d1f5@mail.gmail.com> Subject: Re: Problems with ordering (can't force query planner to use an index) From: Robert Haas To: Sebastjan Trepca Cc: pgsql-performance@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200903/35 X-Sequence-Number: 32957 On Tue, Mar 3, 2009 at 2:16 PM, Sebastjan Trepca 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=3D# explain analyze SELECT * FROM "core_accessor" WHERE > (("core_accessor"."slot_type_id" =3D 119 > noovo-new(# =A0AND "core_accessor"."slot_id" =3D 472 AND > "core_accessor"."label" =3D E'' AND "core_accessor"."publish_state" >=3D > 60 AND > noovo-new(# =A0"core_accessor"."role" IN (0) AND > "core_accessor"."user_id" =3D 0)) ORDER BY "core_accessor"."date_posted" > DESC, "core_accessor"."nooximity" DESC LIMIT 5 > noovo-new-# ; > > =A0 =A0 =A0 QUERY PLAN > -------------------------------------------------------------------------= ---------------------------------------------------------------------------= ------------------ > =A0Limit =A0(cost=3D0.00..3709.56 rows=3D5 width=3D178) (actual > time=3D4593.867..4597.587 rows=3D5 loops=3D1) > =A0 -> =A0Index Scan Backward using core_accessor_date_idx on > core_accessor =A0(cost=3D0.00..1810265.67 rows=3D2440 width=3D178) (actua= l > time=3D4593.866..4597.583 rows=3D5 loops=3D1) > =A0 =A0 =A0 =A0 Filter: ((publish_state >=3D 60) AND (slot_type_id =3D 11= 9) AND > (slot_id =3D 472) AND (label =3D ''::text) AND (role =3D 0) AND (user_id = =3D > 0)) > =A0Total 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