Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vfd5P-0002ci-B3 for pgsql-bugs@arkaria.postgresql.org; Sun, 10 Nov 2013 22:02:27 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Vfd5O-00012K-O1 for pgsql-bugs@arkaria.postgresql.org; Sun, 10 Nov 2013 22:02:26 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vfd5N-00012D-On for pgsql-bugs@postgresql.org; Sun, 10 Nov 2013 22:02:25 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vfd5L-0005Kj-23 for pgsql-bugs@postgresql.org; Sun, 10 Nov 2013 22:02:25 +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 rAAM2MHk003913; Sun, 10 Nov 2013 17:02:22 -0500 From: Tom Lane To: m@pplcast.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #8533: JSON error caused by optimisation In-reply-to: References: Comments: In-reply-to m@pplcast.com message dated "Wed, 16 Oct 2013 19:43:23 -0000" Date: Sun, 10 Nov 2013 17:02:22 -0500 Message-ID: <3912.1384120942@sss.pgh.pa.us> X-Pg-Spam-Score: -0.5 (/) 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 m@pplcast.com writes: > Not sure if bug or feature, but the query below without the "offset 0" fails > with "ERROR: cannot extract field from a non-object", while the one with > succeeds as intended. Please excuse the messiness. Yeah, this is not surprising, since as you can see from the query plans, by default the planner will flatten the sub-select, and it ends up putting your json_isarray() function after the filter conditions it's meant to protect. That it does so is a feature, not a bug, because PL functions are by default assigned a higher cost than built-in C functions; so they'll be put at the end of any list of conditions to be checked at the same plan node. If you want something less ugly than the OFFSET 0 hack as a workaround, you could try assigning your function a small cost (less than 1). Another possible approach is to make the "select where not json_isarray" bit into an explicitly declared view, which you could mark as a SECURITY view to prevent the planner from changing the qual order. That might turn out badly from an optimization standpoint though. 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