* and determine the element type information.
*/
static DatumArray *
-make_datum_array(ProxyFunction *func, ArrayType *v, Oid elem_type)
+make_datum_array(ProxyFunction *func, ArrayType *v, ProxyType *array_type)
{
DatumArray *da = palloc0(sizeof(*da));
- da->type = plproxy_find_type_info(func, elem_type, true);
+ da->type = plproxy_get_elem_type(func, array_type, true);
if (v)
deconstruct_array(v,
plproxy_error(func, "split multi-dimensional arrays are not supported");
}
- arrays_to_split[i] = make_datum_array(func, v, func->arg_types[i]->elem_type);
+ arrays_to_split[i] = make_datum_array(func, v, func->arg_types[i]);
/* Check that the element counts match */
if (split_array_len < 0)
bool by_value; /* False if Datum is a pointer to data */
char alignment; /* Type alignment */
bool is_array; /* True if array */
- Oid elem_type; /* Array element type */
+ Oid elem_type_oid; /* Array element type oid */
+ struct ProxyType *elem_type_t; /* Elem type info, filled lazily */
short length; /* Type length */
/* I/O functions */
/* type.c */
ProxyComposite *plproxy_composite_info(ProxyFunction *func, TupleDesc tupdesc);
ProxyType *plproxy_find_type_info(ProxyFunction *func, Oid oid, bool for_send);
+ProxyType *plproxy_get_elem_type(ProxyFunction *func, ProxyType *type, bool for_send);
char *plproxy_send_type(ProxyType *type, Datum val, bool allow_bin, int *len, int *fmt);
Datum plproxy_recv_type(ProxyType *type, char *str, int len, bool bin);
HeapTuple plproxy_recv_composite(ProxyComposite *meta, char **values, int *lengths, int *fmts);
if (split_support && IS_SPLIT_ARG(func, idx))
/* for SPLIT arguments use array element type instead */
- types[i] = func->arg_types[idx]->elem_type;
+ types[i] = func->arg_types[idx]->elem_type_oid;
else
types[i] = func->arg_types[idx]->type_oid;
}
if (type->name)
pfree(type->name);
+ if (type->elem_type_t)
+ plproxy_free_type(type->elem_type_t);
+
/* hopefully I/O functions do not use ->fn_extra */
pfree(type);
type->by_value = s_type->typbyval;
type->name = plproxy_func_strdup(func, namebuf);
type->is_array = (s_type->typelem != 0 && s_type->typlen == -1);
- type->elem_type = s_type->typelem;
+ type->elem_type_oid = s_type->typelem;
+ type->elem_type_t = NULL;
type->alignment = s_type->typalign;
type->length = s_type->typlen;
return type;
}
+/* Get cached type info for array elems */
+ProxyType *plproxy_get_elem_type(ProxyFunction *func, ProxyType *type, bool for_send)
+{
+ if (!type->elem_type_t)
+ type->elem_type_t = plproxy_find_type_info(func, type->elem_type_oid, for_send);
+ return type->elem_type_t;
+}
/* Convert a Datum to parameter for libpq */
char *