Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W1nQm-0005kT-GA for pgsql-bugs@arkaria.postgresql.org; Sat, 11 Jan 2014 01:32:08 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1W1nQl-0005VU-Rl for pgsql-bugs@arkaria.postgresql.org; Sat, 11 Jan 2014 01:32:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W1nQk-0005VI-VI for pgsql-bugs@postgresql.org; Sat, 11 Jan 2014 01:32:07 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W1nQh-0006H1-CP for pgsql-bugs@postgresql.org; Sat, 11 Jan 2014 01:32:06 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id s0B1W2Dq020986; Fri, 10 Jan 2014 20:32:02 -0500 From: Tom Lane To: martin.junek@tracmap.co.nz cc: pgsql-bugs@postgresql.org Subject: Re: BUG #8771: Query execution plan broken after upgrade from 9.1.9 In-reply-to: References: Comments: In-reply-to martin.junek@tracmap.co.nz message dated "Thu, 09 Jan 2014 23:18:10 +0000" Date: Fri, 10 Jan 2014 20:32:02 -0500 Message-ID: <20985.1389403922@sss.pgh.pa.us> X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org martin.junek@tracmap.co.nz writes: > after upgrading from 9.1.9 to 9.1.11 one of our queries started to run > terribly slow (went from few miliseconds to hours). The problem is better > explained in the following SQL snippet (which is a very simplified version > of the problem). If you run it on 9.1.9, all the SELECTs evaluate in few > miliseconds, if you run it on 9.1.11, it will take probably hours (I didn't > have the patience to wait for it). I believe this is a result of this 9.1.11 change: * Avoid flattening a subquery whose SELECT list contains a volatile function wrapped inside a sub-SELECT (Tom Lane) This avoids unexpected results due to extra evaluations of the volatile function. full details of which can be found here: http://git.postgresql.org/gitweb/?p=postgresql.git&a=commitdiff&h=af38d140c71c21eda422fedc838525525d155cac That's an intentional change that is not going to get undone. If you don't like the results, I'd suggest fixing the "slow function" to get it marked as stable or immutable as appropriate. (The given example would be best marked stable, but I suppose it's just an example and not your real problem function.) When it's marked volatile, as this is by default, that discourages the planner from rearranging the query in ways that would change the number of function executions from what a naive implementation would suggest. 9.1.11 is a bit more discouraged than previous releases, but it's also less likely to produce surprising results when the function is genuinely volatile. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs