Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 86C6F632AB5 for ; Mon, 28 Jun 2010 17:19:07 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 91853-03 for ; Mon, 28 Jun 2010 20:18:59 +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 5B991632A4F for ; Mon, 28 Jun 2010 17:19:00 -0300 (ADT) 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 o5SKIwW1003372; Mon, 28 Jun 2010 16:18:58 -0400 (EDT) To: Rajesh Kumar Mallah cc: Kevin Grittner , pgsql-performance@postgresql.org Subject: Re: order by slowing down a query by 80 times In-reply-to: References: <4C2862C90200002500032BCD@gw.wicourts.gov> <26902.1277734649@sss.pgh.pa.us> Comments: In-reply-to Rajesh Kumar Mallah message dated "Tue, 29 Jun 2010 01:26:50 +0530" Date: Mon, 28 Jun 2010 16:18:58 -0400 Message-ID: <3371.1277756338@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.51 tagged_above=-10 required=5 tests=BAYES_05=-0.5, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201006/505 X-Sequence-Number: 39361 Rajesh Kumar Mallah writes: > co_name_vec is actually the auxiliary tsvector column that is mantained via > a > an update trigger. and the index that you suggested is there . Well, in that case it's just a costing/statistics issue. The planner is probably estimating there are more tsvector matches than there really are, which causes it to think the in-order indexscan will terminate earlier than it really will, so it goes for that instead of a full scan and sort. If this is 8.4 then increasing the statistics target for the co_name_vec column should help that. In previous versions I'm not sure how much you can do about it other than raise random_page_cost, which is likely to be a net loss overall. regards, tom lane