diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2017-05-10 18:41:27 -0300 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2017-05-10 18:41:27 -0300 |
commit | b66adb7b0c83e632e0f881f828fa6f4233d01d06 (patch) | |
tree | fbc6b9a10c2c522a146818dfc5f590ea01c3c345 /src/backend/lib/stringinfo.c | |
parent | b83f4e4a25394b964a7fadc6429c7de82d62b58a (diff) | |
download | postgresql-b66adb7b0c83e632e0f881f828fa6f4233d01d06.tar.gz postgresql-b66adb7b0c83e632e0f881f828fa6f4233d01d06.zip |
Revert "Permit dump/reload of not-too-large >1GB tuples"
This reverts commits fa2fa9955280 and 42f50cb8fa98.
While the functionality that was intended to be provided by these
commits is desired, the patch didn't actually solve as many of the
problematic situations as we hoped, and it created a bunch of its own
problems. Since we're going to require more extensive changes soon for
other reasons and users have been working around these problems for a
long time already, there is no point in spending effort in fixing this
halfway measure.
Per complaint from Tom Lane.
Discussion: https://postgr.es/m/21407.1484606922@sss.pgh.pa.us
(Commit fa2fa9955280 had already been reverted in branches 9.5 as
f858524ee4f and 9.6 as e9e44a0953, so this touches master only.
Commit 42f50cb8fa98 was not present in the older branches.)
Diffstat (limited to 'src/backend/lib/stringinfo.c')
-rw-r--r-- | src/backend/lib/stringinfo.c | 71 |
1 files changed, 14 insertions, 57 deletions
diff --git a/src/backend/lib/stringinfo.c b/src/backend/lib/stringinfo.c index 3eee49beb62..fd155671443 100644 --- a/src/backend/lib/stringinfo.c +++ b/src/backend/lib/stringinfo.c @@ -4,8 +4,7 @@ * * StringInfo provides an indefinitely-extensible string data type. * It can be used to buffer either ordinary C strings (null-terminated text) - * or arbitrary binary data. All storage is allocated with palloc() and - * friends. + * or arbitrary binary data. All storage is allocated with palloc(). * * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California @@ -38,28 +37,10 @@ makeStringInfo(void) } /* - * makeLongStringInfo - * - * Same as makeStringInfo, for larger strings. - */ -StringInfo -makeLongStringInfo(void) -{ - StringInfo res; - - res = (StringInfo) palloc(sizeof(StringInfoData)); - - initLongStringInfo(res); - - return res; -} - - -/* * initStringInfo * * Initialize a StringInfoData struct (with previously undefined contents) - * to describe an empty string; don't enable long strings yet. + * to describe an empty string. */ void initStringInfo(StringInfo str) @@ -68,23 +49,10 @@ initStringInfo(StringInfo str) str->data = (char *) palloc(size); str->maxlen = size; - str->long_ok = false; resetStringInfo(str); } /* - * initLongStringInfo - * - * Same as initStringInfo, plus enable long strings. - */ -void -initLongStringInfo(StringInfo str) -{ - initStringInfo(str); - str->long_ok = true; -} - -/* * resetStringInfo * * Reset the StringInfo: the data buffer remains valid, but its @@ -174,7 +142,7 @@ appendStringInfoVA(StringInfo str, const char *fmt, va_list args) /* * Return pvsnprintf's estimate of the space needed. (Although this is * given as a size_t, we know it will fit in int because it's not more - * than either MaxAllocSize or half an int's width.) + * than MaxAllocSize.) */ return (int) nprinted; } @@ -276,17 +244,7 @@ appendBinaryStringInfo(StringInfo str, const char *data, int datalen) void enlargeStringInfo(StringInfo str, int needed) { - Size newlen; - Size limit; - - /* - * Determine the upper size limit. Because of overflow concerns outside - * of this module, we limit ourselves to 4-byte signed integer range, - * even for "long_ok" strings. - */ - limit = str->long_ok ? - (((Size) 1) << (sizeof(int32) * 8 - 1)) - 1 : - MaxAllocSize; + int newlen; /* * Guard against out-of-range "needed" values. Without this, we can get @@ -294,7 +252,7 @@ enlargeStringInfo(StringInfo str, int needed) */ if (needed < 0) /* should not happen */ elog(ERROR, "invalid string enlargement request size: %d", needed); - if (((Size) needed) >= (limit - (Size) str->len)) + if (((Size) needed) >= (MaxAllocSize - (Size) str->len)) ereport(ERROR, (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED), errmsg("out of memory"), @@ -303,7 +261,7 @@ enlargeStringInfo(StringInfo str, int needed) needed += str->len + 1; /* total space required now */ - /* Because of the above test, we now have needed <= limit */ + /* Because of the above test, we now have needed <= MaxAllocSize */ if (needed <= str->maxlen) return; /* got enough space already */ @@ -313,20 +271,19 @@ enlargeStringInfo(StringInfo str, int needed) * for efficiency, double the buffer size each time it overflows. * Actually, we might need to more than double it if 'needed' is big... */ - newlen = 2 * (Size) str->maxlen; - while ((Size) needed > newlen) + newlen = 2 * str->maxlen; + while (needed > newlen) newlen = 2 * newlen; /* - * Clamp to the limit in case we went past it. (We used to depend on - * limit <= INT32_MAX/2, to avoid overflow in the loop above; we no longer - * depend on that, but if "needed" and str->maxlen ever become wider, we - * will need similar caution here.) We will still have newlen >= needed. + * Clamp to MaxAllocSize in case we went past it. Note we are assuming + * here that MaxAllocSize <= INT_MAX/2, else the above loop could + * overflow. We will still have newlen >= needed. */ - if (newlen > limit) - newlen = limit; + if (newlen > (int) MaxAllocSize) + newlen = (int) MaxAllocSize; - str->data = (char *) repalloc_huge(str->data, newlen); + str->data = (char *) repalloc(str->data, newlen); str->maxlen = newlen; } |