pg_query 2.0.3 → 2.1.3
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 +77 -0
- data/README.md +12 -0
- data/Rakefile +5 -19
- data/ext/pg_query/extconf.rb +3 -1
- data/ext/pg_query/include/c.h +12 -0
- data/ext/pg_query/include/executor/executor.h +6 -0
- data/ext/pg_query/include/nodes/execnodes.h +9 -6
- data/ext/pg_query/include/nodes/pathnodes.h +1 -1
- data/ext/pg_query/include/optimizer/paths.h +8 -0
- data/ext/pg_query/include/pg_config.h +9 -6
- data/ext/pg_query/include/pg_config_manual.h +7 -0
- data/ext/pg_query/include/pg_query.h +2 -2
- data/ext/pg_query/include/pg_query_outfuncs_defs.c +1 -0
- data/ext/pg_query/include/pg_query_readfuncs_defs.c +1 -0
- data/ext/pg_query/include/protobuf/pg_query.pb-c.h +472 -467
- data/ext/pg_query/include/protobuf-c/protobuf-c.h +7 -3
- data/ext/pg_query/include/protobuf-c.h +7 -3
- data/ext/pg_query/include/utils/array.h +1 -0
- data/ext/pg_query/include/utils/lsyscache.h +1 -0
- data/ext/pg_query/include/utils/probes.h +57 -57
- data/ext/pg_query/pg_query.pb-c.c +502 -487
- data/ext/pg_query/pg_query_deparse.c +6 -0
- data/ext/pg_query/pg_query_fingerprint.c +119 -32
- data/ext/pg_query/pg_query_fingerprint.h +3 -1
- data/ext/pg_query/pg_query_normalize.c +222 -63
- data/ext/pg_query/pg_query_parse_plpgsql.c +21 -1
- data/ext/pg_query/pg_query_ruby.c +1 -1
- data/ext/pg_query/pg_query_ruby.sym +1 -0
- data/ext/pg_query/protobuf-c.c +34 -27
- data/ext/pg_query/src_backend_utils_mmgr_mcxt.c +36 -0
- data/ext/pg_query/src_common_hashfn.c +420 -0
- data/ext/pg_query/src_pl_plpgsql_src_pl_gram.c +1 -1
- data/lib/pg_query/filter_columns.rb +4 -4
- data/lib/pg_query/fingerprint.rb +1 -3
- data/lib/pg_query/parse.rb +111 -45
- data/lib/pg_query/pg_query_pb.rb +1385 -1383
- data/lib/pg_query/version.rb +1 -1
- data/lib/pg_query.rb +0 -1
- metadata +8 -8
- data/lib/pg_query/json_field_names.rb +0 -1402
data/ext/pg_query/protobuf-c.c
CHANGED
@@ -84,7 +84,9 @@
|
|
84
84
|
# define PROTOBUF_C_UNPACK_ERROR(...)
|
85
85
|
#endif
|
86
86
|
|
87
|
+
#if !defined(_WIN32) || !defined(PROTOBUF_C_USE_SHARED_LIB)
|
87
88
|
const char protobuf_c_empty_string[] = "";
|
89
|
+
#endif
|
88
90
|
|
89
91
|
/**
|
90
92
|
* Internal `ProtobufCMessage` manipulation macro.
|
@@ -148,12 +150,14 @@ protobuf_c_version_number(void)
|
|
148
150
|
static void *
|
149
151
|
system_alloc(void *allocator_data, size_t size)
|
150
152
|
{
|
153
|
+
(void)allocator_data;
|
151
154
|
return malloc(size);
|
152
155
|
}
|
153
156
|
|
154
157
|
static void
|
155
158
|
system_free(void *allocator_data, void *data)
|
156
159
|
{
|
160
|
+
(void)allocator_data;
|
157
161
|
free(data);
|
158
162
|
}
|
159
163
|
|
@@ -1618,22 +1622,19 @@ required_field_pack_to_buffer(const ProtobufCFieldDescriptor *field,
|
|
1618
1622
|
break;
|
1619
1623
|
}
|
1620
1624
|
case PROTOBUF_C_TYPE_MESSAGE: {
|
1621
|
-
uint8_t simple_buffer_scratch[256];
|
1622
|
-
size_t sublen;
|
1623
1625
|
const ProtobufCMessage *msg = *(ProtobufCMessage * const *) member;
|
1624
|
-
|
1625
|
-
PROTOBUF_C_BUFFER_SIMPLE_INIT(simple_buffer_scratch);
|
1626
|
-
|
1626
|
+
|
1627
1627
|
scratch[0] |= PROTOBUF_C_WIRE_TYPE_LENGTH_PREFIXED;
|
1628
|
-
if (msg == NULL)
|
1629
|
-
|
1630
|
-
|
1631
|
-
|
1632
|
-
|
1633
|
-
|
1634
|
-
|
1635
|
-
|
1636
|
-
|
1628
|
+
if (msg == NULL) {
|
1629
|
+
rv += uint32_pack(0, scratch + rv);
|
1630
|
+
buffer->append(buffer, rv, scratch);
|
1631
|
+
} else {
|
1632
|
+
size_t sublen = protobuf_c_message_get_packed_size(msg);
|
1633
|
+
rv += uint32_pack(sublen, scratch + rv);
|
1634
|
+
buffer->append(buffer, rv, scratch);
|
1635
|
+
protobuf_c_message_pack_to_buffer(msg, buffer);
|
1636
|
+
rv += sublen;
|
1637
|
+
}
|
1637
1638
|
break;
|
1638
1639
|
}
|
1639
1640
|
default:
|
@@ -2063,7 +2064,7 @@ static size_t
|
|
2063
2064
|
parse_tag_and_wiretype(size_t len,
|
2064
2065
|
const uint8_t *data,
|
2065
2066
|
uint32_t *tag_out,
|
2066
|
-
|
2067
|
+
uint8_t *wiretype_out)
|
2067
2068
|
{
|
2068
2069
|
unsigned max_rv = len > 5 ? 5 : len;
|
2069
2070
|
uint32_t tag = (data[0] & 0x7f) >> 3;
|
@@ -2095,9 +2096,9 @@ parse_tag_and_wiretype(size_t len,
|
|
2095
2096
|
|
2096
2097
|
/* sizeof(ScannedMember) must be <= (1UL<<BOUND_SIZEOF_SCANNED_MEMBER_LOG2) */
|
2097
2098
|
#define BOUND_SIZEOF_SCANNED_MEMBER_LOG2 5
|
2098
|
-
typedef struct
|
2099
|
+
typedef struct ScannedMember ScannedMember;
|
2099
2100
|
/** Field as it's being read. */
|
2100
|
-
struct
|
2101
|
+
struct ScannedMember {
|
2101
2102
|
uint32_t tag; /**< Field tag. */
|
2102
2103
|
uint8_t wire_type; /**< Field type. */
|
2103
2104
|
uint8_t length_prefix_len; /**< Prefix length. */
|
@@ -2132,11 +2133,13 @@ scan_length_prefixed_data(size_t len, const uint8_t *data,
|
|
2132
2133
|
// Protobuf messages should always be less than 2 GiB in size.
|
2133
2134
|
// We also want to return early here so that hdr_len + val does
|
2134
2135
|
// not overflow on 32-bit systems.
|
2135
|
-
PROTOBUF_C_UNPACK_ERROR("length prefix of %lu is too large",
|
2136
|
+
PROTOBUF_C_UNPACK_ERROR("length prefix of %lu is too large",
|
2137
|
+
(unsigned long int)val);
|
2136
2138
|
return 0;
|
2137
2139
|
}
|
2138
2140
|
if (hdr_len + val > len) {
|
2139
|
-
PROTOBUF_C_UNPACK_ERROR("data too short after length-prefix of %lu",
|
2141
|
+
PROTOBUF_C_UNPACK_ERROR("data too short after length-prefix of %lu",
|
2142
|
+
(unsigned long int)val);
|
2140
2143
|
return 0;
|
2141
2144
|
}
|
2142
2145
|
return hdr_len + val;
|
@@ -2498,7 +2501,7 @@ parse_required_member(ScannedMember *scanned_member,
|
|
2498
2501
|
{
|
2499
2502
|
unsigned len = scanned_member->len;
|
2500
2503
|
const uint8_t *data = scanned_member->data;
|
2501
|
-
|
2504
|
+
uint8_t wire_type = scanned_member->wire_type;
|
2502
2505
|
|
2503
2506
|
switch (scanned_member->field->type) {
|
2504
2507
|
case PROTOBUF_C_TYPE_ENUM:
|
@@ -2579,7 +2582,7 @@ parse_required_member(ScannedMember *scanned_member,
|
|
2579
2582
|
{
|
2580
2583
|
do_free(allocator, bd->data);
|
2581
2584
|
}
|
2582
|
-
if (len
|
2585
|
+
if (len > pref_len) {
|
2583
2586
|
bd->data = do_alloc(allocator, len - pref_len);
|
2584
2587
|
if (bd->data == NULL)
|
2585
2588
|
return FALSE;
|
@@ -2747,7 +2750,9 @@ parse_packed_repeated_member(ScannedMember *scanned_member,
|
|
2747
2750
|
const uint8_t *at = scanned_member->data + scanned_member->length_prefix_len;
|
2748
2751
|
size_t rem = scanned_member->len - scanned_member->length_prefix_len;
|
2749
2752
|
size_t count = 0;
|
2753
|
+
#if defined(WORDS_BIGENDIAN)
|
2750
2754
|
unsigned i;
|
2755
|
+
#endif
|
2751
2756
|
|
2752
2757
|
switch (field->type) {
|
2753
2758
|
case PROTOBUF_C_TYPE_SFIXED32:
|
@@ -2840,13 +2845,15 @@ parse_packed_repeated_member(ScannedMember *scanned_member,
|
|
2840
2845
|
}
|
2841
2846
|
break;
|
2842
2847
|
case PROTOBUF_C_TYPE_BOOL:
|
2843
|
-
|
2844
|
-
|
2845
|
-
if (
|
2848
|
+
while (rem > 0) {
|
2849
|
+
unsigned s = scan_varint(rem, at);
|
2850
|
+
if (s == 0) {
|
2846
2851
|
PROTOBUF_C_UNPACK_ERROR("bad packed-repeated boolean value");
|
2847
2852
|
return FALSE;
|
2848
2853
|
}
|
2849
|
-
((protobuf_c_boolean *) array)[
|
2854
|
+
((protobuf_c_boolean *) array)[count++] = parse_boolean(s, at);
|
2855
|
+
at += s;
|
2856
|
+
rem -= s;
|
2850
2857
|
}
|
2851
2858
|
break;
|
2852
2859
|
default:
|
@@ -3080,7 +3087,7 @@ protobuf_c_message_unpack(const ProtobufCMessageDescriptor *desc,
|
|
3080
3087
|
|
3081
3088
|
while (rem > 0) {
|
3082
3089
|
uint32_t tag;
|
3083
|
-
|
3090
|
+
uint8_t wire_type;
|
3084
3091
|
size_t used = parse_tag_and_wiretype(rem, at, &tag, &wire_type);
|
3085
3092
|
const ProtobufCFieldDescriptor *field;
|
3086
3093
|
ScannedMember tmp;
|
@@ -3657,4 +3664,4 @@ protobuf_c_service_descriptor_get_method_by_name(const ProtobufCServiceDescripto
|
|
3657
3664
|
if (strcmp(desc->methods[desc->method_indices_by_name[start]].name, name) == 0)
|
3658
3665
|
return desc->methods + desc->method_indices_by_name[start];
|
3659
3666
|
return NULL;
|
3660
|
-
}
|
3667
|
+
}
|
@@ -28,6 +28,7 @@
|
|
28
28
|
* - CurrentMemoryContext
|
29
29
|
* - MemoryContextDelete
|
30
30
|
* - palloc0
|
31
|
+
* - MemoryContextAllocExtended
|
31
32
|
*--------------------------------------------------------------------
|
32
33
|
*/
|
33
34
|
|
@@ -840,7 +841,42 @@ MemoryContextAllocZeroAligned(MemoryContext context, Size size)
|
|
840
841
|
* MemoryContextAllocExtended
|
841
842
|
* Allocate space within the specified context using the given flags.
|
842
843
|
*/
|
844
|
+
void *
|
845
|
+
MemoryContextAllocExtended(MemoryContext context, Size size, int flags)
|
846
|
+
{
|
847
|
+
void *ret;
|
848
|
+
|
849
|
+
AssertArg(MemoryContextIsValid(context));
|
850
|
+
AssertNotInCriticalSection(context);
|
851
|
+
|
852
|
+
if (((flags & MCXT_ALLOC_HUGE) != 0 && !AllocHugeSizeIsValid(size)) ||
|
853
|
+
((flags & MCXT_ALLOC_HUGE) == 0 && !AllocSizeIsValid(size)))
|
854
|
+
elog(ERROR, "invalid memory alloc request size %zu", size);
|
855
|
+
|
856
|
+
context->isReset = false;
|
857
|
+
|
858
|
+
ret = context->methods->alloc(context, size);
|
859
|
+
if (unlikely(ret == NULL))
|
860
|
+
{
|
861
|
+
if ((flags & MCXT_ALLOC_NO_OOM) == 0)
|
862
|
+
{
|
863
|
+
MemoryContextStats(TopMemoryContext);
|
864
|
+
ereport(ERROR,
|
865
|
+
(errcode(ERRCODE_OUT_OF_MEMORY),
|
866
|
+
errmsg("out of memory"),
|
867
|
+
errdetail("Failed on request of size %zu in memory context \"%s\".",
|
868
|
+
size, context->name)));
|
869
|
+
}
|
870
|
+
return NULL;
|
871
|
+
}
|
843
872
|
|
873
|
+
VALGRIND_MEMPOOL_ALLOC(context, ret, size);
|
874
|
+
|
875
|
+
if ((flags & MCXT_ALLOC_ZERO) != 0)
|
876
|
+
MemSetAligned(ret, 0, size);
|
877
|
+
|
878
|
+
return ret;
|
879
|
+
}
|
844
880
|
|
845
881
|
void *
|
846
882
|
palloc(Size size)
|
@@ -0,0 +1,420 @@
|
|
1
|
+
/*--------------------------------------------------------------------
|
2
|
+
* Symbols referenced in this file:
|
3
|
+
* - hash_bytes
|
4
|
+
*--------------------------------------------------------------------
|
5
|
+
*/
|
6
|
+
|
7
|
+
/*-------------------------------------------------------------------------
|
8
|
+
*
|
9
|
+
* hashfn.c
|
10
|
+
* Generic hashing functions, and hash functions for use in dynahash.c
|
11
|
+
* hashtables
|
12
|
+
*
|
13
|
+
*
|
14
|
+
* Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
|
15
|
+
* Portions Copyright (c) 1994, Regents of the University of California
|
16
|
+
*
|
17
|
+
*
|
18
|
+
* IDENTIFICATION
|
19
|
+
* src/common/hashfn.c
|
20
|
+
*
|
21
|
+
* NOTES
|
22
|
+
* It is expected that every bit of a hash function's 32-bit result is
|
23
|
+
* as random as every other; failure to ensure this is likely to lead
|
24
|
+
* to poor performance of hash tables. In most cases a hash
|
25
|
+
* function should use hash_bytes() or its variant hash_bytes_uint32(),
|
26
|
+
* or the wrappers hash_any() and hash_uint32 defined in hashfn.h.
|
27
|
+
*
|
28
|
+
*-------------------------------------------------------------------------
|
29
|
+
*/
|
30
|
+
#include "postgres.h"
|
31
|
+
|
32
|
+
#include "common/hashfn.h"
|
33
|
+
|
34
|
+
|
35
|
+
/*
|
36
|
+
* This hash function was written by Bob Jenkins
|
37
|
+
* (bob_jenkins@burtleburtle.net), and superficially adapted
|
38
|
+
* for PostgreSQL by Neil Conway. For more information on this
|
39
|
+
* hash function, see http://burtleburtle.net/bob/hash/doobs.html,
|
40
|
+
* or Bob's article in Dr. Dobb's Journal, Sept. 1997.
|
41
|
+
*
|
42
|
+
* In the current code, we have adopted Bob's 2006 update of his hash
|
43
|
+
* function to fetch the data a word at a time when it is suitably aligned.
|
44
|
+
* This makes for a useful speedup, at the cost of having to maintain
|
45
|
+
* four code paths (aligned vs unaligned, and little-endian vs big-endian).
|
46
|
+
* It also uses two separate mixing functions mix() and final(), instead
|
47
|
+
* of a slower multi-purpose function.
|
48
|
+
*/
|
49
|
+
|
50
|
+
/* Get a bit mask of the bits set in non-uint32 aligned addresses */
|
51
|
+
#define UINT32_ALIGN_MASK (sizeof(uint32) - 1)
|
52
|
+
|
53
|
+
/* Rotate a uint32 value left by k bits - note multiple evaluation! */
|
54
|
+
#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
|
55
|
+
|
56
|
+
/*----------
|
57
|
+
* mix -- mix 3 32-bit values reversibly.
|
58
|
+
*
|
59
|
+
* This is reversible, so any information in (a,b,c) before mix() is
|
60
|
+
* still in (a,b,c) after mix().
|
61
|
+
*
|
62
|
+
* If four pairs of (a,b,c) inputs are run through mix(), or through
|
63
|
+
* mix() in reverse, there are at least 32 bits of the output that
|
64
|
+
* are sometimes the same for one pair and different for another pair.
|
65
|
+
* This was tested for:
|
66
|
+
* * pairs that differed by one bit, by two bits, in any combination
|
67
|
+
* of top bits of (a,b,c), or in any combination of bottom bits of
|
68
|
+
* (a,b,c).
|
69
|
+
* * "differ" is defined as +, -, ^, or ~^. For + and -, I transformed
|
70
|
+
* the output delta to a Gray code (a^(a>>1)) so a string of 1's (as
|
71
|
+
* is commonly produced by subtraction) look like a single 1-bit
|
72
|
+
* difference.
|
73
|
+
* * the base values were pseudorandom, all zero but one bit set, or
|
74
|
+
* all zero plus a counter that starts at zero.
|
75
|
+
*
|
76
|
+
* This does not achieve avalanche. There are input bits of (a,b,c)
|
77
|
+
* that fail to affect some output bits of (a,b,c), especially of a. The
|
78
|
+
* most thoroughly mixed value is c, but it doesn't really even achieve
|
79
|
+
* avalanche in c.
|
80
|
+
*
|
81
|
+
* This allows some parallelism. Read-after-writes are good at doubling
|
82
|
+
* the number of bits affected, so the goal of mixing pulls in the opposite
|
83
|
+
* direction from the goal of parallelism. I did what I could. Rotates
|
84
|
+
* seem to cost as much as shifts on every machine I could lay my hands on,
|
85
|
+
* and rotates are much kinder to the top and bottom bits, so I used rotates.
|
86
|
+
*----------
|
87
|
+
*/
|
88
|
+
#define mix(a,b,c) \
|
89
|
+
{ \
|
90
|
+
a -= c; a ^= rot(c, 4); c += b; \
|
91
|
+
b -= a; b ^= rot(a, 6); a += c; \
|
92
|
+
c -= b; c ^= rot(b, 8); b += a; \
|
93
|
+
a -= c; a ^= rot(c,16); c += b; \
|
94
|
+
b -= a; b ^= rot(a,19); a += c; \
|
95
|
+
c -= b; c ^= rot(b, 4); b += a; \
|
96
|
+
}
|
97
|
+
|
98
|
+
/*----------
|
99
|
+
* final -- final mixing of 3 32-bit values (a,b,c) into c
|
100
|
+
*
|
101
|
+
* Pairs of (a,b,c) values differing in only a few bits will usually
|
102
|
+
* produce values of c that look totally different. This was tested for
|
103
|
+
* * pairs that differed by one bit, by two bits, in any combination
|
104
|
+
* of top bits of (a,b,c), or in any combination of bottom bits of
|
105
|
+
* (a,b,c).
|
106
|
+
* * "differ" is defined as +, -, ^, or ~^. For + and -, I transformed
|
107
|
+
* the output delta to a Gray code (a^(a>>1)) so a string of 1's (as
|
108
|
+
* is commonly produced by subtraction) look like a single 1-bit
|
109
|
+
* difference.
|
110
|
+
* * the base values were pseudorandom, all zero but one bit set, or
|
111
|
+
* all zero plus a counter that starts at zero.
|
112
|
+
*
|
113
|
+
* The use of separate functions for mix() and final() allow for a
|
114
|
+
* substantial performance increase since final() does not need to
|
115
|
+
* do well in reverse, but is does need to affect all output bits.
|
116
|
+
* mix(), on the other hand, does not need to affect all output
|
117
|
+
* bits (affecting 32 bits is enough). The original hash function had
|
118
|
+
* a single mixing operation that had to satisfy both sets of requirements
|
119
|
+
* and was slower as a result.
|
120
|
+
*----------
|
121
|
+
*/
|
122
|
+
#define final(a,b,c) \
|
123
|
+
{ \
|
124
|
+
c ^= b; c -= rot(b,14); \
|
125
|
+
a ^= c; a -= rot(c,11); \
|
126
|
+
b ^= a; b -= rot(a,25); \
|
127
|
+
c ^= b; c -= rot(b,16); \
|
128
|
+
a ^= c; a -= rot(c, 4); \
|
129
|
+
b ^= a; b -= rot(a,14); \
|
130
|
+
c ^= b; c -= rot(b,24); \
|
131
|
+
}
|
132
|
+
|
133
|
+
/*
|
134
|
+
* hash_bytes() -- hash a variable-length key into a 32-bit value
|
135
|
+
* k : the key (the unaligned variable-length array of bytes)
|
136
|
+
* len : the length of the key, counting by bytes
|
137
|
+
*
|
138
|
+
* Returns a uint32 value. Every bit of the key affects every bit of
|
139
|
+
* the return value. Every 1-bit and 2-bit delta achieves avalanche.
|
140
|
+
* About 6*len+35 instructions. The best hash table sizes are powers
|
141
|
+
* of 2. There is no need to do mod a prime (mod is sooo slow!).
|
142
|
+
* If you need less than 32 bits, use a bitmask.
|
143
|
+
*
|
144
|
+
* This procedure must never throw elog(ERROR); the ResourceOwner code
|
145
|
+
* relies on this not to fail.
|
146
|
+
*
|
147
|
+
* Note: we could easily change this function to return a 64-bit hash value
|
148
|
+
* by using the final values of both b and c. b is perhaps a little less
|
149
|
+
* well mixed than c, however.
|
150
|
+
*/
|
151
|
+
uint32
|
152
|
+
hash_bytes(const unsigned char *k, int keylen)
|
153
|
+
{
|
154
|
+
uint32 a,
|
155
|
+
b,
|
156
|
+
c,
|
157
|
+
len;
|
158
|
+
|
159
|
+
/* Set up the internal state */
|
160
|
+
len = keylen;
|
161
|
+
a = b = c = 0x9e3779b9 + len + 3923095;
|
162
|
+
|
163
|
+
/* If the source pointer is word-aligned, we use word-wide fetches */
|
164
|
+
if (((uintptr_t) k & UINT32_ALIGN_MASK) == 0)
|
165
|
+
{
|
166
|
+
/* Code path for aligned source data */
|
167
|
+
const uint32 *ka = (const uint32 *) k;
|
168
|
+
|
169
|
+
/* handle most of the key */
|
170
|
+
while (len >= 12)
|
171
|
+
{
|
172
|
+
a += ka[0];
|
173
|
+
b += ka[1];
|
174
|
+
c += ka[2];
|
175
|
+
mix(a, b, c);
|
176
|
+
ka += 3;
|
177
|
+
len -= 12;
|
178
|
+
}
|
179
|
+
|
180
|
+
/* handle the last 11 bytes */
|
181
|
+
k = (const unsigned char *) ka;
|
182
|
+
#ifdef WORDS_BIGENDIAN
|
183
|
+
switch (len)
|
184
|
+
{
|
185
|
+
case 11:
|
186
|
+
c += ((uint32) k[10] << 8);
|
187
|
+
/* fall through */
|
188
|
+
case 10:
|
189
|
+
c += ((uint32) k[9] << 16);
|
190
|
+
/* fall through */
|
191
|
+
case 9:
|
192
|
+
c += ((uint32) k[8] << 24);
|
193
|
+
/* fall through */
|
194
|
+
case 8:
|
195
|
+
/* the lowest byte of c is reserved for the length */
|
196
|
+
b += ka[1];
|
197
|
+
a += ka[0];
|
198
|
+
break;
|
199
|
+
case 7:
|
200
|
+
b += ((uint32) k[6] << 8);
|
201
|
+
/* fall through */
|
202
|
+
case 6:
|
203
|
+
b += ((uint32) k[5] << 16);
|
204
|
+
/* fall through */
|
205
|
+
case 5:
|
206
|
+
b += ((uint32) k[4] << 24);
|
207
|
+
/* fall through */
|
208
|
+
case 4:
|
209
|
+
a += ka[0];
|
210
|
+
break;
|
211
|
+
case 3:
|
212
|
+
a += ((uint32) k[2] << 8);
|
213
|
+
/* fall through */
|
214
|
+
case 2:
|
215
|
+
a += ((uint32) k[1] << 16);
|
216
|
+
/* fall through */
|
217
|
+
case 1:
|
218
|
+
a += ((uint32) k[0] << 24);
|
219
|
+
/* case 0: nothing left to add */
|
220
|
+
}
|
221
|
+
#else /* !WORDS_BIGENDIAN */
|
222
|
+
switch (len)
|
223
|
+
{
|
224
|
+
case 11:
|
225
|
+
c += ((uint32) k[10] << 24);
|
226
|
+
/* fall through */
|
227
|
+
case 10:
|
228
|
+
c += ((uint32) k[9] << 16);
|
229
|
+
/* fall through */
|
230
|
+
case 9:
|
231
|
+
c += ((uint32) k[8] << 8);
|
232
|
+
/* fall through */
|
233
|
+
case 8:
|
234
|
+
/* the lowest byte of c is reserved for the length */
|
235
|
+
b += ka[1];
|
236
|
+
a += ka[0];
|
237
|
+
break;
|
238
|
+
case 7:
|
239
|
+
b += ((uint32) k[6] << 16);
|
240
|
+
/* fall through */
|
241
|
+
case 6:
|
242
|
+
b += ((uint32) k[5] << 8);
|
243
|
+
/* fall through */
|
244
|
+
case 5:
|
245
|
+
b += k[4];
|
246
|
+
/* fall through */
|
247
|
+
case 4:
|
248
|
+
a += ka[0];
|
249
|
+
break;
|
250
|
+
case 3:
|
251
|
+
a += ((uint32) k[2] << 16);
|
252
|
+
/* fall through */
|
253
|
+
case 2:
|
254
|
+
a += ((uint32) k[1] << 8);
|
255
|
+
/* fall through */
|
256
|
+
case 1:
|
257
|
+
a += k[0];
|
258
|
+
/* case 0: nothing left to add */
|
259
|
+
}
|
260
|
+
#endif /* WORDS_BIGENDIAN */
|
261
|
+
}
|
262
|
+
else
|
263
|
+
{
|
264
|
+
/* Code path for non-aligned source data */
|
265
|
+
|
266
|
+
/* handle most of the key */
|
267
|
+
while (len >= 12)
|
268
|
+
{
|
269
|
+
#ifdef WORDS_BIGENDIAN
|
270
|
+
a += (k[3] + ((uint32) k[2] << 8) + ((uint32) k[1] << 16) + ((uint32) k[0] << 24));
|
271
|
+
b += (k[7] + ((uint32) k[6] << 8) + ((uint32) k[5] << 16) + ((uint32) k[4] << 24));
|
272
|
+
c += (k[11] + ((uint32) k[10] << 8) + ((uint32) k[9] << 16) + ((uint32) k[8] << 24));
|
273
|
+
#else /* !WORDS_BIGENDIAN */
|
274
|
+
a += (k[0] + ((uint32) k[1] << 8) + ((uint32) k[2] << 16) + ((uint32) k[3] << 24));
|
275
|
+
b += (k[4] + ((uint32) k[5] << 8) + ((uint32) k[6] << 16) + ((uint32) k[7] << 24));
|
276
|
+
c += (k[8] + ((uint32) k[9] << 8) + ((uint32) k[10] << 16) + ((uint32) k[11] << 24));
|
277
|
+
#endif /* WORDS_BIGENDIAN */
|
278
|
+
mix(a, b, c);
|
279
|
+
k += 12;
|
280
|
+
len -= 12;
|
281
|
+
}
|
282
|
+
|
283
|
+
/* handle the last 11 bytes */
|
284
|
+
#ifdef WORDS_BIGENDIAN
|
285
|
+
switch (len)
|
286
|
+
{
|
287
|
+
case 11:
|
288
|
+
c += ((uint32) k[10] << 8);
|
289
|
+
/* fall through */
|
290
|
+
case 10:
|
291
|
+
c += ((uint32) k[9] << 16);
|
292
|
+
/* fall through */
|
293
|
+
case 9:
|
294
|
+
c += ((uint32) k[8] << 24);
|
295
|
+
/* fall through */
|
296
|
+
case 8:
|
297
|
+
/* the lowest byte of c is reserved for the length */
|
298
|
+
b += k[7];
|
299
|
+
/* fall through */
|
300
|
+
case 7:
|
301
|
+
b += ((uint32) k[6] << 8);
|
302
|
+
/* fall through */
|
303
|
+
case 6:
|
304
|
+
b += ((uint32) k[5] << 16);
|
305
|
+
/* fall through */
|
306
|
+
case 5:
|
307
|
+
b += ((uint32) k[4] << 24);
|
308
|
+
/* fall through */
|
309
|
+
case 4:
|
310
|
+
a += k[3];
|
311
|
+
/* fall through */
|
312
|
+
case 3:
|
313
|
+
a += ((uint32) k[2] << 8);
|
314
|
+
/* fall through */
|
315
|
+
case 2:
|
316
|
+
a += ((uint32) k[1] << 16);
|
317
|
+
/* fall through */
|
318
|
+
case 1:
|
319
|
+
a += ((uint32) k[0] << 24);
|
320
|
+
/* case 0: nothing left to add */
|
321
|
+
}
|
322
|
+
#else /* !WORDS_BIGENDIAN */
|
323
|
+
switch (len)
|
324
|
+
{
|
325
|
+
case 11:
|
326
|
+
c += ((uint32) k[10] << 24);
|
327
|
+
/* fall through */
|
328
|
+
case 10:
|
329
|
+
c += ((uint32) k[9] << 16);
|
330
|
+
/* fall through */
|
331
|
+
case 9:
|
332
|
+
c += ((uint32) k[8] << 8);
|
333
|
+
/* fall through */
|
334
|
+
case 8:
|
335
|
+
/* the lowest byte of c is reserved for the length */
|
336
|
+
b += ((uint32) k[7] << 24);
|
337
|
+
/* fall through */
|
338
|
+
case 7:
|
339
|
+
b += ((uint32) k[6] << 16);
|
340
|
+
/* fall through */
|
341
|
+
case 6:
|
342
|
+
b += ((uint32) k[5] << 8);
|
343
|
+
/* fall through */
|
344
|
+
case 5:
|
345
|
+
b += k[4];
|
346
|
+
/* fall through */
|
347
|
+
case 4:
|
348
|
+
a += ((uint32) k[3] << 24);
|
349
|
+
/* fall through */
|
350
|
+
case 3:
|
351
|
+
a += ((uint32) k[2] << 16);
|
352
|
+
/* fall through */
|
353
|
+
case 2:
|
354
|
+
a += ((uint32) k[1] << 8);
|
355
|
+
/* fall through */
|
356
|
+
case 1:
|
357
|
+
a += k[0];
|
358
|
+
/* case 0: nothing left to add */
|
359
|
+
}
|
360
|
+
#endif /* WORDS_BIGENDIAN */
|
361
|
+
}
|
362
|
+
|
363
|
+
final(a, b, c);
|
364
|
+
|
365
|
+
/* report the result */
|
366
|
+
return c;
|
367
|
+
}
|
368
|
+
|
369
|
+
/*
|
370
|
+
* hash_bytes_extended() -- hash into a 64-bit value, using an optional seed
|
371
|
+
* k : the key (the unaligned variable-length array of bytes)
|
372
|
+
* len : the length of the key, counting by bytes
|
373
|
+
* seed : a 64-bit seed (0 means no seed)
|
374
|
+
*
|
375
|
+
* Returns a uint64 value. Otherwise similar to hash_bytes.
|
376
|
+
*/
|
377
|
+
#ifdef WORDS_BIGENDIAN
|
378
|
+
#else /* !WORDS_BIGENDIAN */
|
379
|
+
#endif /* WORDS_BIGENDIAN */
|
380
|
+
#ifdef WORDS_BIGENDIAN
|
381
|
+
#else /* !WORDS_BIGENDIAN */
|
382
|
+
#endif /* WORDS_BIGENDIAN */
|
383
|
+
#ifdef WORDS_BIGENDIAN
|
384
|
+
#else /* !WORDS_BIGENDIAN */
|
385
|
+
#endif /* WORDS_BIGENDIAN */
|
386
|
+
|
387
|
+
/*
|
388
|
+
* hash_bytes_uint32() -- hash a 32-bit value to a 32-bit value
|
389
|
+
*
|
390
|
+
* This has the same result as
|
391
|
+
* hash_bytes(&k, sizeof(uint32))
|
392
|
+
* but is faster and doesn't force the caller to store k into memory.
|
393
|
+
*/
|
394
|
+
|
395
|
+
|
396
|
+
/*
|
397
|
+
* hash_bytes_uint32_extended() -- hash 32-bit value to 64-bit value, with seed
|
398
|
+
*
|
399
|
+
* Like hash_bytes_uint32, this is a convenience function.
|
400
|
+
*/
|
401
|
+
|
402
|
+
|
403
|
+
/*
|
404
|
+
* string_hash: hash function for keys that are NUL-terminated strings.
|
405
|
+
*
|
406
|
+
* NOTE: this is the default hash function if none is specified.
|
407
|
+
*/
|
408
|
+
|
409
|
+
|
410
|
+
/*
|
411
|
+
* tag_hash: hash function for fixed-size tag values
|
412
|
+
*/
|
413
|
+
|
414
|
+
|
415
|
+
/*
|
416
|
+
* uint32_hash: hash function for keys that are uint32 or int32
|
417
|
+
*
|
418
|
+
* (tag_hash works for this case too, but is slower)
|
419
|
+
*/
|
420
|
+
|
@@ -6147,7 +6147,7 @@ plpgsql_sql_error_callback(void *arg)
|
|
6147
6147
|
* This is handled the same as in check_sql_expr(), and we likewise
|
6148
6148
|
* expect that the given string is a copy from the source text.
|
6149
6149
|
*/
|
6150
|
-
static PLpgSQL_type * parse_datatype(const char *string, int location) { PLpgSQL_type *typ; typ = (PLpgSQL_type *) palloc0(sizeof(PLpgSQL_type)); typ->typname = pstrdup(string); typ->ttype = PLPGSQL_TTYPE_SCALAR; return typ; }
|
6150
|
+
static PLpgSQL_type * parse_datatype(const char *string, int location) { PLpgSQL_type *typ; typ = (PLpgSQL_type *) palloc0(sizeof(PLpgSQL_type)); typ->typname = pstrdup(string); typ->ttype = strcmp(string, "RECORD") == 0 ? PLPGSQL_TTYPE_REC : PLPGSQL_TTYPE_SCALAR; return typ; }
|
6151
6151
|
|
6152
6152
|
|
6153
6153
|
/*
|
@@ -5,7 +5,7 @@ module PgQuery
|
|
5
5
|
#
|
6
6
|
# Note: This also traverses into sub-selects.
|
7
7
|
def filter_columns # rubocop:disable Metrics/CyclomaticComplexity
|
8
|
-
|
8
|
+
load_objects! if @aliases.nil?
|
9
9
|
|
10
10
|
# Get condition items from the parsetree
|
11
11
|
statements = @tree.stmts.dup.to_a.map(&:stmt)
|
@@ -42,9 +42,9 @@ module PgQuery
|
|
42
42
|
statements << item.common_table_expr.ctequery if item.node == :common_table_expr
|
43
43
|
end
|
44
44
|
end
|
45
|
-
when :SETOP_UNION
|
46
|
-
statements << statement.select_stmt.larg if statement.select_stmt.larg
|
47
|
-
statements << statement.select_stmt.rarg if statement.select_stmt.rarg
|
45
|
+
when :SETOP_UNION, :SETOP_EXCEPT, :SETOP_INTERSECT
|
46
|
+
statements << PgQuery::Node.new(select_stmt: statement.select_stmt.larg) if statement.select_stmt.larg
|
47
|
+
statements << PgQuery::Node.new(select_stmt: statement.select_stmt.rarg) if statement.select_stmt.rarg
|
48
48
|
end
|
49
49
|
when :update_stmt
|
50
50
|
condition_items << statement.update_stmt.where_clause if statement.update_stmt.where_clause
|
data/lib/pg_query/fingerprint.rb
CHANGED
@@ -60,9 +60,7 @@ module PgQuery
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def node_protobuf_field_name_to_json_name(node_class, field)
|
63
|
-
|
64
|
-
# node_class.descriptor.find { |d| d.name == field.to_s }.json_name
|
65
|
-
INTERNAL_PROTO_FIELD_NAME_TO_JSON_NAME.fetch([node_class, field])
|
63
|
+
node_class.descriptor.find { |d| d.name == field.to_s }.json_name
|
66
64
|
end
|
67
65
|
|
68
66
|
def fingerprint_node(node, hash, parent_node_name = nil, parent_field_name = nil) # rubocop:disable Metrics/CyclomaticComplexity
|