Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WZiN7-0006AH-V2 for pgsql-performance@arkaria.postgresql.org; Mon, 14 Apr 2014 15:00:34 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WZiN6-00006l-Fg for pgsql-performance@arkaria.postgresql.org; Mon, 14 Apr 2014 15:00:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WZiMw-0008L9-Uz for pgsql-performance@postgresql.org; Mon, 14 Apr 2014 15:00:23 +0000 Received: from alexander.swishmail.com ([208.72.56.31]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WZiMp-0002iG-8W for pgsql-performance@postgresql.org; Mon, 14 Apr 2014 15:00:22 +0000 Received: (qmail 57395 invoked by uid 89); 14 Apr 2014 15:00:12 -0000 Received: from unknown (HELO ?192.168.0.198?) (eric.schwarzenbach@wrycan.com@209.6.206.194) by alexander.swishmail.com with ESMTPA; 14 Apr 2014 15:00:12 -0000 Message-ID: <534BF7E8.4090008@blackbrook.org> Date: Mon, 14 Apr 2014 10:59:52 -0400 From: Eric Schwarzenbach User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.5.0 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: Getting query plan alternatives from query planner? References: <1397486357.89780.YahooMailBasic@web122305.mail.ne1.yahoo.com> In-Reply-To: <1397486357.89780.YahooMailBasic@web122305.mail.ne1.yahoo.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org I don't know how anyone else feels about this, as I don't think I've seen this ever suggested, but my ideal would be a way to configure the database to recognize specific queries and to have a way of influencing its plan choice for that query. I'm intentionally wording that last part vaguely, as I'm not sure what would be best or practical there. Ideally, perhaps, would be to be able to store a particular plan for that query and have it always use it. I don't want either hints OR fence distortions in my application code, which might have to work with different versions of PostgreSQL with different optimization characteristics, different servers with different performance characteristics, or even different database products entirely. A solution to a server-side problem should live on the server not on the client. That's why I've always preferred PostgeSQL's server settings for tweaking the optimizer to the hints offered by other products. On 4/14/2014 10:39 AM, Kevin Grittner wrote: > Shaun Thomas wrote: > >> these issues tend to get solved through optimization fences. >> Reorganize a query into a CTE, or use the (gross) OFFSET 0 trick. >> How are these nothing other than unofficial hints? > Yeah, the cognitive dissonance levels get pretty high around this > issue. Some of the same people who argue strenuously against > adding hints about what plan should be chosen also argue against > having clearly equivalent queries optimize to the same plan because > they find the fact that they don't useful for coercing a decent > plan sometimes. That amounts to a hint, but obscure and > undocumented. (The OP may be wondering what this "OFFSET 0 trick" > is, and how he can use it.) > >> Well... they're worse, really. Hints can be deprecated, disabled >> in configs, or ignored in extreme cases. Optimization fences are >> truly forever. > +1 > > With explicit, documented hints, one could search for hints of a > particular type should the optimizer improve to the point where > they are no longer needed. It is harder to do that with subtle > differences in syntax choice. Figuring out which CTEs or LIMITs > were chosen because they caused optimization barriers rather than > for their semantic merit takes some effort. > > -- > Kevin Grittner > EDB: http://www.enterprisedb.com > The Enterprise PostgreSQL Company > > > -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance