Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4f3b56e

Browse files
committed
Revert "Optimize various aggregate deserialization functions"
This reverts commit 608fd19. On 2nd thoughts, the StringInfo API requires that strings are NUL terminated and pointing directly to the data in a bytea Datum isn't NUL terminated. Discussion: https://postgr.es/m/CAApHDvorfO3iBZ=xpiZvp3uHtJVLyFaPBSvcAhAq2HPLnaNSwQ@mail.gmail.com
1 parent f483b20 commit 4f3b56e

File tree

3 files changed

+42
-42
lines changed

3 files changed

+42
-42
lines changed

src/backend/utils/adt/array_userfuncs.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -723,13 +723,12 @@ array_agg_deserialize(PG_FUNCTION_ARGS)
723723
sstate = PG_GETARG_BYTEA_PP(0);
724724

725725
/*
726-
* Fake up a StringInfo pointing to the bytea's value so we can "receive"
727-
* the serialized aggregate state value.
726+
* Copy the bytea into a StringInfo so that we can "receive" it using the
727+
* standard recv-function infrastructure.
728728
*/
729-
buf.data = VARDATA_ANY(sstate);
730-
buf.len = VARSIZE_ANY_EXHDR(sstate);
731-
buf.maxlen = 0;
732-
buf.cursor = 0;
729+
initStringInfo(&buf);
730+
appendBinaryStringInfo(&buf,
731+
VARDATA_ANY(sstate), VARSIZE_ANY_EXHDR(sstate));
733732

734733
/* element_type */
735734
element_type = pq_getmsgint(&buf, 4);
@@ -826,6 +825,7 @@ array_agg_deserialize(PG_FUNCTION_ARGS)
826825
}
827826

828827
pq_getmsgend(&buf);
828+
pfree(buf.data);
829829

830830
PG_RETURN_POINTER(result);
831831
}
@@ -1134,13 +1134,12 @@ array_agg_array_deserialize(PG_FUNCTION_ARGS)
11341134
sstate = PG_GETARG_BYTEA_PP(0);
11351135

11361136
/*
1137-
* Fake up a StringInfo pointing to the bytea's value so we can "receive"
1138-
* the serialized aggregate state value.
1137+
* Copy the bytea into a StringInfo so that we can "receive" it using the
1138+
* standard recv-function infrastructure.
11391139
*/
1140-
buf.data = VARDATA_ANY(sstate);
1141-
buf.len = VARSIZE_ANY_EXHDR(sstate);
1142-
buf.maxlen = 0;
1143-
buf.cursor = 0;
1140+
initStringInfo(&buf);
1141+
appendBinaryStringInfo(&buf,
1142+
VARDATA_ANY(sstate), VARSIZE_ANY_EXHDR(sstate));
11441143

11451144
/* element_type */
11461145
element_type = pq_getmsgint(&buf, 4);
@@ -1198,6 +1197,7 @@ array_agg_array_deserialize(PG_FUNCTION_ARGS)
11981197
memcpy(result->lbs, temp, sizeof(result->lbs));
11991198

12001199
pq_getmsgend(&buf);
1200+
pfree(buf.data);
12011201

12021202
PG_RETURN_POINTER(result);
12031203
}

src/backend/utils/adt/numeric.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5190,13 +5190,12 @@ numeric_avg_deserialize(PG_FUNCTION_ARGS)
51905190
init_var(&tmp_var);
51915191

51925192
/*
5193-
* Fake up a StringInfo pointing to the bytea's value so we can "receive"
5194-
* the serialized aggregate state value.
5193+
* Copy the bytea into a StringInfo so that we can "receive" it using the
5194+
* standard recv-function infrastructure.
51955195
*/
5196-
buf.data = VARDATA_ANY(sstate);
5197-
buf.len = VARSIZE_ANY_EXHDR(sstate);
5198-
buf.maxlen = 0;
5199-
buf.cursor = 0;
5196+
initStringInfo(&buf);
5197+
appendBinaryStringInfo(&buf,
5198+
VARDATA_ANY(sstate), VARSIZE_ANY_EXHDR(sstate));
52005199

52015200
result = makeNumericAggStateCurrentContext(false);
52025201

@@ -5223,6 +5222,7 @@ numeric_avg_deserialize(PG_FUNCTION_ARGS)
52235222
result->nInfcount = pq_getmsgint64(&buf);
52245223

52255224
pq_getmsgend(&buf);
5225+
pfree(buf.data);
52265226

52275227
free_var(&tmp_var);
52285228

@@ -5306,13 +5306,12 @@ numeric_deserialize(PG_FUNCTION_ARGS)
53065306
init_var(&tmp_var);
53075307

