Re: BUG #14849: jsonb_build_object doesn't like VARIADIC calls very much

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Andrew Dunstan <andrew(dot)dunstan(at)2ndquadrant(dot)com>, Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Marko Tiikkaja <marko(at)joh(dot)to>, PostgreSQL mailing lists <pgsql-bugs(at)postgresql(dot)org>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: BUG #14849: jsonb_build_object doesn't like VARIADIC calls very much
Date: 2017-10-23 13:50:24
Message-ID: CAB7nPqR+XEVU=VZvAJrEVk9Hfn1gOdWHAuTzCSEOwBru2cCGoQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

On Mon, Oct 23, 2017 at 7:03 AM, Michael Paquier
<michael(dot)paquier(at)gmail(dot)com> wrote:
>> Looks good otherwise.
>
> My set of diffs for funcapi.h are actually that:
> * funcapi.h
> * Definitions for functions which return composite type and/or sets
> + * or work on VARIADIC inputs.
> [...]
> +/*----------
> + * Support to ease writing of functions dealing with VARIADIC inputs
> + *----------
> + *
> + * This function extracts a set of argument values, types and NULL markers
> + * for a given input function. This returns a set of data:
> + * - **values includes the set of Datum values extracted.
> + * - **types the data type OID for each element.
> + * - **nulls tracks if an element is NULL.
> + *
> + * convert_unknown set to true enforces conversion of unknown input type
> + * unknown to text.
> + * variadic_start tracks the argument number of the function call where the
> + * VARIADIC set of arguments begins.
> + *
> + * The return result is the number of elements stored. In the event of a
> + * NULL input, then the caller of this function ought to generate a NULL
> + * object as final result, and in this case a result value of -1 is used
> + * to be able to make the difference between an empty array or object.
> + */
> +extern int extract_variadic_args(FunctionCallInfo fcinfo, int variadic_start,
> + bool convert_unknown, Datum **values,
> Oid **types,
> + bool **nulls);
>
> Got this bit as well:
> * funcapi.c
> * Utility and convenience functions for fmgr functions that return
> - * sets and/or composite types.
> + * sets and/or composite types, or deal with VARIADIC inputs.
> *

Okay, attached is what I think a fully implemented patch should look
like. On top of what Andrew has done, I added and reworked the
following:
- removed duplicate error handling.
- documented the function in funcapi.h and funcapi.c.
- Added a new section in funcapi.h to outline that this is for support
of VARIADIC inputs.
I have added a commit message as well. Hope this helps.

format, concat and potentially count_nulls could take advantage of
this new function, though refactoring is left for later. I am fine to
do the legwork on a different thread. Changing count_nulls would also
switch it to a o(n^2), which is not cool either, so I think that it
could be left out. Still let's discuss that on another thread.
--
Michael

Attachment Content-Type Size
json_variadic_v6.patch application/octet-stream 27.5 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Alvaro Herrera 2017-10-23 14:03:57 Re: [pg_dump] not dumping some default privileges
Previous Message Feike Steenbergen 2017-10-23 13:16:40 Re: [pg_dump] not dumping some default privileges

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2017-10-23 15:12:51 Re: Proposal: Local indexes for partitioned table
Previous Message Amit Kapila 2017-10-23 12:50:34 Re: [POC] Faster processing at Gather node