PostgreSQL Source Code git master
Loading...
Searching...
No Matches
_int_op.c File Reference
#include "postgres.h"
#include "_int.h"
Include dependency graph for _int_op.c:

Go to the source code of this file.

Functions

 PG_MODULE_MAGIC_EXT (.name="intarray",.version=PG_VERSION)
 
 PG_FUNCTION_INFO_V1 (_int_different)
 
 PG_FUNCTION_INFO_V1 (_int_same)
 
 PG_FUNCTION_INFO_V1 (_int_contains)
 
 PG_FUNCTION_INFO_V1 (_int_contained)
 
 PG_FUNCTION_INFO_V1 (_int_overlap)
 
 PG_FUNCTION_INFO_V1 (_int_union)
 
 PG_FUNCTION_INFO_V1 (_int_inter)
 
Datum _int_contained (PG_FUNCTION_ARGS)
 
Datum _int_contains (PG_FUNCTION_ARGS)
 
Datum _int_different (PG_FUNCTION_ARGS)
 
Datum _int_same (PG_FUNCTION_ARGS)
 
Datum _int_overlap (PG_FUNCTION_ARGS)
 
Datum _int_union (PG_FUNCTION_ARGS)
 
Datum _int_inter (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (intset)
 
 PG_FUNCTION_INFO_V1 (icount)
 
 PG_FUNCTION_INFO_V1 (sort)
 
 PG_FUNCTION_INFO_V1 (sort_asc)
 
 PG_FUNCTION_INFO_V1 (sort_desc)
 
 PG_FUNCTION_INFO_V1 (uniq)
 
 PG_FUNCTION_INFO_V1 (idx)
 
 PG_FUNCTION_INFO_V1 (subarray)
 
 PG_FUNCTION_INFO_V1 (intarray_push_elem)
 
 PG_FUNCTION_INFO_V1 (intarray_push_array)
 
 PG_FUNCTION_INFO_V1 (intarray_del_elem)
 
 PG_FUNCTION_INFO_V1 (intset_union_elem)
 
 PG_FUNCTION_INFO_V1 (intset_subtract)
 
Datum intset (PG_FUNCTION_ARGS)
 
Datum icount (PG_FUNCTION_ARGS)
 
Datum sort (PG_FUNCTION_ARGS)
 
Datum sort_asc (PG_FUNCTION_ARGS)
 
Datum sort_desc (PG_FUNCTION_ARGS)
 
Datum uniq (PG_FUNCTION_ARGS)
 
Datum idx (PG_FUNCTION_ARGS)
 
Datum subarray (PG_FUNCTION_ARGS)
 
Datum intarray_push_elem (PG_FUNCTION_ARGS)
 
Datum intarray_push_array (PG_FUNCTION_ARGS)
 
Datum intarray_del_elem (PG_FUNCTION_ARGS)
 
Datum intset_union_elem (PG_FUNCTION_ARGS)
 
Datum intset_subtract (PG_FUNCTION_ARGS)
 

Function Documentation

◆ _int_contained()

Datum _int_contained ( PG_FUNCTION_ARGS  )

Definition at line 22 of file _int_op.c.

23{
24 /* just reverse the operands and call _int_contains */
28}
Datum _int_contains(PG_FUNCTION_ARGS)
Definition _int_op.c:31
#define DirectFunctionCall2(func, arg1, arg2)
Definition fmgr.h:690
#define PG_GETARG_DATUM(n)
Definition fmgr.h:268

References _int_contains(), DirectFunctionCall2, and PG_GETARG_DATUM.

◆ _int_contains()

Datum _int_contains ( PG_FUNCTION_ARGS  )

Definition at line 31 of file _int_op.c.

32{
33 /* Force copy so we can modify the arrays in-place */
36 bool res;
37
42 res = inner_int_contains(a, b);
43 pfree(a);
44 pfree(b);
45 PG_RETURN_BOOL(res);
46}
bool inner_int_contains(ArrayType *a, ArrayType *b)
Definition _int_tool.c:15
#define PREPAREARR(x)
Definition _int.h:49
#define CHECKARRVALID(x)
Definition _int.h:30
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
Definition array.h:264
#define PG_RETURN_BOOL(x)
Definition fmgr.h:360
int b
Definition isn.c:74
int a
Definition isn.c:73
void pfree(void *pointer)
Definition mcxt.c:1619

References a, b, CHECKARRVALID, inner_int_contains(), pfree(), PG_GETARG_ARRAYTYPE_P_COPY, PG_RETURN_BOOL, and PREPAREARR.

Referenced by _int_contained().

◆ _int_different()

Datum _int_different ( PG_FUNCTION_ARGS  )

Definition at line 49 of file _int_op.c.

50{
54}
Datum _int_same(PG_FUNCTION_ARGS)
Definition _int_op.c:57
#define PG_GETARG_POINTER(n)
Definition fmgr.h:277
static bool DatumGetBool(Datum X)
Definition postgres.h:100
#define PointerGetDatum(X)
Definition postgres.h:354

References _int_same(), DatumGetBool(), DirectFunctionCall2, PG_GETARG_POINTER, PG_RETURN_BOOL, and PointerGetDatum.

◆ _int_inter()

Datum _int_inter ( PG_FUNCTION_ARGS  )

Definition at line 147 of file _int_op.c.

148{
152
155
156 SORT(a);
157 SORT(b);
158
160
161 pfree(a);
162 pfree(b);
163
165}
ArrayType * inner_int_inter(ArrayType *a, ArrayType *b)
Definition _int_tool.c:136
#define SORT(x)
Definition _int.h:41
uint32 result
#define PG_RETURN_POINTER(x)
Definition fmgr.h:363

References a, b, CHECKARRVALID, inner_int_inter(), pfree(), PG_GETARG_ARRAYTYPE_P_COPY, PG_RETURN_POINTER, result, and SORT.

◆ _int_overlap()

Datum _int_overlap ( PG_FUNCTION_ARGS  )

Definition at line 103 of file _int_op.c.

104{
107 bool result;
108
111 if (ARRISEMPTY(a) || ARRISEMPTY(b))
112 PG_RETURN_BOOL(false);
113
114 SORT(a);
115 SORT(b);
116
118
119 pfree(a);
120 pfree(b);
121
123}
bool inner_int_overlap(ArrayType *a, ArrayType *b)
Definition _int_tool.c:50
#define ARRISEMPTY(x)
Definition _int.h:38

References a, ARRISEMPTY, b, CHECKARRVALID, inner_int_overlap(), pfree(), PG_GETARG_ARRAYTYPE_P_COPY, PG_RETURN_BOOL, result, and SORT.

◆ _int_same()

Datum _int_same ( PG_FUNCTION_ARGS  )

Definition at line 57 of file _int_op.c.

58{
61 int na,
62 nb;
63 int n;
64 int *da,
65 *db;
66 bool result;
67
70 na = ARRNELEMS(a);
71 nb = ARRNELEMS(b);
72 da = ARRPTR(a);
73 db = ARRPTR(b);
74
75 result = false;
76
77 if (na == nb)
78 {
79 SORT(a);
80 SORT(b);
81 result = true;
82
83 for (n = 0; n < na; n++)
84 {
85 if (da[n] != db[n])
86 {
87 result = false;
88 break;
89 }
90 }
91 }
92
93 pfree(a);
94 pfree(b);
95
97}
#define ARRNELEMS(x)
Definition cube.c:29
#define ARRPTR(x)
Definition cube.c:28
static int fb(int x)

References a, ARRNELEMS, ARRPTR, b, CHECKARRVALID, fb(), pfree(), PG_GETARG_ARRAYTYPE_P_COPY, PG_RETURN_BOOL, result, and SORT.

Referenced by _int_different().

◆ _int_union()

Datum _int_union ( PG_FUNCTION_ARGS  )

Definition at line 126 of file _int_op.c.

127{
131
134
135 SORT(a);
136 SORT(b);
137
139
140 pfree(a);
141 pfree(b);
142
144}
ArrayType * inner_int_union(ArrayType *a, ArrayType *b)
Definition _int_tool.c:79

References a, b, CHECKARRVALID, inner_int_union(), pfree(), PG_GETARG_ARRAYTYPE_P_COPY, PG_RETURN_POINTER, result, and SORT.

◆ icount()

Datum icount ( PG_FUNCTION_ARGS  )

Definition at line 189 of file _int_op.c.

190{
192 int32 count = ARRNELEMS(a);
193
194 PG_FREE_IF_COPY(a, 0);
195 PG_RETURN_INT32(count);
196}
#define PG_GETARG_ARRAYTYPE_P(n)
Definition array.h:263
int32_t int32
Definition c.h:620
#define PG_FREE_IF_COPY(ptr, n)
Definition fmgr.h:260
#define PG_RETURN_INT32(x)
Definition fmgr.h:355

References a, ARRNELEMS, PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, and PG_RETURN_INT32.

◆ idx()

Definition at line 263 of file _int_op.c.

264{
267
269 result = ARRNELEMS(a);
270 if (result)
272 PG_FREE_IF_COPY(a, 0);
274}
int32 intarray_match_first(ArrayType *a, int32 elem)
Definition _int_tool.c:338
#define PG_GETARG_INT32(n)
Definition fmgr.h:269

References a, ARRNELEMS, CHECKARRVALID, intarray_match_first(), PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, PG_GETARG_INT32, PG_RETURN_INT32, and result.

Referenced by aclexplode(), AllocSetFreeIndex(), appendStringInfoRegexpSubstr(), array_subscript_transform(), AttachPartitionEnsureIndexes(), avlCollectFields(), brin_minmax_multi_summary_out(), brin_revmap_data(), build_expr_data(), build_sorted_items(), casemap(), copy_sequences(), cube_subset(), dependencies_clauselist_selectivity(), DetachPartitionFinalize(), do_set_block_offsets(), estimate_multivariate_ndistinct(), ExecHashIncreaseNumBatches(), ExecHashIncreaseNumBuckets(), ExecInitIndexOnlyScan(), ExecParallelHashIncreaseNumBuckets(), ExecParallelHashRepartitionFirst(), fill_expanded_ranges(), find_having_collation_conflicts(), find_target_tuple(), generate_restrict_key(), GetLWTrancheName(), GetXLogBuffer(), hstore_contains(), hstore_defined(), hstore_exists(), hstore_exists_all(), hstore_exists_any(), hstore_fetchval(), hstore_populate_record(), hstore_slice_to_array(), hstore_slice_to_hstore(), hstore_subscript_fetch(), indexOfColumn(), InjectionPointAttach(), InjectionPointDetach(), InjectionPointList(), jsonb_delete_idx(), jsonb_subscript_transform(), lazy_cleanup_all_indexes(), lazy_vacuum_all_indexes(), Lookahead(), LWLockNewTrancheId(), LWLockShmemInit(), make_build_data(), mcv_get_match_bitmap(), mcv_match_expression(), merge_overlapping_ranges(), multirange_bsearch_match(), parallel_vacuum_process_safe_indexes(), percentile_cont_multi_final_common(), percentile_disc_multi_final(), pg_buffercache_os_pages_internal(), pg_get_wait_events(), pg_mb_radix_conv(), pg_nextoid(), pg_stat_get_db_numbackends(), pgoutput_row_filter_init(), pgstat_build_snapshot_fixed(), pgstat_fetch_replslot(), pgstat_get_custom_shmem_data(), pgstat_get_custom_snapshot_data(), pgstat_get_kind_from_str(), pgstat_get_kind_info(), pgstat_get_local_beentry_by_index(), pgstat_read_statsfile(), pgstat_register_kind(), pgstat_replslot_from_serialized_name_cb(), PLy_result_item(), PLySequence_ToComposite(), printCrosstab(), radix_sort_recursive(), range_gist_double_sorting_split(), range_gist_single_sorting_split(), ReindexRelationConcurrently(), RemoveListenerFromChannel(), ResourceOwnerAddToHash(), ResourceOwnerForget(), ResourceOwnerReleaseAll(), ResourceOwnerRemember(), ResourceOwnerSort(), ri_ReportViolation(), RT_ADD_CHILD_256(), RT_ADD_CHILD_48(), RT_GROW_NODE_16(), RT_NODE_256_IS_CHUNK_USED(), RT_NODE_4_GET_INSERTPOS(), RT_VERIFY_NODE(), setPathArray(), stat_find_expression(), statext_expressions_load(), StatsShmemInit(), store_expanded_ranges(), StoreIndexTuple(), tbm_prepare_shared_iterate(), test_pattern(), test_remove_node(), TidStoreSetBlockOffsets(), transformContainerSubscripts(), update_relstats_all_indexes(), and WALReadFromBuffers().

◆ intarray_del_elem()

Datum intarray_del_elem ( PG_FUNCTION_ARGS  )

Definition at line 351 of file _int_op.c.

352{
354 int32 elem = PG_GETARG_INT32(1);
355 int32 c;
356 int32 *aa;
357 int32 n = 0,
358 i;
359
361 if (!ARRISEMPTY(a))
362 {
363 c = ARRNELEMS(a);
364 aa = ARRPTR(a);
365 for (i = 0; i < c; i++)
366 {
367 if (aa[i] != elem)
368 {
369 if (i > n)
370 aa[n++] = aa[i];
371 else
372 n++;
373 }
374 }
375 a = resize_intArrayType(a, n);
376 }
378}
ArrayType * resize_intArrayType(ArrayType *a, int num)
Definition _int_tool.c:252
int i
Definition isn.c:77
char * c

References a, ARRISEMPTY, ARRNELEMS, ARRPTR, CHECKARRVALID, fb(), i, PG_GETARG_ARRAYTYPE_P_COPY, PG_GETARG_INT32, PG_RETURN_POINTER, and resize_intArrayType().

◆ intarray_push_array()

Datum intarray_push_array ( PG_FUNCTION_ARGS  )

Definition at line 338 of file _int_op.c.

339{
343
345 PG_FREE_IF_COPY(a, 0);
346 PG_FREE_IF_COPY(b, 1);
348}
ArrayType * intarray_concat_arrays(ArrayType *a, ArrayType *b)
Definition _int_tool.c:371

References a, b, intarray_concat_arrays(), PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, PG_RETURN_POINTER, and result.

◆ intarray_push_elem()

Datum intarray_push_elem ( PG_FUNCTION_ARGS  )

Definition at line 327 of file _int_op.c.

328{
331
333 PG_FREE_IF_COPY(a, 0);
335}
ArrayType * intarray_add_elem(ArrayType *a, int32 elem)
Definition _int_tool.c:354

References a, intarray_add_elem(), PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, PG_GETARG_INT32, PG_RETURN_POINTER, and result.

◆ intset()

◆ intset_subtract()

Datum intset_subtract ( PG_FUNCTION_ARGS  )

Definition at line 393 of file _int_op.c.

394{
398 int32 ca;
399 int32 cb;
400 int32 *aa,
401 *bb,
402 *r;
403 int32 n = 0,
404 i = 0,
405 k = 0;
406
409
410 QSORT(a, 1);
411 a = _int_unique(a);
412 ca = ARRNELEMS(a);
413 QSORT(b, 1);
414 b = _int_unique(b);
415 cb = ARRNELEMS(b);
417 aa = ARRPTR(a);
418 bb = ARRPTR(b);
419 r = ARRPTR(result);
420 while (i < ca)
421 {
422 if (k == cb || aa[i] < bb[k])
423 r[n++] = aa[i++];
424 else if (aa[i] == bb[k])
425 {
426 i++;
427 k++;
428 }
429 else
430 k++;
431 }
433 pfree(a);
434 pfree(b);
436}
ArrayType * new_intArrayType(int num)
Definition _int_tool.c:224
#define QSORT(a, direction)
Definition _int.h:180
ArrayType * _int_unique(ArrayType *r)
Definition _int_tool.c:313

References _int_unique(), a, ARRNELEMS, ARRPTR, b, CHECKARRVALID, fb(), i, new_intArrayType(), pfree(), PG_GETARG_ARRAYTYPE_P_COPY, PG_RETURN_POINTER, QSORT, resize_intArrayType(), and result.

◆ intset_union_elem()

◆ PG_FUNCTION_INFO_V1() [1/20]

PG_FUNCTION_INFO_V1 ( _int_contained  )

◆ PG_FUNCTION_INFO_V1() [2/20]

PG_FUNCTION_INFO_V1 ( _int_contains  )

◆ PG_FUNCTION_INFO_V1() [3/20]

PG_FUNCTION_INFO_V1 ( _int_different  )

◆ PG_FUNCTION_INFO_V1() [4/20]

PG_FUNCTION_INFO_V1 ( _int_inter  )

◆ PG_FUNCTION_INFO_V1() [5/20]

PG_FUNCTION_INFO_V1 ( _int_overlap  )

◆ PG_FUNCTION_INFO_V1() [6/20]

PG_FUNCTION_INFO_V1 ( _int_same  )

◆ PG_FUNCTION_INFO_V1() [7/20]

PG_FUNCTION_INFO_V1 ( _int_union  )

◆ PG_FUNCTION_INFO_V1() [8/20]

PG_FUNCTION_INFO_V1 ( icount  )

◆ PG_FUNCTION_INFO_V1() [9/20]

PG_FUNCTION_INFO_V1 ( idx  )

◆ PG_FUNCTION_INFO_V1() [10/20]

PG_FUNCTION_INFO_V1 ( intarray_del_elem  )

◆ PG_FUNCTION_INFO_V1() [11/20]

PG_FUNCTION_INFO_V1 ( intarray_push_array  )

◆ PG_FUNCTION_INFO_V1() [12/20]

PG_FUNCTION_INFO_V1 ( intarray_push_elem  )

◆ PG_FUNCTION_INFO_V1() [13/20]

PG_FUNCTION_INFO_V1 ( intset  )

◆ PG_FUNCTION_INFO_V1() [14/20]

PG_FUNCTION_INFO_V1 ( intset_subtract  )

◆ PG_FUNCTION_INFO_V1() [15/20]

PG_FUNCTION_INFO_V1 ( intset_union_elem  )

◆ PG_FUNCTION_INFO_V1() [16/20]

PG_FUNCTION_INFO_V1 ( sort  )

◆ PG_FUNCTION_INFO_V1() [17/20]

PG_FUNCTION_INFO_V1 ( sort_asc  )

◆ PG_FUNCTION_INFO_V1() [18/20]

PG_FUNCTION_INFO_V1 ( sort_desc  )

◆ PG_FUNCTION_INFO_V1() [19/20]

PG_FUNCTION_INFO_V1 ( subarray  )

◆ PG_FUNCTION_INFO_V1() [20/20]

PG_FUNCTION_INFO_V1 ( uniq  )

◆ PG_MODULE_MAGIC_EXT()

PG_MODULE_MAGIC_EXT ( name = "intarray",
version = PG_VERSION 
)

◆ sort()

Datum sort ( PG_FUNCTION_ARGS  )

Definition at line 199 of file _int_op.c.

200{
202 text *dirstr = (fcinfo->nargs == 2) ? PG_GETARG_TEXT_PP(1) : NULL;
204 char *d = (dirstr) ? VARDATA_ANY(dirstr) : NULL;
205 int dir = -1;
206
208 if (ARRNELEMS(a) < 2)
210
211 if (dirstr == NULL || (dc == 3
212 && (d[0] == 'A' || d[0] == 'a')
213 && (d[1] == 'S' || d[1] == 's')
214 && (d[2] == 'C' || d[2] == 'c')))
215 dir = 1;
216 else if (dc == 4
217 && (d[0] == 'D' || d[0] == 'd')
218 && (d[1] == 'E' || d[1] == 'e')
219 && (d[2] == 'S' || d[2] == 's')
220 && (d[3] == 'C' || d[3] == 'c'))
221 dir = 0;
222 if (dir == -1)
225 errmsg("second parameter must be \"ASC\" or \"DESC\"")));
226 QSORT(a, dir);
228}
int errcode(int sqlerrcode)
Definition elog.c:875
#define ERROR
Definition elog.h:40
#define ereport(elevel,...)
Definition elog.h:152
#define PG_GETARG_TEXT_PP(n)
Definition fmgr.h:310
static char * errmsg
Definition c.h:776
static Size VARSIZE_ANY_EXHDR(const void *PTR)
Definition varatt.h:472
static char * VARDATA_ANY(const void *PTR)
Definition varatt.h:486

