Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hN4Jo-0004wl-MP for pgsql-hackers@arkaria.postgresql.org; Sat, 04 May 2019 23:43:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hN4In-0007RO-7v for pgsql-hackers@arkaria.postgresql.org; Sat, 04 May 2019 23:42:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hN4Im-0007RG-VA for pgsql-hackers@lists.postgresql.org; Sat, 04 May 2019 23:42:44 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hN4Ih-0001Cb-Na for pgsql-hackers@lists.postgresql.org; Sat, 04 May 2019 23:42:42 +0000 Received: by mail-wr1-x442.google.com with SMTP id r7so12371018wrr.13 for ; Sat, 04 May 2019 16:42:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=HZJvuNGTIqBKacbFeDjy2uRgAJq/Z6CoPHO+sGN3NdI=; b=NZgeEpWJ+mpSW1TjBjnjoRA+fQHA2oHgtVH3zGRsLlv4bJZ7ybUR08jxP3oXtmG0OD N+LDThDji2oGRHkcJenEIrf7htXJx32k/2eXsxHQ5qeuFV6GR7BYqI9yH6cIozsZxaHu 9KfhhSoUbC81f2Cur6gvZ85RuHN/CkwkuUPjXubxbicgbtM9vM/CGW0t3W+ndxR/vosP 0pRW82XNWAdfJ3FpGDzTmjR1UR2w++AXkn26PWK++JhhhXWVRl5jdACswoHhx24BduFA 2gWmjsvelkYwdYwK0AqhpLAMNe8ksggSrsM4rAnEPcS0NWjtHGs7qZGM2MLi3ePOqUGO wkwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=HZJvuNGTIqBKacbFeDjy2uRgAJq/Z6CoPHO+sGN3NdI=; b=fL650Ofo80X7qvenHBrXvveGDie0kMhuQcnpOq52PXHz7Rj9/RHlvvWELAFfsMaRNP H9kdzhDQGORAMSOXlYlMsr/UzqYju80l1GhXNxLbp+7wG1/PlfPjnFSnohYiIkwqB5G7 2TSLCk7dK8u2NKHEEuDwUEHYNelFGhG5z68tcpSnGkHXCaivuMctthAnGmD2T7zFoahw XhGYSpf1Lwjc1sZjHe6eJ4WKqkaTeIHbuVojC52sCQghLcaryUJSddzK6hKI6MHsJnrO 957wEOTPxYO8lr8HvMe4z0Uc+1YDARigWXid+6nlE6D3wPI35d3dlhXLuRoozRIiGUlk ZcVw== X-Gm-Message-State: APjAAAXfpdsXxC7qOJeWw1Urr2/CxUGBNci6ku3UrA4QHzJ+EYfDiwFf RjsgTW17Eu2rQrHxggU1eGCuoA== X-Google-Smtp-Source: APXvYqzJk3MoSdIDohRMQvQxM5Aew4FIaYb3q8cQyMO57CEv+C2icDNyDQwEtNGPg/TDTgYvCY4jag== X-Received: by 2002:adf:e703:: with SMTP id c3mr11674082wrm.98.1557013358221; Sat, 04 May 2019 16:42:38 -0700 (PDT) Received: from localhost (ip-86-49-243-43.net.upcbroadband.cz. [86.49.243.43]) by smtp.gmail.com with ESMTPSA id m187sm4486543wmm.37.2019.05.04.16.42.34 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 04 May 2019 16:42:35 -0700 (PDT) Date: Sun, 5 May 2019 01:42:33 +0200 From: Tomas Vondra To: Tom Lane Cc: Alvaro Herrera , Pg Hackers Subject: Re: error messages in extended statistics Message-ID: <20190504234233.l66mzyun4bykvdnq@development> References: <20190503154404.GA7478@alvherre.pgsql> <10879.1556900496@sss.pgh.pa.us> <20190503194217.53bub7jqml43kml4@development> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="hoikpq3btecfgvma" Content-Disposition: inline In-Reply-To: <20190503194217.53bub7jqml43kml4@development> User-Agent: NeoMutt/20180716-1444-295967 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --hoikpq3btecfgvma Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline 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 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 --hoikpq3btecfgvma Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="stats-log-cleanup.patch" diff --git a/src/backend/statistics/dependencies.c b/src/backend/statistics/dependencies.c index 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.c index 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 --hoikpq3btecfgvma--