Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb66adb7

Browse files
committed
Revert "Permit dump/reload of not-too-large >1GB tuples"
This reverts commitsfa2fa99 and42f50cb.While the functionality that was intended to be provided by thesecommits is desired, the patch didn't actually solve as many of theproblematic situations as we hoped, and it created a bunch of its ownproblems. Since we're going to require more extensive changes soon forother reasons and users have been working around these problems for along time already, there is no point in spending effort in fixing thishalfway measure.Per complaint from Tom Lane.Discussion:https://postgr.es/m/21407.1484606922@sss.pgh.pa.us(Commitfa2fa99 had already been reverted in branches 9.5 asf858524ee4f and 9.6 ase9e44a0, so this touches master only.Commit42f50cb was not present in the older branches.)
1 parentb83f4e4 commitb66adb7

File tree

4 files changed

+24
-77
lines changed

4 files changed

+24
-77
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
@@ -394,7 +394,7 @@ ReceiveCopyBegin(CopyState cstate)
394394
pq_sendint(&buf,format,2);/* per-column formats */
395395
pq_endmessage(&buf);
396396
cstate->copy_dest=COPY_NEW_FE;
397-
cstate->fe_msgbuf=makeLongStringInfo();
397+
cstate->fe_msgbuf=makeStringInfo();
398398
}
399399
else
400400
{
@@ -1954,7 +1954,7 @@ CopyTo(CopyState cstate)
19541954
cstate->null_print_client=cstate->null_print;/* default */
19551955

19561956
/* We use fe_msgbuf as a per-row buffer regardless of copy_dest */
1957-
cstate->fe_msgbuf=makeLongStringInfo();
1957+
cstate->fe_msgbuf=makeStringInfo();
19581958

19591959
/* Get info about the columns we need to process. */
19601960
cstate->out_functions= (FmgrInfo*)palloc(num_phys_attrs*sizeof(FmgrInfo));
@@ -2909,8 +2909,8 @@ BeginCopyFrom(ParseState *pstate,
29092909
cstate->cur_attval=NULL;
29102910

29112911
/* Set up variables to avoid per-attribute overhead. */
2912-
initLongStringInfo(&cstate->attribute_buf);
2913-
initLongStringInfo(&cstate->line_buf);
2912+
initStringInfo(&cstate->attribute_buf);
2913+
initStringInfo(&cstate->line_buf);
29142914
cstate->line_buf_converted= false;
29152915
cstate->raw_buf= (char*)palloc(RAW_BUF_SIZE+1);
29162916
cstate->raw_buf_index=cstate->raw_buf_len=0;

‎src/backend/lib/stringinfo.c

Lines changed: 14 additions & 57 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-2017, PostgreSQL Global Development Group
1110
* Portions Copyright (c) 1994, Regents of the University of California
@@ -37,29 +36,11 @@ makeStringInfo(void)
3736
returnres;
3837
}
3938

40-
/*
41-
* makeLongStringInfo
42-
*
43-
* Same as makeStringInfo, for larger strings.
44-
*/
45-
StringInfo
46-
makeLongStringInfo(void)
47-
{
48-
StringInfores;
49-
50-
res= (StringInfo)palloc(sizeof(StringInfoData));
51-
52-
initLongStringInfo(res);
53-
54-
returnres;
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(StringInfostr)
@@ -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(StringInfostr)
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-
* thaneitherMaxAllocSize 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(StringInfostr,intneeded)
278246
{
279-
Sizenewlen;
280-
Sizelimit;
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+
intnewlen;
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 */
@@ -313,20 +271,19 @@ enlargeStringInfo(StringInfo str, int needed)
313271
* for efficiency, double the buffer size each time it overflows.
314272
* Actually, we might need to more than double it if 'needed' is big...
315273
*/
316-
newlen=2*(Size)str->maxlen;
317-
while ((Size)needed>newlen)
274+
newlen=2*str->maxlen;
275+
while (needed>newlen)
318276
newlen=2*newlen;
319277

320278
/*
321-
* Clamp to the limit in case we went past it. (We used to depend on
322-
* limit <= INT32_MAX/2, to avoid overflow in the loop above; we no longer
323-
* depend on that, but if "needed" and str->maxlen ever become wider, we
324-
* will need similar caution here.) We will 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.
325282
*/
326-
if (newlen>limit)
327-
newlen=limit;
283+
if (newlen>(int)MaxAllocSize)
284+
newlen=(int)MaxAllocSize;
328285

329-
str->data= (char*)repalloc_huge(str->data,newlen);
286+
str->data= (char*)repalloc(str->data,newlen);
330287

331288
str->maxlen=newlen;
332289
}

‎src/include/lib/stringinfo.h

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
*cursoris 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
typedefstructStringInfoData
@@ -40,7 +38,6 @@ typedef struct StringInfoData
4038
intlen;
4139
intmaxlen;
4240
intcursor;
43-
boollong_ok;
4441
}StringInfoData;
4542

4643
typedefStringInfoData*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
externStringInfomakeStringInfo(void);
78-
externStringInfomakeLongStringInfo(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
externvoidinitStringInfo(StringInfostr);
87-
externvoidinitLongStringInfo(StringInfostr);
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
externvoidresetStringInfo(StringInfostr);
9587

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp