Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 63963D84656 for ; Fri, 8 Jun 2012 10:33:38 -0300 (ADT) Received: from mail-pb0-f46.google.com ([209.85.160.46]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SczJm-0003Eq-7P for pgsql-performance@postgresql.org; Fri, 08 Jun 2012 13:33:37 +0000 Received: by pbbrp8 with SMTP id rp8so2555225pbb.19 for ; Fri, 08 Jun 2012 06:33:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; bh=6e9B4wiQLH5wXfFuSZS7/LaP/XWJ6Bvc9iBETO2vaeI=; b=Eix5qz19Q5y92j7MxWzdwjAJ7Fcgy06EF/lNn1iYdB2if8Oxm6BzZqn+wTzN0WXQMK 4zXkcgeaebcTukXilMZcxHWFZWvGwqNVV1X+g6Yxqb0+tkVuarrnh2snrSL6OnwMByIK E+oypJQz3CcZQk3bDmI1ythE/TEuH7GWqvwVtqASHwc8BIuuNGlTpmZWP/NNsFgFuNVZ K3hsNIHzZu8Qqt07U5k37S3zzk5rmU+1pFLdiI+xK6jWLfSXZwwe2Nn+ovJqGBcITecn AcABPmYvd2JZnKNaOcdQtGbMxkWQ9rCqj5Y8OWBvwbizhggJAPDmCH4+OTlfF/WGPgkD OrHw== Received: by 10.68.202.99 with SMTP id kh3mr19752257pbc.157.1339162399589; Fri, 08 Jun 2012 06:33:19 -0700 (PDT) Received: from [192.168.11.3] ([114.95.165.117]) by mx.google.com with ESMTPS id qt10sm7854908pbc.57.2012.06.08.06.33.12 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 08 Jun 2012 06:33:18 -0700 (PDT) Message-ID: <4FD1FF14.9060303@gmail.com> Date: Fri, 08 Jun 2012 21:33:08 +0800 From: Rural Hunter User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:13.0) Gecko/20120604 Thunderbird/13.0 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: how to change the index chosen in plan? Content-Type: text/plain; charset=GB18030; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.7 (--) X-Archive-Number: 201206/40 X-Sequence-Number: 47066 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. So I re-wrote the query as below: select a.* from a where a.aid in (select aid from b where bid=8) and a.col1=33 a.col2=44 But surprisingly, postgresql didn't change the plan. it still chose to index scan on a.col1. How can I re-wirte the query so postgresql will scan on b.bid first?