Skip to content

Commit f858524

Browse files
committed
Revert "Permit dump/reload of not-too-large >1GB tuples"
This reverts commit 646655d. Per Tom Lane, changing the definition of StringInfoData amounts to an ABI break, which is unacceptable in back branches.
1 parent 8606271 commit f858524

File tree

4 files changed

+22
-74
lines changed

4 files changed

+22
-74
lines changed

src/backend/access/common/heaptuple.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -741,9 +741,7 @@ heap_form_tuple(TupleDesc tupleDescriptor,
741741
* Allocate and zero the space needed. Note that the tuple body and
742742
* HeapTupleData management structure are allocated in one chunk.
743743
*/
744-
tuple = MemoryContextAllocExtended(CurrentMemoryContext,
745-
HEAPTUPLESIZE + len,
746-
MCXT_ALLOC_HUGE | MCXT_ALLOC_ZERO);
744+
tuple = (HeapTuple) palloc0(HEAPTUPLESIZE + len);
747745
tuple->t_data = td = (HeapTupleHeader) ((char *) tuple + HEAPTUPLESIZE);
748746

749747
/*

src/backend/commands/copy.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ ReceiveCopyBegin(CopyState cstate)
400400
pq_sendint(&buf, format, 2); /* per-column formats */
401401
pq_endmessage(&buf);
402402
cstate->copy_dest = COPY_NEW_FE;
403-
cstate->fe_msgbuf = makeLongStringInfo();
403+
cstate->fe_msgbuf = makeStringInfo();
404404
}
405405
else if (PG_PROTOCOL_MAJOR(FrontendProtocol) >= 2)
406406
{
@@ -1865,7 +1865,7 @@ CopyTo(CopyState cstate)
18651865
cstate->null_print_client = cstate->null_print; /* default */
18661866

18671867
/* We use fe_msgbuf as a per-row buffer regardless of copy_dest */
1868-
cstate->fe_msgbuf = makeLongStringInfo();
1868+
cstate->fe_msgbuf = makeStringInfo();
18691869

18701870
/* Get info about the columns we need to process. */
18711871
cstate->out_functions = (FmgrInfo *) palloc(num_phys_attrs * sizeof(FmgrInfo));
@@ -2681,8 +2681,8 @@ BeginCopyFrom(Relation rel,
26812681
cstate->cur_attval = NULL;
26822682

26832683
/* Set up variables to avoid per-attribute overhead. */
2684-
initLongStringInfo(&cstate->attribute_buf);
2685-
initLongStringInfo(&cstate->line_buf);
2684+
initStringInfo(&cstate->attribute_buf);
2685+
initStringInfo(&cstate->line_buf);
26862686
cstate->line_buf_converted = false;
26872687
cstate->raw_buf = (char *) palloc(RAW_BUF_SIZE + 1);
26882688
cstate->raw_buf_index = cstate->raw_buf_len = 0;

src/backend/lib/stringinfo.c

Lines changed: 12 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
*
55
* StringInfo provides an indefinitely-extensible string data type.
66
* It can be used to buffer either ordinary C strings (null-terminated text)
7-
* or arbitrary binary data. All storage is allocated with palloc() and
8-
* friends.
7+
* or arbitrary binary data. All storage is allocated with palloc().
98
*
109
* Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group
1110
* Portions Copyright (c) 1994, Regents of the University of California
@@ -37,29 +36,11 @@ makeStringInfo(void)
3736
return res;
3837
}
3938

40-
/*
41-
* makeLongStringInfo
42-
*
43-
* Same as makeStringInfo, for larger strings.
44-
*/
45-
StringInfo
46-
makeLongStringInfo(void)
47-
{
48-
StringInfo res;
49-
50-
res = (StringInfo) palloc(sizeof(StringInfoData));
51-
52-
initLongStringInfo(res);
53-
54-
return res;
55-
}
56-
57-
5839
/*
5940
* initStringInfo
6041
*
6142
* Initialize a StringInfoData struct (with previously undefined contents)
62-
* to describe an empty string; don't enable long strings yet.
43+
* to describe an empty string.
6344
*/
6445
void
6546
initStringInfo(StringInfo str)
@@ -68,22 +49,9 @@ initStringInfo(StringInfo str)
6849

6950
str->data = (char *) palloc(size);
7051
str->maxlen = size;
71-
str->long_ok = false;
7252
resetStringInfo(str);
7353
}
7454

