Skip to content

Commit 68a2a43

Browse files
committed
Improve ereports for VACUUM's BUFFER_USAGE_LIMIT option
There's no need to check if opt->arg is NULL since defGetString() already does that and raises an ERROR if it is. Let's just remove that check. Also, combine the two remaining ERRORs into a single check. It seems better to give an indication about what sort of values we're looking for rather than just to state that the value given isn't valid. Make BUFFER_USAGE_LIMIT uppercase in this ERROR message too. It's already upper case in one other error message, so make that consistent. Reported-by: Kyotaro Horiguchi Discussion: https://postgr.es/m/20230411.102335.1643720544536884844.horikyota.ntt@gmail.com
1 parent d866f03 commit 68a2a43

File tree

2 files changed

+11
-28
lines changed

2 files changed

+11
-28
lines changed

src/backend/commands/vacuum.c

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -195,38 +195,21 @@ ExecVacuum(ParseState *pstate, VacuumStmt *vacstmt, bool isTopLevel)
195195
int result;
196196
char *vac_buffer_size;
197197

198-
if (opt->arg == NULL)
199-
{
200-
ereport(ERROR,
201-
(errcode(ERRCODE_SYNTAX_ERROR),
202-
errmsg("buffer_usage_limit option requires a valid value"),
203-
parser_errposition(pstate, opt->location)));
204-
}
205-
206198
vac_buffer_size = defGetString(opt);
207199

208-
if (!parse_int(vac_buffer_size, &result, GUC_UNIT_KB, &hintmsg))
209-
{
210-
ereport(ERROR,
211-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
212-
errmsg("value: \"%s\": is invalid for buffer_usage_limit",
213-
vac_buffer_size),
214-
hintmsg ? errhint("%s", _(hintmsg)) : 0));
215-
}
216-
217200
/*
218-
* Check that the specified size falls within the hard upper and
219-
* lower limits if it is not 0. We explicitly disallow -1 since
220-
* that behavior can be obtained by not specifying
221-
* BUFFER_USAGE_LIMIT.
201+
* Check that the specified value is valid and the size falls
202+
* within the hard upper and lower limits if it is not 0.
222203
*/
223-
if (result != 0 &&
224-
(result < MIN_BAS_VAC_RING_SIZE_KB || result > MAX_BAS_VAC_RING_SIZE_KB))
204+
if (!parse_int(vac_buffer_size, &result, GUC_UNIT_KB, &hintmsg) ||
205+
(result != 0 &&
206+
(result < MIN_BAS_VAC_RING_SIZE_KB || result > MAX_BAS_VAC_RING_SIZE_KB)))
225207
{
226208
ereport(ERROR,
227209
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
228-
errmsg("buffer_usage_limit option must be 0 or between %d kB and %d kB",
229-
MIN_BAS_VAC_RING_SIZE_KB, MAX_BAS_VAC_RING_SIZE_KB)));
210+
errmsg("BUFFER_USAGE_LIMIT option must be 0 or between %d kB and %d kB",
211+
MIN_BAS_VAC_RING_SIZE_KB, MAX_BAS_VAC_RING_SIZE_KB),
212+
hintmsg ? errhint("%s", _(hintmsg)) : 0));
230213
}
231214

232215
ring_size = result;

src/test/regress/expected/vacuum.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,13 +358,13 @@ VACUUM (BUFFER_USAGE_LIMIT 0) vac_option_tab;
358358
ANALYZE (BUFFER_USAGE_LIMIT 0) vac_option_tab;
359359
-- value exceeds max size error
360360
VACUUM (BUFFER_USAGE_LIMIT 16777220) vac_option_tab;
361-
ERROR: buffer_usage_limit option must be 0 or between 128 kB and 16777216 kB
361+
ERROR: BUFFER_USAGE_LIMIT option must be 0 or between 128 kB and 16777216 kB
362362
-- value is less than min size error
363363
VACUUM (BUFFER_USAGE_LIMIT 120) vac_option_tab;
364-
ERROR: buffer_usage_limit option must be 0 or between 128 kB and 16777216 kB
364+
ERROR: BUFFER_USAGE_LIMIT option must be 0 or between 128 kB and 16777216 kB
365365
-- integer overflow error
366366
VACUUM (BUFFER_USAGE_LIMIT 10000000000) vac_option_tab;
367-
ERROR: value: "10000000000": is invalid for buffer_usage_limit
367+
ERROR: BUFFER_USAGE_LIMIT option must be 0 or between 128 kB and 16777216 kB
368368
HINT: Value exceeds integer range.
369369
-- incompatible with VACUUM FULL error
370370
VACUUM (BUFFER_USAGE_LIMIT '512 kB', FULL) vac_option_tab;

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