Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id BE601101438A for ; Thu, 1 Mar 2012 07:45:44 -0400 (AST) Received: from meteor.mejor.pl ([2001:470:1f15:1b61::2]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1S34S6-000716-4a for pgsql-performance@postgresql.org; Thu, 01 Mar 2012 11:45:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mejor.pl; s=cokolwiek; h=Content-Transfer-Encoding:Content-Type:Subject:To:MIME-Version:From:Date:Message-ID; bh=W1dB5kJvoQzxHCxgEVPkA1aBopDvRrB1MVtBw/xDKbU=; b=NGoVUPF4xb2xJAWiWtAbew6bnvqp/aDLpkkWX8YG9B7D/tSUL2Qfw5ns2y96++r0DLUs1X14z1ZGKEFEtIdFYje5t55m23unRNjNKEInScURZ3O3k+J9i0x7Z3U1dso4; Received: from cadera.waw.pl ([62.121.127.119] helo=[192.168.138.46]) by meteor.mejor.pl with esmtpsa (TLSv1:DHE-RSA-CAMELLIA256-SHA:256) (Exim 4.77) (envelope-from ) id 1S34Rs-0009F3-Mn for pgsql-performance@postgresql.org; Thu, 01 Mar 2012 12:45:28 +0100 Message-ID: <4F4F6158.7060200@mejor.pl> Date: Thu, 01 Mar 2012 12:45:28 +0100 From: =?UTF-8?B?TWFyY2luIE1pcm9zxYJhdw==?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.1) Gecko/20120213 Thunderbird/10.0.1 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: [planner] Ignore "order by" in subselect if parrent do count(*) Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.0 (--) X-Archive-Number: 201203/1 X-Sequence-Number: 46451 Hello, my example query (and explain) is: $ explain SELECT count(*) from (select * from users_profile order by id) u_p; QUERY PLAN --------------------------------------------------------------------------- Aggregate (cost=1.06..1.07 rows=1 width=0) -> Sort (cost=1.03..1.03 rows=2 width=572) Sort Key: users_profile.id -> Seq Scan on users_profile (cost=0.00..1.02 rows=2 width=572) (4 rows) Meseems "order by id" can be ignored by planner. It should speed up query without side effect. I know the query should be fixed but this is real and simplified query from real application. Does postgresql team think ppostgres should be smarter than user and fix user queries? If answer is positive please treat this as "feature request". Thank you and regards, Marcin.