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