75-
/*
76-
* initLongStringInfo
77-
*
78-
* Same as initStringInfo, plus enable long strings.
79-
*/
80-
void
81-
initLongStringInfo(StringInfo str)
82-
{
83-
initStringInfo(str);
84-
str->long_ok = true;
85-
}
86-
8755
/*
8856
* resetStringInfo
8957
*
@@ -174,7 +142,7 @@ appendStringInfoVA(StringInfo str, const char *fmt, va_list args)
174142
/*
175143
* Return pvsnprintf's estimate of the space needed. (Although this is
176144
* given as a size_t, we know it will fit in int because it's not more
177-
* than either MaxAllocSize or half an int's width.)
145+
* than MaxAllocSize.)
178146
*/
179147
return (int) nprinted;
180148
}
@@ -276,25 +244,15 @@ appendBinaryStringInfo(StringInfo str, const char *data, int datalen)
276244
void
277245
enlargeStringInfo(StringInfo str, int needed)
278246
{
279-
Size newlen;
280-
Size limit;
281-
282-
/*
283-
* Determine the upper size limit. Because of overflow concerns outside
284-
* of this module, we limit ourselves to 4-byte signed integer range,
285-
* even for "long_ok" strings.
286-
*/
287-
limit = str->long_ok ?
288-
(((Size) 1) << (sizeof(int32) * 8 - 1)) - 1 :
289-
MaxAllocSize;
247+
int newlen;
290248

291249
/*
292250
* Guard against out-of-range "needed" values. Without this, we can get
293251
* an overflow or infinite loop in the following.
294252
*/
295253
if (needed < 0) /* should not happen */
296254
elog(ERROR, "invalid string enlargement request size: %d", needed);
297-
if (((Size) needed) >= (limit - (Size) str->len))
255+
if (((Size) needed) >= (MaxAllocSize - (Size) str->len))
298256
ereport(ERROR,
299257
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
300258
errmsg("out of memory"),
@@ -303,7 +261,7 @@ enlargeStringInfo(StringInfo str, int needed)
303261

304262
needed += str->len + 1; /* total space required now */
305263

306-
/* Because of the above test, we now have needed <= limit */
264+
/* Because of the above test, we now have needed <= MaxAllocSize */
307265

308266
if (needed <= str->maxlen)
309267
return; /* got enough space already */
@@ -318,14 +276,14 @@ enlargeStringInfo(StringInfo str, int needed)
318276
newlen = 2 * newlen;
319277

320278
/*
321-
* Clamp to the limit in case we went past it. Note we are assuming here
322-
* that limit <= INT_MAX/2, else the above loop could overflow. We will
323-
* still have newlen >= needed.
279+
* Clamp to MaxAllocSize in case we went past it. Note we are assuming
280+
* here that MaxAllocSize <= INT_MAX/2, else the above loop could
281+
* overflow. We will still have newlen >= needed.
324282
*/
325-
if (newlen > limit)
326-
newlen = limit;
283+
if (newlen > (int) MaxAllocSize)
284+
newlen = (int) MaxAllocSize;
327285

328-
str->data = (char *) repalloc_huge(str->data, (Size) newlen);
286+
str->data = (char *) repalloc(str->data, newlen);
329287

330288
str->maxlen = newlen;
331289
}

src/include/lib/stringinfo.h

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
* cursor is initialized to zero by makeStringInfo or initStringInfo,
3131
* but is not otherwise touched by the stringinfo.c routines.
3232
* Some routines use it to scan through a StringInfo.
33-
* long_ok whether this StringInfo can allocate more than MaxAllocSize
34-
* bytes (but still up to 2GB).
3533
*-------------------------
3634
*/
3735
typedef struct StringInfoData
@@ -40,7 +38,6 @@ typedef struct StringInfoData
4038
int len;
4139
int maxlen;
4240
int cursor;
43-
bool long_ok;
4441
} StringInfoData;
4542

4643
typedef StringInfoData *StringInfo;
@@ -49,11 +46,11 @@ typedef StringInfoData *StringInfo;
4946
/*------------------------
5047
* There are two ways to create a StringInfo object initially:
5148
*
52-
* StringInfo stringptr = makeStringInfo(); // or makeLongStringInfo();
49+
* StringInfo stringptr = makeStringInfo();
5350
* Both the StringInfoData and the data buffer are palloc'd.
5451
*
5552
* StringInfoData string;
56-
* initStringInfo(&string); // or initLongStringInfo();
53+
* initStringInfo(&string);
5754
* The data buffer is palloc'd but the StringInfoData is just local.
5855
* This is the easiest approach for a StringInfo object that will
5956
* only live as long as the current routine.
@@ -70,26 +67,21 @@ typedef StringInfoData *StringInfo;
7067

7168
/*------------------------
7269
* makeStringInfo
73-
* makeLongStringInfo
74-
* Create an empty 'StringInfoData' & return a pointer to it. The former
75-
* allows up to 1 GB in size, per palloc(); the latter allows up to 2 GB.
70+
* Create an empty 'StringInfoData' & return a pointer to it.
7671
*/
7772
extern StringInfo makeStringInfo(void);
78-
extern StringInfo makeLongStringInfo(void);
7973

8074
/*------------------------
8175
* initStringInfo
82-
* initLongStringInfo
8376
* Initialize a StringInfoData struct (with previously undefined contents)
84-
* to describe an empty string. Size limits as above.
77+
* to describe an empty string.
8578
*/
8679
extern void initStringInfo(StringInfo str);
87-
extern void initLongStringInfo(StringInfo str);
8880

8981
/*------------------------
9082
* resetStringInfo
9183
* Clears the current content of the StringInfo, if any. The
92-
* StringInfo remains valid. The long_ok flag is not reset.
84+
* StringInfo remains valid.
9385
*/
9486
extern void resetStringInfo(StringInfo str);
9587

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy