pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: m@pplcast.com
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #8533: JSON error caused by optimisation
Date: Sun, 10 Nov 2013 17:02:22 -0500
Message-ID: <3912.1384120942@sss.pgh.pa.us> (raw)
In-Reply-To: <E1VWX07-0005Yy-Qh@wrigleys.postgresql.org>
References: <E1VWX07-0005Yy-Qh@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

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



view thread (2+ messages)

Message-ID: <3912.1384120942@sss.pgh.pa.us>
Permalink:  ../3912.1384120942@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/3912.1384120942@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, m@pplcast.com
  Subject: Re: BUG #8533: JSON error caused by optimisation
  In-Reply-To: <3912.1384120942@sss.pgh.pa.us>
  References: <E1VWX07-0005Yy-Qh@wrigleys.postgresql.org> <3912.1384120942@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox