/
funcarray.c
752 lines (659 loc) · 17.7 KB
/
funcarray.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
/*----------------------------------------------------------------------------
* funcarray.c
* a set of functional array procedures
*
* All the procedures optimze process if the element type is byval and
* fixed format and lambda function is strict and array has no NULLs. In
* the optimization, lambda function is not allowed to return NULL, so if
* you expect lambda function returning NULL sometimes, mark it as
* non-strict even though it doesn't accept NULL (which means you have to
* modify it so that it accepts NULL input).
*---------------------------------------------------------------------------*/
#include "postgres.h"
#include "access/tupmacs.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_type.h"
#include "nodes/makefuncs.h"
#include "nodes/nodes.h"
#include "parser/parse_coerce.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/syscache.h"
PG_MODULE_MAGIC;
PG_FUNCTION_INFO_V1(maparray);
PG_FUNCTION_INFO_V1(reducearray);
PG_FUNCTION_INFO_V1(filterarray);
/*
* A small version of ArrayMetaState + FmgrInfo
*/
typedef struct
{
Oid element_type;
int16 typlen;
bool typbyval;
char typalign;
FmgrInfo flinfo;
char optimize; /* 'i', 's' */
} MapContext;
/* prototype */
static bool check_lambda_type(Oid procid, Oid element_type,
Oid returned_type, int nargs);
Datum maparray(PG_FUNCTION_ARGS);
Datum reducearray(PG_FUNCTION_ARGS);
Datum filterarray(PG_FUNCTION_ARGS);
/*
* check_lambda_type
* Check if the argument type and return type match the input type.
*
* lambda function accepts required arguments of array's element type and
* returns the specified type. Polymorphoic types are allowed.
* Note that variadic functions aren't supported so far.
*/
static bool
check_lambda_type(Oid procid, Oid element_type, Oid returned_type, int nargs)
{
HeapTuple ftup;
Form_pg_proc pform;
oidvector *argtypes;
bool isnull;
int i;
Oid *types;
Oid coerce_funcid;
ftup = SearchSysCache(PROCOID, ObjectIdGetDatum(procid), 0, 0, 0);
if (!HeapTupleIsValid(ftup))
elog(ERROR, "cache lookup failed for function %u", procid);
pform = (Form_pg_proc) GETSTRUCT(ftup);
/* return type is binary coercible to input type? */
if (!can_coerce_type(1,
&pform->prorettype, &returned_type, COERCION_IMPLICIT))
{
ReleaseSysCache(ftup);
return false;
}
/* lambda accepts exactly required number of arguments */
if (pform->pronargs != nargs)
{
ReleaseSysCache(ftup);
return false;
}
argtypes = (oidvector *) SysCacheGetAttr(PROCOID,
ftup, Anum_pg_proc_proargtypes, &isnull);
if (isnull)
{
ReleaseSysCache(ftup);
return false;
}
/* argument type must match the input type */
types = (Oid *) ARR_DATA_PTR(argtypes);
for(i = 0; i < nargs; i++)
{
Oid argtype = types[i];
if (!can_coerce_type(1, &element_type, &argtype, COERCION_IMPLICIT))
{
ReleaseSysCache(ftup);
return false;
}
/*
* can_coerce_type() doesn't report COERCION_PATH_FUNC case.
* We need binary coercible case only.
*/
if (find_coercion_pathway(argtype,
element_type, COERCION_IMPLICIT, &coerce_funcid) !=
COERCION_PATH_RELABELTYPE)
{
ReleaseSysCache(ftup);
return false;
}
}
ReleaseSysCache(ftup);
return true;
}
Datum
maparray(PG_FUNCTION_ARGS)
{
ArrayType *oldarray = PG_GETARG_ARRAYTYPE_P(0);
RegProcedure procid = PG_GETARG_OID(1);
MapContext *mc;
ArrayType *newarray;
if (fcinfo->flinfo->fn_extra == NULL ||
((MapContext *) fcinfo->flinfo->fn_extra)->flinfo.fn_oid != procid)
{
/* set up context */
MemoryContext oldcontext;
if (fcinfo->flinfo->fn_extra)
pfree(fcinfo->flinfo->fn_extra);
oldcontext = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
mc = (MapContext *) palloc(sizeof(MapContext));
mc->element_type = ARR_ELEMTYPE(oldarray);
get_typlenbyvalalign(ARR_ELEMTYPE(oldarray),
&mc->typlen, &mc->typbyval, &mc->typalign);
fmgr_info(procid, &mc->flinfo);
mc->optimize = 0;
if (mc->typlen == sizeof(int32) && mc->typbyval &&
mc->typalign == 'i')
{
mc->optimize = 'i';
}
else if (mc->typlen == sizeof(int64) && mc->typbyval &&
mc->typalign == 'd')
{
mc->optimize = 'd';
}
else if (mc->typlen == sizeof(int16) && mc->typbyval &&
mc->typalign == 's')
{
mc->optimize = 's';
}
{
/* param is dummy for polymorphic argument */
Param *param = makeNode(Param);
param->paramkind = PARAM_EXTERN;
param->paramtype = mc->element_type;
param->paramtypmod = -1; /* function input has always -1 */
param->location = -1;
mc->flinfo.fn_expr = (Node *) makeFuncExpr(
procid,
mc->element_type,
list_make1(param),
COERCE_EXPLICIT_CAST);
}
fcinfo->flinfo->fn_extra = (void *) mc;
/* type check */
if (!check_lambda_type(procid, mc->element_type, mc->element_type, 1))
{
elog(ERROR, "function %s type mismatch",
format_procedure(procid));
}
MemoryContextSwitchTo(oldcontext);
}
else
{
/* restore the previous call info */
mc = (MapContext *) fcinfo->flinfo->fn_extra;
}
if (mc->optimize > 0 && !ARR_HASNULL(oldarray) && mc->flinfo.fn_strict)
{
int i, nelems;
size_t bytes;
FunctionCallInfoData myinfo;
bytes = ARR_SIZE(oldarray);
newarray = DatumGetArrayTypePCopy(oldarray);
nelems = ArrayGetNItems(ARR_NDIM(oldarray), ARR_DIMS(oldarray));
InitFunctionCallInfoData(myinfo, &mc->flinfo, 1, NULL, NULL);
if (mc->optimize == 'i')
{
/* optimization for int4 without null */
int32 *oldints = (int32 *) ARR_DATA_PTR(oldarray);
int32 *newints = (int32 *) ARR_DATA_PTR(newarray);
for(i = 0; i < nelems; i++)
{
myinfo.arg[0] = Int32GetDatum(oldints[i]);
newints[i] = DatumGetInt32(FunctionCallInvoke(&myinfo));
if (myinfo.isnull)
{
elog(ERROR, "function %s returned NULL",
format_procedure(mc->flinfo.fn_oid));
}
}
}
else if (mc->optimize == 'd')
{
/*
* optimization for int8 wtihout null
* Note that this path is processed only when int8 is byval.
*/
int64 *oldints = (int64 *) ARR_DATA_PTR(oldarray);
int64 *newints = (int64 *) ARR_DATA_PTR(newarray);
for(i = 0; i < nelems; i++)
{
myinfo.arg[0] = Int64GetDatum(oldints[i]);
newints[i] = DatumGetInt64(FunctionCallInvoke(&myinfo));
if (myinfo.isnull)
{
elog(ERROR, "function %s returned NULL",
format_procedure(mc->flinfo.fn_oid));
}
}
}
else if (mc->optimize == 's')
{
/* optimization for int2 without null */
int16 *oldints = (int16 *) ARR_DATA_PTR(oldarray);
int16 *newints = (int16 *) ARR_DATA_PTR(newarray);
for(i = 0; i < nelems; i++)
{
myinfo.arg[0] = Int16GetDatum(oldints[i]);
newints[i] = DatumGetInt16(FunctionCallInvoke(&myinfo));
if (myinfo.isnull)
{
elog(ERROR, "function %s returned NULL",
format_procedure(mc->flinfo.fn_oid));
}
}
}
else
{
elog(ERROR, "unknown optimization code = %c", mc->optimize);
}
}
else
{
/*
* variable length element types:
* speed is secondary here, but flexibility is primary.
*/
Datum *values;
bool *nulls;
int i, nelems;
deconstruct_array(oldarray, mc->element_type,
mc->typlen, mc->typbyval, mc->typalign,
&values, &nulls, &nelems);
for(i = 0; i < nelems; i++)
{
if (!nulls[i] || !mc->flinfo.fn_strict)
{
FunctionCallInfoData myinfo;
InitFunctionCallInfoData(myinfo, &mc->flinfo, 1, NULL, NULL);
myinfo.arg[0] = values[i];
myinfo.argnull[0] = nulls[i];
values[i] = FunctionCallInvoke(&myinfo);
nulls[i] = myinfo.isnull;
}
}
newarray = construct_md_array(values, nulls, ARR_NDIM(oldarray),
ARR_DIMS(oldarray), ARR_LBOUND(oldarray),
mc->element_type, mc->typlen,
mc->typbyval, mc->typalign);
pfree(values);
pfree(nulls);
}
PG_RETURN_ARRAYTYPE_P(newarray);
}
Datum
reducearray(PG_FUNCTION_ARGS)
{
ArrayType *array = PG_GETARG_ARRAYTYPE_P(0);
RegProcedure procid = PG_GETARG_OID(1);
MapContext *mc;
Datum result = 0;
if (fcinfo->flinfo->fn_extra == NULL ||
((MapContext *) fcinfo->flinfo->fn_extra)->flinfo.fn_oid != procid)
{
/* set up context */
MemoryContext oldcontext;
if (fcinfo->flinfo->fn_extra)
pfree(fcinfo->flinfo->fn_extra);
oldcontext = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
mc = (MapContext *) palloc(sizeof(MapContext));
mc->element_type = ARR_ELEMTYPE(array);
get_typlenbyvalalign(ARR_ELEMTYPE(array),
&mc->typlen, &mc->typbyval, &mc->typalign);
fmgr_info(procid, &mc->flinfo);
mc->optimize = 0;
if (mc->typlen == sizeof(int32) && mc->typbyval &&
mc->typalign == 'i')
{
mc->optimize = 'i';
}
else if (mc->typlen == sizeof(int64) && mc->typbyval &&
mc->typalign == 'd')
{
mc->optimize = 'd';
}
else if (mc->typlen == sizeof(int16) && mc->typbyval &&
mc->typalign == 's')
{
mc->optimize = 's';
}
{
/* param is dummy for polymorphic argument */
Param *param = makeNode(Param);
param->paramkind = PARAM_EXTERN;
param->paramtype = mc->element_type;
param->paramtypmod = -1; /* function input has always -1 */
param->location = -1;
mc->flinfo.fn_expr = (Node *) makeFuncExpr(
procid,
mc->element_type,
list_make2(param, copyObject(param)),
COERCE_EXPLICIT_CAST);
}
fcinfo->flinfo->fn_extra = (void *) mc;
/* type check */
if (!check_lambda_type(procid, mc->element_type, mc->element_type, 2))
{
elog(ERROR, "function %s type mismatch",
format_procedure(procid));
}
MemoryContextSwitchTo(oldcontext);
}
else
{
mc = (MapContext *) fcinfo->flinfo->fn_extra;
}
if (mc->optimize > 0 && !ARR_HASNULL(array) && mc->flinfo.fn_strict)
{
int i, nelems;
FunctionCallInfoData myinfo;
nelems = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
InitFunctionCallInfoData(myinfo, &mc->flinfo, 2, NULL, NULL);
if (nelems == 0)
{
PG_RETURN_NULL();
}
if (mc->optimize == 'i')
{
/* optimization for int4 without null */
int32 *ints = (int32 *) ARR_DATA_PTR(array);
myinfo.arg[0] = Int32GetDatum(ints[0]);
myinfo.argnull[0] = false;
myinfo.argnull[1] = false;
for(i = 1; i < nelems; i++)
{
myinfo.arg[1] = Int32GetDatum(ints[i]);
myinfo.arg[0] = FunctionCallInvoke(&myinfo);
if (myinfo.isnull)
{
elog(ERROR, "function %s returned NULL",
format_procedure(mc->flinfo.fn_oid));
}
}
result = Int32GetDatum(myinfo.arg[0]);
}
else if (mc->optimize == 'd')
{
/*
* optimization for int8 without null.
* Note that this path is processed only when int8 is byval.
*/
int64 *ints = (int64 *) ARR_DATA_PTR(array);
myinfo.arg[0] = Int64GetDatum(ints[0]);
myinfo.argnull[0] = false;
myinfo.argnull[1] = false;
for(i = 1; i < nelems; i++)
{
myinfo.arg[1] = Int64GetDatum(ints[i]);
myinfo.arg[0] = FunctionCallInvoke(&myinfo);
if (myinfo.isnull)
{
elog(ERROR, "function %s returned NULL",
format_procedure(mc->flinfo.fn_oid));
}
}
result = Int64GetDatum(myinfo.arg[0]);
}
else if (mc->optimize == 's')
{
/* optimization for int2 without null */
uint16 *ints = (uint16 *) ARR_DATA_PTR(array);
myinfo.arg[0] = Int16GetDatum(ints[0]);
myinfo.argnull[0] = false;
myinfo.argnull[1] = false;
for(i = 1; i < nelems; i++)
{
myinfo.arg[1] = Int16GetDatum(ints[i]);
myinfo.arg[0] = FunctionCallInvoke(&myinfo);
if (myinfo.isnull)
{
elog(ERROR, "function %s returned NULL",
format_procedure(mc->flinfo.fn_oid));
}
}
result = Int16GetDatum(myinfo.arg[0]);
}
else
{
elog(ERROR, "unknown optimization code %c", mc->optimize);
}
}
else
{
/*
* variable length element types:
* speed is secondary here, but flexibility is primary.
*/
Datum *values;
bool *nulls;
int i, nelems;
bool isnull = true;
deconstruct_array(array, mc->element_type,
mc->typlen, mc->typbyval, mc->typalign,
&values, &nulls, &nelems);
if (nelems == 0)
{
PG_RETURN_NULL();
}
for(i = 0; i < nelems; i++)
{
if (nulls[i] && mc->flinfo.fn_strict)
{
continue;
}
if (isnull)
{
result = values[i];
isnull = false;
}
else
{
FunctionCallInfoData myinfo;
InitFunctionCallInfoData(myinfo, &mc->flinfo, 2, NULL, NULL);
myinfo.arg[0] = result;
myinfo.argnull[0] = false;
myinfo.arg[1] = values[i];
myinfo.argnull[1] = nulls[i];
result = FunctionCallInvoke(&myinfo);
}
}
pfree(values);
pfree(nulls);
if (isnull)
{
PG_RETURN_NULL();
}
}
PG_RETURN_DATUM(result);
}
Datum
filterarray(PG_FUNCTION_ARGS)
{
ArrayType *oldarray = PG_GETARG_ARRAYTYPE_P(0);
RegProcedure procid = PG_GETARG_OID(1);
MapContext *mc;
ArrayType *newarray;
if (ARR_NDIM(oldarray) == 0)
PG_RETURN_ARRAYTYPE_P(oldarray);
else if (ARR_NDIM(oldarray) != 1)
elog(ERROR, "cannot accept >= 2 dim");
if (fcinfo->flinfo->fn_extra == NULL ||
((MapContext *) fcinfo->flinfo->fn_extra)->flinfo.fn_oid != procid)
{
/* set up context */
MemoryContext oldcontext;
oldcontext = MemoryContextSwitchTo(fcinfo->flinfo->fn_mcxt);
mc = (MapContext *) palloc(sizeof(MapContext));
mc->element_type = ARR_ELEMTYPE(oldarray);
get_typlenbyvalalign(ARR_ELEMTYPE(oldarray),
&mc->typlen, &mc->typbyval, &mc->typalign);
fmgr_info(procid, &mc->flinfo);
mc->optimize = 0;
if (mc->typlen == sizeof(int32) && mc->typbyval &&
mc->typalign == 'i')
{
mc->optimize = 'i';
}
else if (mc->typlen == sizeof(int64) && mc->typbyval &&
mc->typalign == 'd')
{
mc->optimize = 'd';
}
else if (mc->typlen == sizeof(int16) && mc->typbyval &&
mc->typalign == 's')
{
mc->optimize = 's';
}
{
/* param is dummy for polymorphic argument */
Param *param = makeNode(Param);
param->paramkind = PARAM_EXTERN;
param->paramtype = mc->element_type;
param->paramtypmod = -1; /* function input has always -1 */
param->location = -1;
mc->flinfo.fn_expr = (Node *) makeFuncExpr(
procid,
mc->element_type,
list_make1(param),
COERCE_EXPLICIT_CAST);
}
fcinfo->flinfo->fn_extra = (void *) mc;
if (!check_lambda_type(procid, mc->element_type, BOOLOID, 1))
{
elog(ERROR, "function %s type mismatch",
format_procedure(procid));
}
MemoryContextSwitchTo(oldcontext);
}
else
{
mc = (MapContext *) fcinfo->flinfo->fn_extra;
}
if (mc->optimize > 0 && !ARR_HASNULL(oldarray) && mc->flinfo.fn_strict)
{
int i, nelems;
FunctionCallInfoData myinfo;
newarray = DatumGetArrayTypePCopy(oldarray);
nelems = ArrayGetNItems(ARR_NDIM(oldarray), ARR_DIMS(oldarray));
InitFunctionCallInfoData(myinfo, &mc->flinfo, 1, NULL, NULL);
myinfo.argnull[0] = false;
if (mc->optimize == 'i')
{
int32 *oldints = (int32 *) ARR_DATA_PTR(oldarray);
int32 *newints = (int32 *) ARR_DATA_PTR(newarray);
int newlen = 0;
for(i = 0; i < nelems; i++)
{
myinfo.arg[0] = Int32GetDatum(oldints[i]);
/*
* isnull = false everytime as it may be set true
* in the previous call
*/
myinfo.isnull = false;
if (DatumGetBool(FunctionCallInvoke(&myinfo)) &&
!myinfo.isnull)
{
newints[newlen++] = oldints[i];
}
}
if (newlen == 0)
{
PG_RETURN_NULL();
}
SET_VARSIZE(newarray,
ARR_OVERHEAD_NONULLS(ARR_NDIM(newarray)) +
sizeof(int32) * newlen);
ARR_DIMS(newarray)[0] = newlen;
}
else if (mc->optimize == 'd')
{
int64 *oldints = (int64 *) ARR_DATA_PTR(oldarray);
int64 *newints = (int64 *) ARR_DATA_PTR(newarray);
int newlen = 0;
for(i = 0; i < nelems; i++)
{
myinfo.arg[0] = Int64GetDatum(oldints[i]);
myinfo.isnull = false;
if (DatumGetBool(FunctionCallInvoke(&myinfo)) &&
!myinfo.isnull)
{
newints[newlen++] = oldints[i];
}
}
if (newlen == 0)
{
PG_RETURN_NULL();
}
SET_VARSIZE(newarray,
ARR_OVERHEAD_NONULLS(ARR_NDIM(newarray)) +
sizeof(int64) * newlen);
ARR_DIMS(newarray)[0] = newlen;
}
else if (mc->optimize == 's')
{
int16 *oldints = (int16 *) ARR_DATA_PTR(oldarray);
int16 *newints = (int16 *) ARR_DATA_PTR(newarray);
int newlen = 0;
for(i = 0; i < nelems; i++)
{
myinfo.arg[0] = Int16GetDatum(oldints[i]);
myinfo.isnull = false;
if (DatumGetBool(FunctionCallInvoke(&myinfo)) &&
!myinfo.isnull)
{
newints[newlen++] = oldints[i];
}
}
if (newlen == 0)
{
PG_RETURN_NULL();
}
SET_VARSIZE(newarray,
ARR_OVERHEAD_NONULLS(ARR_NDIM(newarray)) +
sizeof(int16) * newlen);
ARR_DIMS(newarray)[0] = newlen;
}
else
{
elog(ERROR, "unknown optimization code = %c", mc->optimize);
}
}
else
{
Datum *values;
bool *nulls;
int i, nelems;
int newlen;
deconstruct_array(oldarray, mc->element_type,
mc->typlen, mc->typbyval, mc->typalign,
&values, &nulls, &nelems);
if (nelems == 0)
{
PG_RETURN_NULL();
}
newlen = 0;
/*
* To avoid allocate double datum array,
* we overwrite the new value on the old array.
* This is possible since filter() processes values
* from head one by one.
*/
for(i = 0; i < nelems; i++)
{
if (!nulls[i] || !mc->flinfo.fn_strict)
{
FunctionCallInfoData myinfo;
InitFunctionCallInfoData(myinfo, &mc->flinfo, 1, NULL, NULL);
myinfo.arg[0] = values[i];
myinfo.argnull[0] = nulls[i];
if (DatumGetBool(FunctionCallInvoke(&myinfo)) &&
!myinfo.isnull)
{
values[newlen] = values[i];
nulls[newlen] = nulls[i];
newlen++;
}
}
/*
* null input on strict function means NULL result,
* which means the value is 'false', and filter it.
*/
}
newarray = construct_md_array(values, nulls, ARR_NDIM(oldarray),
&newlen, ARR_LBOUND(oldarray),
mc->element_type, mc->typlen,
mc->typbyval, mc->typalign);
pfree(values);
pfree(nulls);
}
PG_RETURN_ARRAYTYPE_P(newarray);
}