53085308
/*
5309-
* Fake up a StringInfo pointing to the bytea's value so we can "receive"
5310-
* the serialized aggregate state value.
5309+
* Copy the bytea into a StringInfo so that we can "receive" it using the
5310+
* standard recv-function infrastructure.
53115311
*/
5312-
buf.data = VARDATA_ANY(sstate);
5313-
buf.len = VARSIZE_ANY_EXHDR(sstate);
5314-
buf.maxlen = 0;
5315-
buf.cursor = 0;
5312+
initStringInfo(&buf);
5313+
appendBinaryStringInfo(&buf,
5314+
VARDATA_ANY(sstate), VARSIZE_ANY_EXHDR(sstate));
53165315

53175316
result = makeNumericAggStateCurrentContext(false);
53185317

@@ -5343,6 +5342,7 @@ numeric_deserialize(PG_FUNCTION_ARGS)
53435342
result->nInfcount = pq_getmsgint64(&buf);
53445343

53455344
pq_getmsgend(&buf);
5345+
pfree(buf.data);
53465346

53475347
free_var(&tmp_var);
53485348

@@ -5677,13 +5677,12 @@ numeric_poly_deserialize(PG_FUNCTION_ARGS)
56775677
init_var(&tmp_var);
56785678

56795679
/*
5680-
* Fake up a StringInfo pointing to the bytea's value so we can "receive"
5681-
* the serialized aggregate state value.
5680+
* Copy the bytea into a StringInfo so that we can "receive" it using the
5681+
* standard recv-function infrastructure.
56825682
*/
5683-
buf.data = VARDATA_ANY(sstate);
5684-
buf.len = VARSIZE_ANY_EXHDR(sstate);
5685-
buf.maxlen = 0;
5686-
buf.cursor = 0;
5683+
initStringInfo(&buf);
5684+
appendBinaryStringInfo(&buf,
5685+
VARDATA_ANY(sstate), VARSIZE_ANY_EXHDR(sstate));
56875686

56885687
result = makePolyNumAggStateCurrentContext(false);
56895688

@@ -5707,6 +5706,7 @@ numeric_poly_deserialize(PG_FUNCTION_ARGS)
57075706
#endif
57085707

57095708
pq_getmsgend(&buf);
5709+
pfree(buf.data);
57105710

57115711
free_var(&tmp_var);
57125712

@@ -5868,13 +5868,12 @@ int8_avg_deserialize(PG_FUNCTION_ARGS)
58685868
init_var(&tmp_var);
58695869

58705870
/*
5871-
* Fake up a StringInfo pointing to the bytea's value so we can "receive"
5872-
* the serialized aggregate state value.
5871+
* Copy the bytea into a StringInfo so that we can "receive" it using the
5872+
* standard recv-function infrastructure.
58735873
*/
5874-
buf.data = VARDATA_ANY(sstate);
5875-
buf.len = VARSIZE_ANY_EXHDR(sstate);
5876-
buf.maxlen = 0;
5877-
buf.cursor = 0;
5874+
initStringInfo(&buf);
5875+
appendBinaryStringInfo(&buf,
5876+
VARDATA_ANY(sstate), VARSIZE_ANY_EXHDR(sstate));
58785877

58795878
result = makePolyNumAggStateCurrentContext(false);
58805879

@@ -5890,6 +5889,7 @@ int8_avg_deserialize(PG_FUNCTION_ARGS)
58905889
#endif
58915890

58925891
pq_getmsgend(&buf);
5892+
pfree(buf.data);
58935893

58945894
free_var(&tmp_var);
58955895

src/backend/utils/adt/varlena.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5289,13 +5289,12 @@ string_agg_deserialize(PG_FUNCTION_ARGS)
52895289
sstate = PG_GETARG_BYTEA_PP(0);
52905290

52915291
/*
5292-
* Fake up a StringInfo pointing to the bytea's value so we can "receive"
5293-
* the serialized aggregate state value.
5292+
* Copy the bytea into a StringInfo so that we can "receive" it using the
5293+
* standard recv-function infrastructure.
52945294
*/
5295-
buf.data = VARDATA_ANY(sstate);
5296-
buf.len = VARSIZE_ANY_EXHDR(sstate);
5297-
buf.maxlen = 0;
5298-
buf.cursor = 0;
5295+
initStringInfo(&buf);
5296+
appendBinaryStringInfo(&buf,
5297+
VARDATA_ANY(sstate), VARSIZE_ANY_EXHDR(sstate));
52995298

53005299
result = makeStringAggState(fcinfo);
53015300

@@ -5308,6 +5307,7 @@ string_agg_deserialize(PG_FUNCTION_ARGS)
53085307
appendBinaryStringInfo(result, data, datalen);
53095308

53105309
pq_getmsgend(&buf);
5310+
pfree(buf.data);
53115311

53125312
PG_RETURN_POINTER(result);
53135313
}

0 commit comments

Comments
 (0)