pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Nikita Glukhov <n.gluhov@postgrespro.ru>
To: Alexander Korotkov <a.korotkov@postgrespro.ru>
Cc: Tomas Vondra <tomas.vondra@2ndquadrant.com>
Cc: Michael Paquier <michael@paquier.xyz>
Cc: Stas Kelvich <s.kelvich@postgrespro.ru>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Cc: Thomas Munro <thomas.munro@enterprisedb.com>
Cc: David Steele <david@pgmasters.net>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: Oleg Bartunov <obartunov@gmail.com>
Cc: Pavel Stehule <pavel.stehule@gmail.com>
Subject: Re: jsonpath
Date: Mon, 21 Jan 2019 16:56:46 +0300
Message-ID: <a37b47a8-d853-b9ba-9b61-2e87ecc783b2@postgrespro.ru> (raw)
In-Reply-To: <CAPpHfdtq0b_g9MmDPpAOFkxXSH93TrJCkxNc5EmJktUJ0tuZtA@mail.gmail.com>
References: <CAA8=A796mY7kJdKARt7B+faW70-c8mRh+Ff_joBJ+NyCFLv3Gg@mail.gmail.com>
	<42272F2B-16D1-43D6-B22F-273AE1DA6D6B@postgrespro.ru>
	<715c1c44-9bb9-6b9f-7c59-61b66578f107@postgrespro.ru>
	<20181002023317.GI11712@paquier.xyz>
	<063560d8-bc0b-945b-8796-5ba998d79dc6@2ndquadrant.com>
	<9a175c2d-b0a9-475f-078b-febc185282ff@postgrespro.ru>
	<86a0e7df-443b-3f20-70b0-655a1f5dcbb2@2ndquadrant.com>
	<2265b7fe-3b0e-c437-fe15-ac1807319b73@2ndquadrant.com>
	<64e3108c-888f-092e-30a2-58dea157707e@postgrespro.ru>
	<43e52ed7-9c21-db2c-693a-9245f9e8ce2a@2ndquadrant.com>
	<38018365-5793-2827-e3c1-5a3b259fb6ae@postgrespro.ru>
	<CAPpHfdvVyXsD1gSwVB7A2C07Mx_6XZOOpEBqO_Le11mYJyq8YQ@mail.gmail.com>
	<885de241-5a51-29c8-a6b3-f1dda22aba13@postgrespro.ru>
	<CAPpHfdsA09V3s5Q6gtCgYMmyQPOFAj7=Ez1bb7Q0eriFjJugkQ@mail.gmail.com>
	<dea8e62f-001d-671f-e3ad-8a7f9cf318d0@2ndquadrant.com>
	<CAPpHfdtYvffCJfChnFMcOOP6O0RgJVkXy1-_1=teFc8aRJUY7g@mail.gmail.com>
	<CAPpHfdtq0b_g9MmDPpAOFkxXSH93TrJCkxNc5EmJktUJ0tuZtA@mail.gmail.com>

On 20.01.2019 2:45, Alexander Korotkov wrote:

> 3) How do we calculate the "id" property returned by keyvalue()
> function?  It's not documented.  Even presence of "id" columns isn't
> documented.  Standard stands that it's implementation-depended
> indetifier of object holding key-value pair.  The way of its
> calculation is also not clear from the code.  Why do we need constant
> of 10000000000?
>
>                  id = jb->type != jbvBinary ? 0 :
>                      (int64)((char *) jb->val.binary.data -
>                              (char *) cxt->baseObject.jbc);
>                  id += (int64) cxt->baseObject.id * INT64CONST(10000000000);

I decided to construct object id from the two parts: base object id and its
binary offset in its base object's jsonb:

object_id = 10000000000 * base_object_id + object_offset_in_base_object


10000000000 (10^10) -- is a first round decimal number greater than 2^32
(maximal offset in jsonb).  Decimal multiplier is used here to improve the
readability of identifiers.


Base object is usually a root object of the path: context item '$' or path
variable '$var', literals can't produce objects for now.  But if the path
contains generated objects (.keyvalue() itself, for example), then they become
base object for the subsequent .keyvalue().  See example:

'$.a.b.keyvalue().value.keyvalue()' :
  - base for the first .keyvalue() is '$'
  - base for the second .keyvalue() is '$.a.b.keyvalue()'


Id of '$' is 0.
Id of '$var' is its ordinal (positive) number in the list of variables.
Ids for generated objects are assigned using global counter
'JsonPathExecContext.generatedObjectId' starting from 'number_of_vars + 1'.


Corresponding comments will be added in the upcoming version of the patches.

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

view thread (198+ messages)  latest in thread

Message-ID: <a37b47a8-d853-b9ba-9b61-2e87ecc783b2@postgrespro.ru>
Permalink:  ../a37b47a8-d853-b9ba-9b61-2e87ecc783b2@postgrespro.ru/
Also on:    postgresql.org/message-id/a37b47a8-d853-b9ba-9b61-2e87ecc783b2@postgrespro.ru

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: n.gluhov@postgrespro.ru, a.korotkov@postgrespro.ru, tomas.vondra@2ndquadrant.com, michael@paquier.xyz, s.kelvich@postgrespro.ru, thomas.munro@enterprisedb.com, david@pgmasters.net, tgl@sss.pgh.pa.us, andrew.dunstan@2ndquadrant.com, robertmhaas@gmail.com, obartunov@gmail.com, pavel.stehule@gmail.com
  Subject: Re: jsonpath
  In-Reply-To: <a37b47a8-d853-b9ba-9b61-2e87ecc783b2@postgrespro.ru>

* 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