Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id C7EF21337BD4 for ; Thu, 10 Feb 2011 17:12:32 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 53715-02 for ; Thu, 10 Feb 2011 21:12:25 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 1712F1337BE1 for ; Thu, 10 Feb 2011 17:12:19 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p1ALCC94004661; Thu, 10 Feb 2011 16:12:13 -0500 (EST) To: Tobias Brox cc: Josh Berkus , pgsql-performance@postgresql.org Subject: Re: Why we don't want hints Was: Slow count(*) again... In-reply-to: References: <201102012247.p11Ml6u02682@momjian.us> <4D48914B.4050403@dunslane.net> <4D489AD1.1010105@vmsinfo.com> <4D499E55.4020107@vmsinfo.com> <4D49A6B9.4060608@2ndquadrant.com> <4D49C482.4010707@vmsinfo.com> <4D49F0BA.9000901@2ndquadrant.com> <4D4A16BF.1020304@vmsinfo.com> <4D4A4844.3020409@2ndquadrant.com> <4D4AD9F6.6040903@vmsinfo.com> <4D4AE16E.9040807@peak6.com> <4D4B17B4.9030406@vmsinfo.com> <4D4B1F5B.4060403@peak6.com> <4D4B261B.6010303@vmsinfo.com> <4D4B2E8A.7010402@vmsinfo.com> <4D4B3395.6010007@agliodbs.com> <4D4B394E.9080505@vmsinfo.com> <4D4B5A73.3080302@agliodbs.com> Comments: In-reply-to Tobias Brox message dated "Thu, 10 Feb 2011 23:55:29 +0300" Date: Thu, 10 Feb 2011 16:12:12 -0500 Message-ID: <4660.1297372332@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201102/344 X-Sequence-Number: 42482 Tobias Brox writes: > I have no clue about how hints works in Oracle ... I've never been > working "enterprise level" on anything else than Postgres. Anyway, > today I just came over an interesting problem in our production > database today - and I think it would be a benefit to be able to > explicitly tell the planner what index to use (the dev team is adding > redundant attributes and more indexes to solve the problem - which > worries me, because we will run into serious problems as soon as there > won't be enough memory for all the frequently-used indexes). > We have users and transactions, and we have transaction types. The > transaction table is huge. The users are able to interactively check > their transaction listings online, and they have some simple filter > options available as well. Slightly simplified, the queries done > looks like this: > select * from account_transaction where account_id=? order by > created desc limit 25; > select * from account_transaction where trans_type_id in ( ... > long, hard-coded list ...) and account_id=? order by created desc > limit 25; > and we have indexes on: > account_transaction(account_id, created) > account_transaction(account_id, trans_type_id, created) Well, in this case the optimizer *is* smarter than you are, and the reason is that it remembers the correct rules for when indexes are useful. That second index is of no value for either query, because "in" doesn't work the way you're hoping. I understand the larger point you're trying to make, but this example also nicely illustrates the point being made on the other side, that "force the optimizer to use the index I think it should use" isn't a very good solution. regards, tom lane