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 1rnfg2-00ES69-8p for pgsql-hackers@arkaria.postgresql.org; Fri, 22 Mar 2024 14:15:23 +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 1rnfg0-0044YK-NI for pgsql-hackers@arkaria.postgresql.org; Fri, 22 Mar 2024 14:15:21 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rnffz-0044Y3-PO for pgsql-hackers@lists.postgresql.org; Fri, 22 Mar 2024 14:15:20 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rnffr-005urP-Vu for pgsql-hackers@postgresql.org; Fri, 22 Mar 2024 14:15:19 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 6A8A15C0064; Fri, 22 Mar 2024 10:15:09 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Fri, 22 Mar 2024 10:15:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eisentraut.org; h=cc:cc:content-transfer-encoding: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=fm1; t=1711116909; x=1711203309; bh=UD2vNZoJtcGaAL+1pVY555fO0vUkXKzF 5eV1Br82yjo=; b=yslS3xHjrmdUp8A8OMLLHOEw3d+ioP5RoiFSNMbsmY9H9w83 A+ai4GLNHz8WrFPtCaeybONrLMy59FeJswr9IG94pm2dsQSkxb6VQdoceHkQLD0u NRKUInf/UmT21NZrPzqJ6kz3I5ChPa828Yv0oPK2olNkmcG/dXpPAcEANyWztQAQ RhAvcXN8iJI7w0y6fGCehGAXl7+p5ZMrJK+O+eb1c9PGvtWQCOuAZw1HOlppSQjB iDepHtnj+1oTm2LCeQ2pVghVgn7ar7zP+y3KIXwjd5iUtSHsUpb8cbUNB7TpnIiH RwbQdzdjob7iOYH5KTqcsTv58vlwm9WE+KiJQQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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=1711116909; x= 1711203309; bh=UD2vNZoJtcGaAL+1pVY555fO0vUkXKzF5eV1Br82yjo=; b=a 4aCJtudwiM6QwvQQdOzY8YaLjSoDg/rUicTOo/71crvqt6xImaglJcWc4tCJ+nzm DfwwHNNp5BxRdnSFfx0nFmWaJ4ZJS8CBE9NtsSWcmIGlXQSWEprkikYJZxs3ifIY 4AH7S2T3RXzQG3Voo4vkVaW8nfK050xR/2xqkUbkwe0u920+gNQdkMY+Xon1LkXJ Cu/R1Id3t2sWqXPyKddSHvFVHUyE7x0O6ZAtEigQ1GegKdQGFgMcvjDG6Q0uGv+9 otDz1xP8HHHtjaCtri3wC2VtCV+XfKIZuJ4umKxdTIZle/VpYQhS2vENrU3Kls5h vqi1UnBKCtZVIAXB2/YWA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledruddtuddgtddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtvdejnecuhfhrohhmpefrvght vghrucfgihhsvghnthhrrghuthcuoehpvghtvghrsegvihhsvghnthhrrghuthdrohhrgh eqnecuggftrfgrthhtvghrnhepgfejtdfhkeeftdeugfeileehteeljeeghfeuledthfeu tedvffdukeefjefhgeehnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepphgvthgvrhesvghishgvnhhtrhgruhhtrdhorhhg X-ME-Proxy: Feedback-ID: ie0a040ee:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 22 Mar 2024 10:15:06 -0400 (EDT) Message-ID: <2cf9eaf5-057f-4dfa-ae4d-9b23c5339abe@eisentraut.org> Date: Fri, 22 Mar 2024 15:15:05 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: UUID v7 Content-Language: en-US To: "Andrey M. Borodin" Cc: Aleksander Alekseev , pgsql-hackers mailing list , Sergey Prokhorenko , Jelte Fennema-Nio , =?UTF-8?Q?Przemys=C5=82aw_Sztoch?= , "David G. Johnston" , Mat Arye , Matthias van de Meent , Nikolay Samokhvalov , Junwang Zhao References: <8AA22330-7D3A-46CF-B311-2FF874D7C713@yandex-team.ru> <1971811009.2132347.1706599708209@mail.yahoo.com> <72C1E7CB-E2EC-46CF-AD2C-B3180CED885B@yandex-team.ru> <0906F8BA-CA52-4956-AA68-E9193E50DFDF@yandex-team.ru> <10553e4c-6b66-44b9-86a7-80bb1958a767@eisentraut.org> <0C26E3AC-983E-43A4-B39E-270FF87A0464@yandex-team.ru> <0b1b5e91-177e-4362-8caf-d227d5a1ae3c@eisentraut.org> From: Peter Eisentraut In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 20.03.24 19:08, Andrey M. Borodin wrote: >> On 19 Mar 2024, at 13:55, Peter Eisentraut wrote: >> >> On 16.03.24 18:43, Andrey M. Borodin wrote: >>>> On 15 Mar 2024, at 14:47, Aleksander Alekseev wrote: >>>> >>>> +1 to the idea. I doubt that anyone will miss it. >>> PFA v22. >>> Changes: >>> 1. Squashed all editorialisation by Jelte >>> 2. Fixed my erroneous comments on using Method 2 (we are using method 1 instead) >>> 3. Remove all traces of uuid_extract_variant() >> >> I have committed a subset of this for now, namely the additions of uuid_extract_timestamp() and uuid_extract_version(). These seemed mature and agreed upon. You can rebase the rest of your patch on top of that. > > Great! Thank you! PFA v23 with rebase on HEAD. I have been studying the uuidv() function. I find this code extremely hard to follow. We don't need to copy all that documentation from the RFC 4122bis document. People can read that themselves. What I would like to see is easy to find information what from there we are implementing. Like, - UUID version 7 - fixed-length dedicated counter - counter is 18 bits - 4 bits are initialized as zero That's more or less all I would need to know what is going on. That said, I don't understand why you say it's an 18 bit counter, when you overwrite 6 bits with variant and version. Then it's just a 12 bit counter? Which is the size of the rand_a field, so that kind of makes sense. But 12 bits is the recommended minimum, and (in this patch) we don't use sub-millisecond timestamp precision, so we should probably use more than the minimum? Also, you are initializing 4 bits (I think?) to zero to guard against counter rollovers (so it's really just an 8 bit counter?). But nothing checks against such rollovers, so I don't understand the use of that. The code code be organized better. In the not-increment_counter case, you could use two separate pg_strong_random calls: One to initialize rand_b, starting at &uuid->data[8], and one to initialize the counter. Then the former could be shared between the two branches, and the code to assign the sequence_counter to the uuid fields could also be shared. I would also prefer if the normal case (not-increment_counter) were the first if branch. Some other notes on your patch: - Your rebase duplicated the documentation of uuid_extract_timestamp and uuid_extract_version. - PostgreSQL code uses uint64 etc. instead of uint64_t etc. - It seems the added includes #include "access/xlog.h" #include "utils/builtins.h" #include "utils/datetime.h" are not needed. - The static variables sequence_counter and previous_timestamp could be kept inside the uuidv7() function.