Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TbCni-0003ed-Mh for pgsql-performance@postgresql.org; Wed, 21 Nov 2012 16:05:22 +0000 Received: from smtp-outbound-1.vmware.com ([208.91.2.12]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TbCng-0002fz-Qv for pgsql-performance@postgresql.org; Wed, 21 Nov 2012 16:05:21 +0000 Received: from sc9-mailhost2.vmware.com (sc9-mailhost2.vmware.com [10.113.161.72]) by smtp-outbound-1.vmware.com (Postfix) with ESMTP id 2CB6F283FA; Wed, 21 Nov 2012 08:05:20 -0800 (PST) Received: from zcs-prod-ext-mta-2.vmware.com (zcs-prod-ext-mta-2.vmware.com [10.113.62.224]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 27DA0B0426; Wed, 21 Nov 2012 08:05:20 -0800 (PST) Received: from localhost (localhost.localdomain [127.0.0.1]) by zcs-prod-ext-mta-2.vmware.com (Postfix) with ESMTP id 07D81C1A75; Wed, 21 Nov 2012 08:05:20 -0800 (PST) X-Virus-Scanned: amavisd-new at zcs-prod-ext-mta-2.vmware.com Received: from zcs-prod-ext-mta-2.vmware.com ([127.0.0.1]) by localhost (zcs-prod-ext-mta-2.vmware.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id o6DeFxLIU2WP; Wed, 21 Nov 2012 08:05:19 -0800 (PST) Received: from [192.168.1.90] (unknown [10.113.62.14]) by zcs-prod-ext-mta-2.vmware.com (Postfix) with ESMTPSA id 0FC99C1A0B; Wed, 21 Nov 2012 08:05:17 -0800 (PST) Message-ID: <50ACFBBD.30204@vmware.com> Date: Wed, 21 Nov 2012 18:05:17 +0200 From: Heikki Linnakangas Organization: VMware User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.10) Gecko/20121027 Icedove/10.0.10 MIME-Version: 1.0 To: Kevin Grittner CC: Craig Ringer , Craig James , Tom Lane , Claudio Freire , Merlin Moncure , David Greco , pgsql-performance@postgresql.org Subject: Re: Hints (was Poor performance using CTE) References: <20121121134232.68590@gmx.com> In-Reply-To: <20121121134232.68590@gmx.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -7.2 (-------) X-Archive-Number: 201211/231 X-Sequence-Number: 48597 On 21.11.2012 15:42, Kevin Grittner wrote: > Better, IMV, would be to identify what sorts of hints people actually > find useful, and use that as the basis for TODO items for optimizer > improvement as well as inventing clear ways to specify the desired > coercion. I liked the suggestion that a CTE which didn't need to be > materialized because of side-effects or multiple references have a > keyword. Personally, I think that AS MATERIALIZED x (SELECT ...) > would be preferable to AS x (SELECT ... OFFSET 0) as the syntax to > specify that. Rather than telling the planner what to do or not to do, I'd much rather have hints that give the planner more information about the tables and quals involved in the query. A typical source of bad plans is when the planner gets its cost estimates wrong. So rather than telling the planner to use a nested loop join for "a INNER JOIN b ON a.id = b.id", the user could tell the planner that there are only 10 rows that match the "a.id = b.id" qual. That gives the planner the information it needs to choose the right plan on its own. That kind of hints would be much less implementation specific and much more likely to still be useful, or at least not outright counter-productive, in a future version with a smarter planner. You could also attach that kind of hints to tables and columns, which would be more portable and nicer than decorating all queries. - Heikki