Re: Making jsonb_agg() faster

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

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Chao Li <li.evan.chao@gmail.com>
Cc: jian he <jian.universality@gmail.com>, pgsql-hackers@lists.postgresql.org
Date: 2025-11-20T18:56:37Z
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.

Attachments

I wrote:
> Chao Li <li.evan.chao@gmail.com> writes:
>> You left two “ugly hack” comments. Maybe add a short description for why they are hack and what can be improved in the future.

> It's the same ugly hack as before, I just formatted the code more
> legibly ... I didn't stop to look at whether there's a better way to
> do it.  Again, that seems like material for a different patch.

I took another look at that code and decided that it wasn't quite
as bad a hack as I first thought: it's relying on the upcoming
JsonbValueToJsonb call to wrap the scalar value into the right
array structure for a "raw scalar" JSONB.  Improving the comments
about what this code is doing is definitely within the charter of
my 0001 patch, so here's a new version that improves those two
comments.  Otherwise this is the same as v3.

			regards, tom lane