Re: jsonpath

From: Nikita Glukhov <n(dot)gluhov(at)postgrespro(dot)ru>
To: Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>, Alexander Korotkov <a(dot)korotkov(at)postgrespro(dot)ru>
Cc: Oleg Bartunov <obartunov(at)postgrespro(dot)ru>, Michael Paquier <michael(at)paquier(dot)xyz>, Stas Kelvich <s(dot)kelvich(at)postgrespro(dot)ru>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>, David Steele <david(at)pgmasters(dot)net>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Andrew Dunstan <andrew(dot)dunstan(at)2ndquadrant(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Subject: Re: jsonpath
Date: 2019-01-28 23:18:23
Message-ID: 9f5f1247-29f4-17cd-edd9-38e9bcd95b14@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 28.01.2019 16:50, Tomas Vondra wrote:

> On 1/28/19 1:22 AM, Alexander Korotkov wrote:
>> * I decided to change behavior of jsonb_path_match() to throw as less
>> errors as possible. The reason is that it's used to implement
>> potentially (patch is pending) indexable operator. Index scan is not
>> always capable to throw as many errors and sequential scan. So, it's
>> better to not introduce extra possible index scan and sequential scan
>> results divergence.
> Hmmm, can you elaborate a bit more? Which errors were thrown before and
> are not thrown with the current patch version?

In the previous version of the patch jsonb_path_match() threw error when
jsonpath did not return a singleton value, but in the last version in such cases
NULL is returned. This problem arises because we cannot guarantee at compile
time that jsonpath expression used in jsonb_path_match() is a predicate.
Predicates by standard can return only True, False, and Unknown (errors occurred
during execution of their operands are transformed into Unknown values), so
predicates cannot throw errors, and there are no problems with errors.

GIN does not attempt to search non-predicate expressions, so there may be no
problem even we throw "not a singleton" error.

Here I want to remind that ability to use predicates in the root of jsonpath
expression is an our extension to standard that was created specially for the
operator @@. By standard predicates are allowed only in filters. Without this
extension we are still able to rewrite @@ using @?:
jsonb @@ 'predicate' is equivalent to
jsonb @? '$ ? (predicate)'
but such @? expression is a bit slower to execute and a bit verbose to write.

If we introduced special type 'jsonpath_predicate', then we could solve the
problem by checking the type of jsonpath expression at compile-time.

Another problem with error handling is that jsonb_path_query*() functions
always throw SQL/JSON errors and there is no easy and effective way to emulate
NULL ON ERROR behavior, which is used by default in SQL/JSON functions. So I
think it's worth trying to add some kind of flag 'throwErrors' to
jsonb_path_query*() functions.

--
Nikita Glukhov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

In response to

Responses

  • Re: jsonpath at 2019-01-29 01:00:19 from Alexander Korotkov

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2019-01-28 23:49:33 Re: Why are we PageInit'ing buffers in RelationAddExtraBlocks()?
Previous Message Tom Lane 2019-01-28 23:08:59 Re: Why are we PageInit'ing buffers in RelationAddExtraBlocks()?