Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jjj5h-0006fA-ED for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Jun 2020 12:47:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jjj5g-0007D6-2T for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Jun 2020 12:47:24 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jjj5f-0007Cz-Ra for pgsql-hackers@lists.postgresql.org; Fri, 12 Jun 2020 12:47:23 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jjj5d-0007sO-M2 for pgsql-hackers@lists.postgresql.org; Fri, 12 Jun 2020 12:47:23 +0000 Received: from [192.168.127.1] (port=40565 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtp (Exim 4.92.3 (FreeBSD)) (envelope-from ) id 1jjj5b-000Jka-Eo; Fri, 12 Jun 2020 12:47:19 +0000 Received: from localhost ([127.0.0.1]:46820 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.93.0.4 (FreeBSD)) (envelope-from ) id 1jjj5b-00011s-23; Fri, 12 Jun 2020 12:47:19 +0000 From: Andrew Gierth To: Tom Lane Cc: pgsql-hackers@lists.postgresql.org Subject: Re: Infinities in type numeric In-Reply-To: <606717.1591924582@sss.pgh.pa.us> (Tom Lane's message of "Thu, 11 Jun 2020 21:16:22 -0400") Message-ID: <87lfks5uwl.fsf@news-spur.riddles.org.uk> References: <606717.1591924582@sss.pgh.pa.us> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (berkeley-unix) Date: Fri, 12 Jun 2020 13:47:19 +0100 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "Tom" == Tom Lane writes: Tom> @@ -359,10 +390,14 @@ typedef struct NumericSumAccum Tom> #define NumericAbbrevGetDatum(X) ((Datum) (X)) Tom> #define DatumGetNumericAbbrev(X) ((int64) (X)) Tom> #define NUMERIC_ABBREV_NAN NumericAbbrevGetDatum(PG_INT64_MIN) Tom> +#define NUMERIC_ABBREV_PINF NumericAbbrevGetDatum(PG_INT64_MIN) Tom> +#define NUMERIC_ABBREV_NINF NumericAbbrevGetDatum(PG_INT64_MAX) Tom> #else Tom> #define NumericAbbrevGetDatum(X) ((Datum) (X)) Tom> #define DatumGetNumericAbbrev(X) ((int32) (X)) Tom> #define NUMERIC_ABBREV_NAN NumericAbbrevGetDatum(PG_INT32_MIN) Tom> +#define NUMERIC_ABBREV_PINF NumericAbbrevGetDatum(PG_INT32_MIN) Tom> +#define NUMERIC_ABBREV_NINF NumericAbbrevGetDatum(PG_INT32_MAX) Tom> #endif I'd have been more inclined to go with -PG_INT64_MAX / -PG_INT32_MAX for the NUMERIC_ABBREV_PINF value. It seems more likely to be beneficial to bucket +Inf and NaN separately (and put +Inf in with the "too large to abbreviate" values) than to bucket them together so as to distinguish between +Inf and "too large" values. But this is an edge case in any event, so it probably wouldn't make a great deal of difference unless you're sorting on data with a large proportion of both +Inf and NaN values. (It would be possible to add another bucket so that "too large", +Inf, and NaN were three separate buckets, but honestly any more complexity seems not worth it for handling an edge case.) The actual changes to the abbrev stuff look fine to me. -- Andrew (irc:RhodiumToad)