Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sQmm9-00BcjL-GS for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Jul 2024 11:43:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sQmm7-0052qU-JP for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Jul 2024 11:43:19 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sQmm6-0052qK-HT for pgsql-hackers@lists.postgresql.org; Mon, 08 Jul 2024 11:43:19 +0000 Received: from fout1-smtp.messagingengine.com ([103.168.172.144]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sQmm3-0011GU-D6 for pgsql-hackers@postgresql.org; Mon, 08 Jul 2024 11:43:17 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailfout.nyi.internal (Postfix) with ESMTP id B276C13800B8; Mon, 8 Jul 2024 07:43:13 -0400 (EDT) Received: from imap48 ([10.202.2.98]) by compute6.internal (MEProxy); Mon, 08 Jul 2024 07:43:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=compiler.org; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1720438993; x=1720525393; bh=ElOSPE6M1Z 7vJoME8s8vo3Sh/GJuNEvNDllgSYUiJNc=; b=EPIg4PP46dCoBHS6HbXWaHtW3k qzvu62hVite+eTXaiiK3BmBpNqKXAqu+8Dem7sdS3ccGzt/hDsIrlrWQDwkkUFbn N00ntGgO+qzmxU7YAnox96tnawRxGqOWbpye4EyoggYst62QgiNE9IBdTDyjcgmL TNAi5MGShuoQseMMK5kM2OZh0H8hCYDN0DLNymrX0xW3PGQepQhcGZAnCv+zgCqI AiyelHWffjkKmYGQdbG/8/QhI5F7sVB34un7a2Zyz/BO9/qCrso0ovWrQzLa2EpB ckOSAmkJQtCYJYy5heOL3zjxPbLMY+BYGvodB0f5c9zOVIqTvDjjqla4tTAQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1720438993; x=1720525393; bh=ElOSPE6M1Z7vJoME8s8vo3Sh/GJu NEvNDllgSYUiJNc=; b=mVJWH4PQ0Gmnf8L43CRaN+BZBr8qP94qRAMb4kEOGj8n FIdvBCkBtlYiF1JCP2tOquUS1/kIWpI9C5kFH0oc/i4CAK1XnDpPzs9GFxKB8t13 Eo35jIhibFQDICdYIJqJzEpWv0m8IOladuHkgrsL6p+Y/zjGuxz3Ge6b2bsbc+d/ M/VZNA9cUfX1i7t3fnUj6I3Hv3ZLm/WDFdbcKMXIoOESq2HQs4IIUV6cno08HE80 jFfIDtCj0DcfiYj84V+0S4wzL4MNEAD8VZm++6WPmR4krbolKL4RoGqR6tezNNey WcTKAjX0+Xyko6Gr8WXiYv/WsyhZUp+C8kZcJpjfXQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrvdejgdegvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepofgfggfkjghffffhvfevufgtsehttd ertderredtnecuhfhrohhmpedflfhovghlucflrggtohgsshhonhdfuceojhhovghlsegt ohhmphhilhgvrhdrohhrgheqnecuggftrfgrthhtvghrnhephfefudegffdvtdetleeuhf ffkeeltddukefhkeekieelleffhfeftdffjefgjeefnecuvehluhhsthgvrhfuihiivgep tdenucfrrghrrghmpehmrghilhhfrhhomhepjhhovghlsegtohhmphhilhgvrhdrohhrgh X-ME-Proxy: Feedback-ID: ic6394509:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 4ACF531A0066; Mon, 8 Jul 2024 07:43:12 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-566-g3812ddbbc-fm-20240627.001-g3812ddbb MIME-Version: 1.0 Message-Id: In-Reply-To: References: <041fd562-e279-4457-a118-9fda593c9be9@app.fastmail.com> Date: Mon, 08 Jul 2024 13:42:51 +0200 From: "Joel Jacobson" To: "Matthias van de Meent" Cc: pgsql-hackers Subject: Re: Thoughts on NBASE=100000000 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Jul 8, 2024, at 12:45, Matthias van de Meent wrote: > On Sun, 7 Jul 2024, 22:40 Joel Jacobson, wrote: >> Today, since 64-bit architectures are dominant, NBASE=1e8 seems like it would >> have been the best choice, since the square of that still fits in >> a 64-bit signed int. > > Back then 64-bit was by far not as dominant (server and consumer chips > with AMD64 ISA only got released that year after the commit), so I > don't think 1e8 would have been the best choice at that point in time. > Would be better now, yes, but not back then. Oh, grammar mistake by me! I meant to say it "would be the best choice", in line with what I wrote above: >> Last time numeric's base was changed was back in 2003, when d72f6c75038 changed >> it from 10 to 10000. Back then, 32-bit architectures were still dominant, >> so base-10000 was clearly the best choice at this time. >> Changing NBASE might seem impossible at first, due to the existing numeric data >> on disk, and incompatibility issues when numeric data is transferred on the >> wire. >> >> Here are some ideas on how to work around some of these: >> >> - Incrementally changing the data on disk, e.g. upon UPDATE/INSERT >> and supporting both NBASE=1e4 (16-bit) and NBASE=1e8 (32-bit) >> when reading data. > > I think that a dynamic decision would make more sense here. At low > precision, the overhead of 4+1 bytes vs 2 bytes is quite significant. > This sounds important for overall storage concerns, especially if the > padding bytes (mentioned below) are added to indicate types. Right, I agree. Another idea: It seems possible to reduce the disk space for numerics that fit into one byte, i.e. 0 <= val <= 255, which could be communicated via NUMERIC_NBYTES=1. At least the value 0 should be quite common. >> - Due to the lack of a version field in the NumericVar struct, >> we need a way to detect if a Numeric value on disk uses >> the existing NBASE=1e4, or NBASE=1e8. >> One hack I've thought about is to exploit the fact that NUMERIC_NBYTES, >> defined as: >> #define NUMERIC_NBYTES(num) (VARSIZE(num) - NUMERIC_HEADER_SIZE(num)) >> will always be divisible by two, since a NumericDigit is an int16 (2 bytes). >> The idea is then to let "NUMERIC_NBYTES divisible by three" >> indicate NBASE=1e8, at the cost of one to three extra padding bytes. > > Do you perhaps mean NUMERIC_NBYTES *not divisible by 2*, i.e. an > uneven NUMERIC_NBYTES as indicator for NBASE=1e8, rather than only > multiples of 3? Oh, yes of course! Thinko. > While I don't think this is worth implementing for general usage, it > could be worth exploring for the larger numeric values, where the > relative overhead of the larger representation is lower. Yes, I agree it's definitively seems like a win for larger numeric values. Not sure about smaller numeric values, maybe it's possible to improve upon. Regards, Joel