Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 89EA7D84656 for ; Fri, 8 Jun 2012 11:11:12 -0300 (ADT) Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SczuB-00019M-UC for pgsql-performance@postgresql.org; Fri, 08 Jun 2012 14:11:12 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id q58EAwKg011882; Fri, 8 Jun 2012 10:10:58 -0400 (EDT) From: Tom Lane To: Rural Hunter cc: pgsql-performance@postgresql.org Subject: Re: how to change the index chosen in plan? In-reply-to: <4FD1FF14.9060303@gmail.com> References: <4FD1FF14.9060303@gmail.com> Comments: In-reply-to Rural Hunter message dated "Fri, 08 Jun 2012 21:33:08 +0800" Date: Fri, 08 Jun 2012 10:10:58 -0400 Message-ID: <11881.1339164658@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201206/42 X-Sequence-Number: 47068 Rural Hunter writes: > I have a query like this: > select a.* from a inner join b on a.aid=b.aid where a.col1=33 a.col2=44 > and b.bid=8 > postgresql selected the index on a.col1 then selected the index on > b.bid. But in my situation, I know that the query will be faster if it > chose the index on b.bid first since there are only a few rows with > value 8. If you know that and the planner doesn't, maybe ANALYZE is called for. regards, tom lane