Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 14DAFD84656 for ; Fri, 8 Jun 2012 11:23:34 -0300 (ADT) Received: from mail-pb0-f46.google.com ([209.85.160.46]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Sd069-0001PW-A5 for pgsql-performance@postgresql.org; Fri, 08 Jun 2012 14:23:33 +0000 Received: by pbbrp8 with SMTP id rp8so2609986pbb.19 for ; Fri, 08 Jun 2012 07:23:20 -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:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=ZHb7b7Lgn7eyaCeGWzMy1ABiwH7nvro9Pcm6dzX+2n0=; b=Fc+BJv1+ao0SXSZHqhSBW0g0mqtmvUoKRiK1rVTfv4W4BPyK2+m3qgv6RJiixu6Qgt +/O9N+kygdvBTtrf9TVubWJGFOwgFuKKGlWt81NHgLyJ3bbfqVzl+aT2SQN9LBqVqaak 67dGk39Ixd3nDQdTjD4rllKen++iiRdmRA/N5lro5PeaOgp1N3sWhXEDa8iZyb4ZehV1 2+YsFKPM8N1QEnhrVaHGjhUlVm0EooR1jz/5RgdMiMgJEP5YBFah/7MVz4YAS6GADMx5 p+vSYzB8qE2Q7YJkzf5NBbY32Vhad7SYcCAJLWstyUROWdsFXxfF5VJ78JMLn2Kv9Ub+ 3xMQ== Received: by 10.68.239.164 with SMTP id vt4mr18428862pbc.166.1339165400641; Fri, 08 Jun 2012 07:23:20 -0700 (PDT) Received: from [192.168.11.3] ([114.95.165.117]) by mx.google.com with ESMTPS id jv6sm7990731pbc.40.2012.06.08.07.23.16 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 08 Jun 2012 07:23:19 -0700 (PDT) Message-ID: <4FD20AD0.3040902@gmail.com> Date: Fri, 08 Jun 2012 22:23:12 +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: Tom Lane CC: pgsql-performance@postgresql.org Subject: Re: how to change the index chosen in plan? References: <4FD1FF14.9060303@gmail.com> <11881.1339164658@sss.pgh.pa.us> In-Reply-To: <11881.1339164658@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Pg-Spam-Score: -2.6 (--) X-Archive-Number: 201206/43 X-Sequence-Number: 47069 No, it's not the analyze problem. For some other values on b.bid such as 9, 10, the plan is fine since there a a lot of rows in table b for them. But for some specific values such as 8 I want the plan changed. 于2012年6月8日 22:10:58,Tom Lane写到: > 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 >