Re: Making jsonb_agg() faster

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: jian he <jian.universality@gmail.com>
Cc: pgsql-hackers@lists.postgresql.org
Date: 2025-08-15T16:57:02Z
Lists: pgsql-hackers

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Fix jsonb_object_agg crash after eliminating null-valued pairs.

  2. Micro-optimize datatype conversions in datum_to_jsonb_internal.

  3. Remove fundamentally-redundant processing in jsonb_agg() et al.

  4. Revise APIs for pushJsonbValue() and associated routines.

  5. Add a macro for the declared typlen of type timetz.

jian he <jian.universality@gmail.com> writes:
> outcontext will always be NULL in 0001.
> that means copyScalarSubstructure is never really called.
> it also means that JsonbInState->MemoryContext  was always as NULL in 00001
> maybe we don't need JsonbInState->MemoryContext in 0001
> So 0001 refactoring change would be less invasive.

I think you're missing the point: per the commit message for 0001,

    The real reason for doing it is to provide a mechanism whereby
    pushJsonbValue() can be told to construct the JsonbValue tree
    in a context that is not CurrentMemoryContext.  That happens
    when a non-null "outcontext" is specified in the JsonbInState.
    No callers exercise that option in this patch, but the next
    patch in the series will make use of it.

If we didn't add the outcontext option in this step, we'd just
have to do so in the next one.

			regards, tom lane