References a, ARRNELEMS, CHECKARRVALID, ereport, errcode(), errmsg, ERROR, fb(), PG_GETARG_ARRAYTYPE_P_COPY, PG_GETARG_TEXT_PP, PG_RETURN_POINTER, QSORT, VARDATA_ANY(), and VARSIZE_ANY_EXHDR().

Referenced by create_incremental_sort_path(), and create_mergejoin_plan().

◆ sort_asc()

Datum sort_asc ( PG_FUNCTION_ARGS  )

Definition at line 231 of file _int_op.c.

232{
234
236 QSORT(a, 1);
238}

References a, CHECKARRVALID, PG_GETARG_ARRAYTYPE_P_COPY, PG_RETURN_POINTER, and QSORT.

◆ sort_desc()

Datum sort_desc ( PG_FUNCTION_ARGS  )

Definition at line 241 of file _int_op.c.

242{
244
246 QSORT(a, 0);
248}

References a, CHECKARRVALID, PG_GETARG_ARRAYTYPE_P_COPY, PG_RETURN_POINTER, and QSORT.

◆ subarray()

Datum subarray ( PG_FUNCTION_ARGS  )

Definition at line 277 of file _int_op.c.

278{
281 int32 len = (fcinfo->nargs == 3) ? PG_GETARG_INT32(2) : 0;
282 int32 end = 0;
283 int32 c;
285
286 start = (start > 0) ? start - 1 : start;
287
289 if (ARRISEMPTY(a))
290 {
291 PG_FREE_IF_COPY(a, 0);
293 }
294
295 c = ARRNELEMS(a);
296
297 if (start < 0)
298 start = c + start;
299
300 if (len < 0)
301 end = c + len;
302 else if (len == 0)
303 end = c;
304 else
305 end = start + len;
306
307 if (end > c)
308 end = c;
309
310 if (start < 0)
311 start = 0;
312
313 if (start >= end || end <= 0)
314 {
315 PG_FREE_IF_COPY(a, 0);
317 }
318
320 if (end - start > 0)
321 memcpy(ARRPTR(result), ARRPTR(a) + start, (end - start) * sizeof(int32));
322 PG_FREE_IF_COPY(a, 0);
324}
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
return str start
const void size_t len

References a, ARRISEMPTY, ARRNELEMS, ARRPTR, CHECKARRVALID, len, memcpy(), new_intArrayType(), PG_FREE_IF_COPY, PG_GETARG_ARRAYTYPE_P, PG_GETARG_INT32, PG_RETURN_POINTER, result, and start.

◆ uniq()

Datum uniq ( PG_FUNCTION_ARGS  )

Definition at line 251 of file _int_op.c.

252{
254
256 if (ARRNELEMS(a) < 2)
258 a = _int_unique(a);
260}

References _int_unique(), a, ARRNELEMS, CHECKARRVALID, PG_GETARG_ARRAYTYPE_P_COPY, and PG_RETURN_POINTER.