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 1p5mtM-0002yA-Hr for pgsql-performance@arkaria.postgresql.org; Thu, 15 Dec 2022 11:59:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p5mtL-0004lw-4d for pgsql-performance@arkaria.postgresql.org; Thu, 15 Dec 2022 11:59:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p5mtK-0004ln-Rj for pgsql-performance@lists.postgresql.org; Thu, 15 Dec 2022 11:59:10 +0000 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1p5mtH-0008NC-RR for pgsql-performance@postgresql.org; Thu, 15 Dec 2022 11:59:09 +0000 Received: by mail-wm1-x329.google.com with SMTP id h8-20020a1c2108000000b003d1efd60b65so1564306wmh.0 for ; Thu, 15 Dec 2022 03:59:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=bw+8AsAz1Xb0ILMLVDIUmlgswAK1pJuMPiZ4wr28yJE=; b=667tCQPD1LAbGlZWjuP2EEK6dnhEL7sE5ImkIsAA0BmID9F4402E6dJYuORyBXwjfR XRWHv8t253+aKWA7m8Alt+4pQScDQDNDO/9biYJxqmMWcz7VX8uRmkroCd63FPsfY8Vk rcChbWPx+4MHDqRzUjwGU7qCE+REU9By9o42otxP8nASliOIkq43uOLTnCF1hB8u1q5B uUISYVkiK+SU3FgNsYcoUssvry4y0nDzueO4HQHBy4tQGrwE1oCaH24VWyLYuxwL4WJ4 g2osNxKQIfZfvofQk4FPJqKiHZ9uDO8Of16jk2CK8AlWN9JUlRbsoBcEF+2sa7jjOdQP NhDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=bw+8AsAz1Xb0ILMLVDIUmlgswAK1pJuMPiZ4wr28yJE=; b=4oXGRc0+6UUJQEIMVLY/wyPkBwQMMZLjJinJ33dzlKaqM0zisqNklNq1Q76rG+3S8/ WeEvVuZ0EL0txo29fHeID5YlKLt9lOiSfCcT7y0S7dp/U801uIPSssEMXffFyZLXuJq7 diM9ORWLlEiFOSXa7z6vfo7G2uXL3i59dybINDnLbJCx6yUNssc1PSoW99+rMT+0nBEI qAOUbcXQcSl9PVjkgnQwX5DYpyikcq02xwFlXKjaEPsS5IV8kxxeJ39RtoZb8mjH0ZB7 9d0AtKSDbJyZTCaFyZDpJixRGJ5jkYixGWR+0SbCdHKVFbPQI5eSQdlEuC16VQ110v9e sUjg== X-Gm-Message-State: ANoB5plZndDTMuWukIHiP/cu4o+PfMSchDpTI0OyeEUNTbx9yMaDXeDU x90FrMF4u3iAVET4eIxauXu3cwDVvZfLyfoI X-Google-Smtp-Source: AA0mqf7F4efOWoHw85k5bLr4t9pB+q7MwmsF9Vb98D4Q9x3H9JpSgY+8xcpBXfgZwVBigxmjD6YMvA== X-Received: by 2002:a1c:7504:0:b0:3cf:98e5:f72 with SMTP id o4-20020a1c7504000000b003cf98e50f72mr21848886wmc.3.1671105546432; Thu, 15 Dec 2022 03:59:06 -0800 (PST) Received: from localhost.localdomain ([88.116.133.170]) by smtp.gmail.com with ESMTPSA id y23-20020a7bcd97000000b003d1e051f671sm5567673wmj.9.2022.12.15.03.59.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 03:59:06 -0800 (PST) Message-ID: Subject: Re: time sorted UUIDs From: Laurenz Albe To: Tim Jones , "pgsql-performa." Date: Thu, 15 Dec 2022 12:59:05 +0100 In-Reply-To: <1713974836.212657.1671054994324.JavaMail.zimbra@mccarthy.co.nz> References: <1713974836.212657.1671054994324.JavaMail.zimbra@mccarthy.co.nz> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.4 (3.42.4-2.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 2022-12-15 at 10:56 +1300, Tim Jones wrote: > could someone please comment on this article https://vladmihalcea.com/uuid-database-primary-key/ > specifically re the comments (copied below) in regards to a Postgres database. > > ... > But, using a random UUID as a database table Primary Key is a bad idea for multiple reasons. > First, the UUID is huge. Every single record will need 16 bytes for the database identifier, > and this impacts all associated Foreign Key columns as well. > Second, the Primary Key column usually has an associated B+Tree index to speed up lookups or > joins, and B+Tree indexes store data in sorted order. > However, indexing random values using B+Tree causes a lot of problems: >  * Index pages will have a very low fill factor because the values come randomly. So, a page > of 8kB will end up storing just a few elements, therefore wasting a lot of space, both > on the disk and in the database memory, as index pages could be cached in the Buffer Pool. >  * Because the B+Tree index needs to rebalance itself in order to maintain its equidistant > tree structure, the random key values will cause more index page splits and merges as > there is no pre-determined order of filling the tree structure. I'd say that is quite accurate. Yours, Laurenz Albe