Re: cache type info in json_agg and friends

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: cache type info in json_agg and friends
Date: 2015-09-14 19:41:27
Message-ID: 20150914194127.GF55767@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Andrew Dunstan wrote:

> Currently, json_agg, jsonb_agg, json_object_agg and jsonb_object_agg do type
> classification on their arguments on each call to the transition function.
> This is quite unnecessary, as the argument types won't change. This patch
> remedies the defect by caching the necessary values in the aggregate state
> object.

Seems a reasonable idea to me. This is 9.6 only, right?

What's the reason for this pattern?

! json_categorize_type(val_type,&tcategory, &outfuncoid);
! state->val_category = tcategory;
! state->val_output_func = outfuncoid;

I think you could just as well call json_categorize_type() with the
final pointer values, and save the two separate variables, as there is
no gain in clarity or ease of reading; I mean

! json_categorize_type(tmptyp, &state->val_category, &state->val_output_func);

Also, and this is not new in this patch, this code reuses a variable
named "val_type" for both values and keys, which reads a bit odd.

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Paul Jungwirth 2015-09-14 19:41:35 Re: Review: GiST support for UUIDs
Previous Message Andrew Dunstan 2015-09-14 19:22:35 cache type info in json_agg and friends