pg_query 6.1.0 → 6.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +38 -1
- data/README.md +1 -1
- data/Rakefile +3 -2
- data/ext/pg_query/extconf.rb +2 -2
- data/ext/pg_query/include/pg_query.h +32 -2
- data/ext/pg_query/include/postgres/access/amapi.h +1 -1
- data/ext/pg_query/include/postgres/access/slru.h +1 -1
- data/ext/pg_query/include/postgres/access/tableam.h +11 -4
- data/ext/pg_query/include/postgres/access/xlog.h +1 -0
- data/ext/pg_query/include/postgres/access/xlogdefs.h +2 -1
- data/ext/pg_query/include/postgres/commands/defrem.h +1 -1
- data/ext/pg_query/include/postgres/commands/trigger.h +18 -0
- data/ext/pg_query/include/postgres/executor/executor.h +4 -0
- data/ext/pg_query/include/postgres/mb/pg_wchar.h +2 -0
- data/ext/pg_query/include/postgres/miscadmin.h +2 -1
- data/ext/pg_query/include/postgres/nodes/execnodes.h +6 -8
- data/ext/pg_query/include/postgres/nodes/pathnodes.h +1 -2
- data/ext/pg_query/include/postgres/pg_config.h +10 -9
- data/ext/pg_query/include/postgres/pg_config_manual.h +2 -0
- data/ext/pg_query/include/postgres/port/atomics/generic-gcc.h +10 -2
- data/ext/pg_query/include/postgres/port/pg_iovec.h +9 -3
- data/ext/pg_query/include/postgres/replication/reorderbuffer.h +29 -9
- data/ext/pg_query/include/postgres/replication/slot.h +2 -0
- data/ext/pg_query/include/postgres/utils/elog.h +1 -0
- data/ext/pg_query/include/postgres/utils/guc.h +1 -1
- data/ext/pg_query/include/postgres/utils/guc_hooks.h +0 -2
- data/ext/pg_query/include/postgres/utils/pg_locale.h +5 -0
- data/ext/pg_query/include/postgres_deparse.h +34 -0
- data/ext/pg_query/include/protobuf/pg_query.pb-c.h +673 -516
- data/ext/pg_query/pg_query.pb-c.c +488 -0
- data/ext/pg_query/pg_query_deparse.c +148 -15
- data/ext/pg_query/pg_query_internal.h +9 -8
- data/ext/pg_query/pg_query_is_utility_stmt.c +70 -0
- data/ext/pg_query/pg_query_normalize.c +3 -0
- data/ext/pg_query/pg_query_raw_tree_walker_supports.c +117 -0
- data/ext/pg_query/pg_query_ruby.c +150 -0
- data/ext/pg_query/pg_query_summary.c +941 -0
- data/ext/pg_query/pg_query_summary.h +109 -0
- data/ext/pg_query/pg_query_summary_statement_type.c +797 -0
- data/ext/pg_query/pg_query_summary_truncate.c +530 -0
- data/ext/pg_query/postgres_deparse.c +4481 -3870
- data/ext/pg_query/src_backend_catalog_namespace.c +29 -0
- data/ext/pg_query/src_backend_nodes_bitmapset.c +84 -1
- data/ext/pg_query/src_backend_nodes_list.c +60 -1
- data/ext/pg_query/src_backend_parser_gram.c +739 -732
- data/ext/pg_query/src_backend_utils_activity_pgstat_database.c +2 -2
- data/ext/pg_query/src_backend_utils_error_elog.c +11 -0
- data/ext/pg_query/src_backend_utils_mb_mbutils.c +43 -4
- data/ext/pg_query/src_backend_utils_mmgr_alignedalloc.c +22 -7
- data/ext/pg_query/src_backend_utils_mmgr_aset.c +3 -3
- data/ext/pg_query/src_backend_utils_mmgr_bump.c +1 -1
- data/ext/pg_query/src_common_stringinfo.c +20 -0
- data/ext/pg_query/src_common_wchar.c +46 -6
- data/lib/pg_query/deparse.rb +29 -8
- data/lib/pg_query/parse.rb +19 -0
- data/lib/pg_query/pg_query_pb.rb +7 -2
- data/lib/pg_query/split.rb +20 -0
- data/lib/pg_query/treewalker.rb +9 -7
- data/lib/pg_query/version.rb +1 -1
- data/lib/pg_query.rb +1 -0
- metadata +10 -3
- data/ext/pg_query/postgres_deparse.h +0 -9
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Symbols referenced in this file:
|
|
3
3
|
* - NameListToString
|
|
4
4
|
* - get_collation_oid
|
|
5
|
+
* - makeRangeVarFromNameList
|
|
5
6
|
*--------------------------------------------------------------------
|
|
6
7
|
*/
|
|
7
8
|
|
|
@@ -900,7 +901,35 @@ static bool MatchNamedCall(HeapTuple proctup, int nargs, List *argnames,
|
|
|
900
901
|
* makeRangeVarFromNameList
|
|
901
902
|
* Utility routine to convert a qualified-name list into RangeVar form.
|
|
902
903
|
*/
|
|
904
|
+
RangeVar *
|
|
905
|
+
makeRangeVarFromNameList(const List *names)
|
|
906
|
+
{
|
|
907
|
+
RangeVar *rel = makeRangeVar(NULL, NULL, -1);
|
|
903
908
|
|
|
909
|
+
switch (list_length(names))
|
|
910
|
+
{
|
|
911
|
+
case 1:
|
|
912
|
+
rel->relname = strVal(linitial(names));
|
|
913
|
+
break;
|
|
914
|
+
case 2:
|
|
915
|
+
rel->schemaname = strVal(linitial(names));
|
|
916
|
+
rel->relname = strVal(lsecond(names));
|
|
917
|
+
break;
|
|
918
|
+
case 3:
|
|
919
|
+
rel->catalogname = strVal(linitial(names));
|
|
920
|
+
rel->schemaname = strVal(lsecond(names));
|
|
921
|
+
rel->relname = strVal(lthird(names));
|
|
922
|
+
break;
|
|
923
|
+
default:
|
|
924
|
+
ereport(ERROR,
|
|
925
|
+
(errcode(ERRCODE_SYNTAX_ERROR),
|
|
926
|
+
errmsg("improper relation name (too many dotted names): %s",
|
|
927
|
+
NameListToString(names))));
|
|
928
|
+
break;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
return rel;
|
|
932
|
+
}
|
|
904
933
|
|
|
905
934
|
/*
|
|
906
935
|
* NameListToString
|
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
* - bms_free
|
|
7
7
|
* - bms_next_member
|
|
8
8
|
* - bms_num_members
|
|
9
|
+
* - bms_add_member
|
|
10
|
+
* - bms_make_singleton
|
|
11
|
+
* - bms_is_member
|
|
9
12
|
*--------------------------------------------------------------------
|
|
10
13
|
*/
|
|
11
14
|
|
|
@@ -195,7 +198,23 @@ bms_equal(const Bitmapset *a, const Bitmapset *b)
|
|
|
195
198
|
/*
|
|
196
199
|
* bms_make_singleton - build a bitmapset containing a single member
|
|
197
200
|
*/
|
|
198
|
-
|
|
201
|
+
Bitmapset *
|
|
202
|
+
bms_make_singleton(int x)
|
|
203
|
+
{
|
|
204
|
+
Bitmapset *result;
|
|
205
|
+
int wordnum,
|
|
206
|
+
bitnum;
|
|
207
|
+
|
|
208
|
+
if (x < 0)
|
|
209
|
+
elog(ERROR, "negative bitmapset member not allowed");
|
|
210
|
+
wordnum = WORDNUM(x);
|
|
211
|
+
bitnum = BITNUM(x);
|
|
212
|
+
result = (Bitmapset *) palloc0(BITMAPSET_SIZE(wordnum + 1));
|
|
213
|
+
result->type = T_Bitmapset;
|
|
214
|
+
result->nwords = wordnum + 1;
|
|
215
|
+
result->words[wordnum] = ((bitmapword) 1 << bitnum);
|
|
216
|
+
return result;
|
|
217
|
+
}
|
|
199
218
|
|
|
200
219
|
/*
|
|
201
220
|
* bms_free - free a bitmapset
|
|
@@ -243,7 +262,28 @@ bms_free(Bitmapset *a)
|
|
|
243
262
|
/*
|
|
244
263
|
* bms_is_member - is X a member of A?
|
|
245
264
|
*/
|
|
265
|
+
bool
|
|
266
|
+
bms_is_member(int x, const Bitmapset *a)
|
|
267
|
+
{
|
|
268
|
+
int wordnum,
|
|
269
|
+
bitnum;
|
|
246
270
|
|
|
271
|
+
Assert(bms_is_valid_set(a));
|
|
272
|
+
|
|
273
|
+
/* XXX better to just return false for x<0 ? */
|
|
274
|
+
if (x < 0)
|
|
275
|
+
elog(ERROR, "negative bitmapset member not allowed");
|
|
276
|
+
if (a == NULL)
|
|
277
|
+
return false;
|
|
278
|
+
|
|
279
|
+
wordnum = WORDNUM(x);
|
|
280
|
+
bitnum = BITNUM(x);
|
|
281
|
+
if (wordnum >= a->nwords)
|
|
282
|
+
return false;
|
|
283
|
+
if ((a->words[wordnum] & ((bitmapword) 1 << bitnum)) != 0)
|
|
284
|
+
return true;
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
247
287
|
|
|
248
288
|
/*
|
|
249
289
|
* bms_member_index
|
|
@@ -331,9 +371,52 @@ bms_num_members(const Bitmapset *a)
|
|
|
331
371
|
*
|
|
332
372
|
* 'a' is recycled when possible.
|
|
333
373
|
*/
|
|
374
|
+
Bitmapset *
|
|
375
|
+
bms_add_member(Bitmapset *a, int x)
|
|
376
|
+
{
|
|
377
|
+
int wordnum,
|
|
378
|
+
bitnum;
|
|
379
|
+
|
|
380
|
+
Assert(bms_is_valid_set(a));
|
|
381
|
+
|
|
382
|
+
if (x < 0)
|
|
383
|
+
elog(ERROR, "negative bitmapset member not allowed");
|
|
384
|
+
if (a == NULL)
|
|
385
|
+
return bms_make_singleton(x);
|
|
386
|
+
|
|
387
|
+
wordnum = WORDNUM(x);
|
|
388
|
+
bitnum = BITNUM(x);
|
|
389
|
+
|
|
390
|
+
/* enlarge the set if necessary */
|
|
391
|
+
if (wordnum >= a->nwords)
|
|
392
|
+
{
|
|
393
|
+
int oldnwords = a->nwords;
|
|
394
|
+
int i;
|
|
395
|
+
|
|
396
|
+
a = (Bitmapset *) repalloc(a, BITMAPSET_SIZE(wordnum + 1));
|
|
397
|
+
a->nwords = wordnum + 1;
|
|
398
|
+
/* zero out the enlarged portion */
|
|
399
|
+
i = oldnwords;
|
|
400
|
+
do
|
|
401
|
+
{
|
|
402
|
+
a->words[i] = 0;
|
|
403
|
+
} while (++i < a->nwords);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
a->words[wordnum] |= ((bitmapword) 1 << bitnum);
|
|
407
|
+
|
|
334
408
|
#ifdef REALLOCATE_BITMAPSETS
|
|
409
|
+
|
|
410
|
+
/*
|
|
411
|
+
* There's no guarantee that the repalloc returned a new pointer, so copy
|
|
412
|
+
* and free unconditionally here.
|
|
413
|
+
*/
|
|
414
|
+
a = bms_copy_and_free(a);
|
|
335
415
|
#endif
|
|
336
416
|
|
|
417
|
+
return a;
|
|
418
|
+
}
|
|
419
|
+
|
|
337
420
|
/*
|
|
338
421
|
* bms_del_member - remove a specified member from set
|
|
339
422
|
*
|
|
@@ -19,6 +19,10 @@
|
|
|
19
19
|
* - list_copy_deep
|
|
20
20
|
* - list_copy_tail
|
|
21
21
|
* - list_truncate
|
|
22
|
+
* - list_delete_last
|
|
23
|
+
* - list_insert_nth
|
|
24
|
+
* - insert_new_cell
|
|
25
|
+
* - list_sort
|
|
22
26
|
*--------------------------------------------------------------------
|
|
23
27
|
*/
|
|
24
28
|
|
|
@@ -383,7 +387,22 @@ lappend(List *list, void *datum)
|
|
|
383
387
|
* list position, ie, 0 <= pos <= list's length.
|
|
384
388
|
* Returns address of the new cell.
|
|
385
389
|
*/
|
|
390
|
+
static ListCell *
|
|
391
|
+
insert_new_cell(List *list, int pos)
|
|
392
|
+
{
|
|
393
|
+
Assert(pos >= 0 && pos <= list->length);
|
|
386
394
|
|
|
395
|
+
/* Enlarge array if necessary */
|
|
396
|
+
if (list->length >= list->max_length)
|
|
397
|
+
enlarge_list(list, list->length + 1);
|
|
398
|
+
/* Now shove the existing data over */
|
|
399
|
+
if (pos < list->length)
|
|
400
|
+
memmove(&list->elements[pos + 1], &list->elements[pos],
|
|
401
|
+
(list->length - pos) * sizeof(ListCell));
|
|
402
|
+
list->length++;
|
|
403
|
+
|
|
404
|
+
return &list->elements[pos];
|
|
405
|
+
}
|
|
387
406
|
|
|
388
407
|
/*
|
|
389
408
|
* Insert the given datum at position 'pos' (measured from 0) in the list.
|
|
@@ -392,7 +411,19 @@ lappend(List *list, void *datum)
|
|
|
392
411
|
* Note that this takes time proportional to the distance to the end of the
|
|
393
412
|
* list, since the following entries must be moved.
|
|
394
413
|
*/
|
|
395
|
-
|
|
414
|
+
List *
|
|
415
|
+
list_insert_nth(List *list, int pos, void *datum)
|
|
416
|
+
{
|
|
417
|
+
if (list == NIL)
|
|
418
|
+
{
|
|
419
|
+
Assert(pos == 0);
|
|
420
|
+
return list_make1(datum);
|
|
421
|
+
}
|
|
422
|
+
Assert(IsPointerList(list));
|
|
423
|
+
lfirst(insert_new_cell(list, pos)) = datum;
|
|
424
|
+
check_list_invariants(list);
|
|
425
|
+
return list;
|
|
426
|
+
}
|
|
396
427
|
|
|
397
428
|
|
|
398
429
|
|
|
@@ -674,7 +705,23 @@ list_delete_nth_cell(List *list, int n)
|
|
|
674
705
|
/*
|
|
675
706
|
* Delete the last element of the list.
|
|
676
707
|
*/
|
|
708
|
+
List *
|
|
709
|
+
list_delete_last(List *list)
|
|
710
|
+
{
|
|
711
|
+
check_list_invariants(list);
|
|
677
712
|
|
|
713
|
+
if (list == NIL)
|
|
714
|
+
return NIL; /* would an error be better? */
|
|
715
|
+
|
|
716
|
+
/* list_truncate won't free list if it goes to empty, but this should */
|
|
717
|
+
if (list_length(list) <= 1)
|
|
718
|
+
{
|
|
719
|
+
list_free(list);
|
|
720
|
+
return NIL;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
return list_truncate(list, list_length(list) - 1);
|
|
724
|
+
}
|
|
678
725
|
|
|
679
726
|
/*
|
|
680
727
|
* Delete the first N cells of the list.
|
|
@@ -992,7 +1039,19 @@ list_copy_deep(const List *oldlist)
|
|
|
992
1039
|
*
|
|
993
1040
|
* This is based on qsort(), so it likewise has O(N log N) runtime.
|
|
994
1041
|
*/
|
|
1042
|
+
void
|
|
1043
|
+
list_sort(List *list, list_sort_comparator cmp)
|
|
1044
|
+
{
|
|
1045
|
+
typedef int (*qsort_comparator) (const void *a, const void *b);
|
|
1046
|
+
int len;
|
|
1047
|
+
|
|
1048
|
+
check_list_invariants(list);
|
|
995
1049
|
|
|
1050
|
+
/* Nothing to do if there's less than two elements */
|
|
1051
|
+
len = list_length(list);
|
|
1052
|
+
if (len > 1)
|
|
1053
|
+
qsort(list->elements, len, sizeof(ListCell), (qsort_comparator) cmp);
|
|
1054
|
+
}
|
|
996
1055
|
|
|
997
1056
|
/*
|
|
998
1057
|
* list_sort comparator for sorting a list into ascending int order.
|