Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TaxOn-0006jc-Nl for pgsql-performance@postgresql.org; Tue, 20 Nov 2012 23:38:37 +0000 Received: from outmail149095.authsmtp.com ([62.13.149.95]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TaxOl-000573-Ub for pgsql-performance@postgresql.org; Tue, 20 Nov 2012 23:38:37 +0000 Received: from mail-c233.authsmtp.com (mail-c233.authsmtp.com [62.13.128.233]) by punt7.authsmtp.com (8.14.2/8.14.2/Kp) with ESMTP id qAKNcXeN024925; Tue, 20 Nov 2012 23:38:33 GMT Received: from ayaki.localdomain (124-148-90-153.dyn.iinet.net.au [124.148.90.153]) (authenticated bits=0) by mail.authsmtp.com (8.14.2/8.14.2/) with ESMTP id qAKNcRSq012805 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Tue, 20 Nov 2012 23:38:29 GMT Message-ID: <50AC1472.3050607@2ndQuadrant.com> Date: Wed, 21 Nov 2012 07:38:26 +0800 From: Craig Ringer Organization: 2nd Quadrant User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121029 Thunderbird/16.0.2 MIME-Version: 1.0 To: Claudio Freire CC: Merlin Moncure , David Greco , "pgsql-performance@postgresql.org" Subject: Re: Poor performance using CTE References: <187F6C10D2931A4386EE8E58E13857F612917154@BLUPRD0811MB413.namprd08.prod.outlook.com> In-Reply-To: X-Enigmail-Version: 1.4.5 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Server-Quench: 647d753c-336b-11e2-a49c-0025907707a1 X-AuthReport-Spam: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse X-AuthRoute: OCdxZQATClZeVg0b BQteCiN5VAwpPBRK HVkIKg5MJUcNSQVJ NksachtFagVbY1ZH HGQLWlZEUl57Wmt/ aAsfbAdZfEtKVxtj UFZIR1FNFgBqBAMA SF9vKWchFWYHeH9y bUZnEHhcVEE0c0J6 FklRFj4bZmRmOn0e URVaalJQeVBXfh9H b1l/U3QNZjQGKBg1 TUcABx0LExJlDREd egYKNxoKTFwFGSQ5 ThYJEH0yBkwDSG0Y EzFO X-Authentic-SMTP: 61633235383639.1021:706 X-AuthFastPath: 0 (Was 255) X-AuthSMTP-Origin: 124.148.90.153/2525 X-AuthVirus-Status: No virus detected - but ensure you scan with your own anti-virus system. X-Pg-Spam-Score: -2.6 (--) X-Archive-Number: 201211/216 X-Sequence-Number: 48582 On 11/21/2012 12:06 AM, Claudio Freire wrote: > I meant for postgres to do automatically. Rewriting as a join wouldn't > work as an optimization fence the way we're used to, but pushing > constraints upwards can only help (especially if highly selective). Because people are now used to using CTEs as query hints, it'd probably cause performance regressions in working queries. Perhaps more importantly, Pg would have to prove that doing so didn't change queries that invoked functions with side-effects to avoid changing the results of currently valid queries. -- Craig Ringer http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services