Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id BADC7632977 for ; Mon, 13 Sep 2010 06:53:59 -0300 (ADT) 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 83139-08 for ; Mon, 13 Sep 2010 09:53:51 +0000 (UTC) Received: from news.hub.org (news.hub.org [200.46.204.72]) by mail.postgresql.org (Postfix) with ESMTP id E71BF63232A for ; Mon, 13 Sep 2010 06:53:52 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.14.4/8.14.4) with ESMTP id o8D9rppn087101 for ; Mon, 13 Sep 2010 06:53:51 -0300 (ADT) (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.14.4/8.14.4/Submit) id o8D9lnXA085472 for pgsql-performance@postgresql.org; Mon, 13 Sep 2010 06:47:49 -0300 (ADT) (envelope-from news) From: Gaetano Mendola X-Newsgroups: pgsql.performance Subject: Useless sort by Date: Mon, 13 Sep 2010 11:47:24 +0200 Organization: Hub.Org Networking Services Lines: 27 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.10pre) Gecko/20100903 Shredder/3.1.4pre To: pgsql-performance@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.011 tagged_above=-10 required=5 tests=BAYES_40=-0.001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201009/53 X-Sequence-Number: 40256 Hi all, I have a view v_table defined as following: select a,b,c,d,e,f from t_table sort by a,b,c; the usage pattern of this view is the following: select distinct(a) from v_table; select distinct(b) from v_table where a = "XXX"; select distinct(c) from v_table where a = "XXX" and b = "YYYY"; because of that sort in the view definition the first query above takes not less than 3 seconds. I have solved this performance issue removing the sort from the view definition and putting it in the select reducing the time from > 3secons to < 150ms. Can not the optimizer take rid of that useless sort on those kind of queries ? Regards Gaetano Mendola