Re: cache type info in json_agg and friends - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: cache type info in json_agg and friends
Date
Msg-id 20150914194127.GF55767@alvherre.pgsql
Whole thread Raw
In response to cache type info in json_agg and friends  (Andrew Dunstan <andrew@dunslane.net>)
Responses Re: cache type info in json_agg and friends  (Andrew Dunstan <andrew@dunslane.net>)
List 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



pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: cache type info in json_agg and friends
Next
From: Teodor Sigaev
Date:
Subject: Re: cache type info in json_agg and friends