From: Tomas Vondra <tomas.vondra@2ndquadrant.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: Pg Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: error messages in extended statistics
Date: Sun, 5 May 2019 01:42:33 +0200
Message-ID: <20190504234233.l66mzyun4bykvdnq@development> (raw)
In-Reply-To: <20190503194217.53bub7jqml43kml4@development>
References: <20190503154404.GA7478@alvherre.pgsql>
<10879.1556900496@sss.pgh.pa.us>
<20190503194217.53bub7jqml43kml4@development>
On Fri, May 03, 2019 at 09:42:17PM +0200, Tomas Vondra wrote:
>On Fri, May 03, 2019 at 12:21:36PM -0400, Tom Lane wrote:
>>Alvaro Herrera <alvherre@2ndquadrant.com> writes:
>>>Error reporting in extended statistics is inconsistent -- many messages
>>>that are ereport() in mvdistinct.c are elog() in the other modules.
>>>...
>>>I think this should be cleaned up, while at the same time not giving too
>>>much hassle for translators; for example, this message
>>>dependencies.c: elog(ERROR, "invalid MVDependencies size %zd (expected at least %zd)",
>>>should not only be turned into an ereport(), but also the MVDependencies
>>>part turned into a %s. (Alternatively, we could decide I was wrong and
>>>turn them all back into elogs, but I obviously vote against that.)
>>
>>FWIW, I'd vote the other way: that seems like a clear "internal error",
>>so making translators deal with it is just make-work. It should be an
>>elog. If there's a reasonably plausible way for a user to trigger an
>>error condition, then yes ereport, but if we're reporting situations
>>that couldn't happen without a server bug then elog seems fine.
>>
>
>Yeah, I agree. Most of (peshaps all) those errors are internal errors,
>and thus should be elog. I'll take care of clening this up a bit.
>
OK, so here is a patch, using elog() for all places except for the
input function, where we simply report we don't accept those values.
I agree those are internal errors, usually meaning the statistics object
was either corrupted or there's a bug in how it's built/serialized.
Users should not be able to trigger those cases (the only thing I can
think of is sending a bogus value through send/recv functions, that
simply do byteaout/byteain).
Now, what about backpatch? It's a small tweak, but it makes the life a
bit easier for translators ...
regards
--
Tomas Vondra http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Attachments:stats-log-cleanup.patch (text/plain, 2.6K) downloaddiff --git a/src/backend/statistics/dependencies.c b/src/backend/statistics/dependencies.cindex 0b26e4166d..d2464381c4 100644--- a/src/backend/statistics/dependencies.c+++ b/src/backend/statistics/dependencies.c@@ -534,9 +534,9 @@ statext_dependencies_deserialize(bytea *data)
dependencies->type, STATS_DEPS_TYPE_BASIC);
if (dependencies->ndeps == 0)
- ereport(ERROR,- (errcode(ERRCODE_DATA_CORRUPTED),- errmsg("invalid zero-length item array in MVDependencies")));+ elog(ERROR,+ (errcode(ERRCODE_DATA_CORRUPTED),+ errmsg("invalid zero-length item array in MVDependencies")));
/* what minimum bytea size do we expect for those parameters */
min_expected_size = SizeOfItem(dependencies->ndeps);
diff --git a/src/backend/statistics/mvdistinct.c b/src/backend/statistics/mvdistinct.cindex 133503cb9b..fa410c95c6 100644--- a/src/backend/statistics/mvdistinct.c+++ b/src/backend/statistics/mvdistinct.c@@ -274,27 +274,27 @@ statext_ndistinct_deserialize(bytea *data)
tmp += sizeof(uint32);
if (ndist.magic != STATS_NDISTINCT_MAGIC)
- ereport(ERROR,- (errcode(ERRCODE_DATA_CORRUPTED),- errmsg("invalid ndistinct magic %08x (expected %08x)",- ndist.magic, STATS_NDISTINCT_MAGIC)));+ elog(ERROR,+ (errcode(ERRCODE_DATA_CORRUPTED),+ errmsg("invalid ndistinct magic %08x (expected %08x)",+ ndist.magic, STATS_NDISTINCT_MAGIC)));
if (ndist.type != STATS_NDISTINCT_TYPE_BASIC)
- ereport(ERROR,- (errcode(ERRCODE_DATA_CORRUPTED),- errmsg("invalid ndistinct type %d (expected %d)",- ndist.type, STATS_NDISTINCT_TYPE_BASIC)));+ elog(ERROR,+ (errcode(ERRCODE_DATA_CORRUPTED),+ errmsg("invalid ndistinct type %d (expected %d)",+ ndist.type, STATS_NDISTINCT_TYPE_BASIC)));
if (ndist.nitems == 0)
- ereport(ERROR,- (errcode(ERRCODE_DATA_CORRUPTED),- errmsg("invalid zero-length item array in MVNDistinct")));+ elog(ERROR,+ (errcode(ERRCODE_DATA_CORRUPTED),+ errmsg("invalid zero-length item array in MVNDistinct")));
/* what minimum bytea size do we expect for those parameters */
minimum_size = MinSizeOfItems(ndist.nitems);
if (VARSIZE_ANY_EXHDR(data) < minimum_size)
- ereport(ERROR,- (errcode(ERRCODE_DATA_CORRUPTED),- errmsg("invalid MVNDistinct size %zd (expected at least %zd)",- VARSIZE_ANY_EXHDR(data), minimum_size)));+ elog(ERROR,+ (errcode(ERRCODE_DATA_CORRUPTED),+ errmsg("invalid MVNDistinct size %zd (expected at least %zd)",+ VARSIZE_ANY_EXHDR(data), minimum_size)));
/*
* Allocate space for the ndistinct items (no space for each item's
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: tomas.vondra@2ndquadrant.com, tgl@sss.pgh.pa.us, alvherre@2ndquadrant.com
Subject: Re: error messages in extended statistics
In-Reply-To: <20190504234233.l66mzyun4bykvdnq@development>
References: <20190503154404.GA7478@alvherre.pgsql> <10879.1556900496@sss.pgh.pa.us> <20190503194217.53bub7jqml43kml4@development> <20190504234233.l66mzyun4bykvdnq@development>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox