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 1hkyHy-000376-Cy for pgsql-performance@arkaria.postgresql.org; Tue, 09 Jul 2019 22:08:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hkyHw-0005x5-OI for pgsql-performance@arkaria.postgresql.org; Tue, 09 Jul 2019 22:08:40 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hkyHw-0005wy-9p for pgsql-performance@lists.postgresql.org; Tue, 09 Jul 2019 22:08:40 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hkyHt-0002Bf-PU for pgsql-performance@lists.postgresql.org; Tue, 09 Jul 2019 22:08:39 +0000 Received: by mail-wm1-x341.google.com with SMTP id a15so291302wmj.5 for ; Tue, 09 Jul 2019 15:08:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=subject:to:cc:references:from:openpgp:autocrypt:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=J1ss2y8kPDpg895Q/0cv4KCcxCLnuTpwrn563mexyPo=; b=r6q3ZlHIOE08HB4nlGhB5Dkk1IXzMXg7LnToWZSievn3JO53bLyOXO+IrtjlDH16eD 6htyw/dvs3G8PommeJnkYr6TmzPiiknKQccE8ewGXAPSIL1iGTkcpp7XZ3DM1boy32RB 1LRmIwJMf2xuD/TRk64LwXLdkGAmczBAc5dTuskzpKirBQrIDsx1qnPMAr1FX/NS5RwZ AiHkk4yzhEGUufntcCqA4th9g69DcxO/X6uKxW5rSE3+PFg5Xtl7Wb93AaqeqEJ12wk3 X14BYsGIlvdlaHM3LOPCUfUbJfay275VZ4kx+lEluDumRn5HgYJFPiobDHJIdNj9M5Jp AujQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=J1ss2y8kPDpg895Q/0cv4KCcxCLnuTpwrn563mexyPo=; b=fGaHSfNCAQgKHnO8pqFeGsbjWgCv1tyuZmYQC73ivIvV8D1x73J+RPdsZi/luCgZeU AfLiVvc4zRoeZBcesVrt7swMRE56eYmvoZmxS8gHgVnfHyQ4bWrpffTA3AEzIYh/qe/4 NvomGHEfFpS/LI0tlcJWBqc9KMWr8J9Y2JQs4xDMAexU3STbIo8AY52Midgfaq//Yf8h d1mCO8Db6HAEY/rrC9tyCZ1TqsXlVes6bYbIZzfmMWpm1hc8Pmw1NkAMx2AoR+hArlsh inwXFeZe1qPxyc76xCSSvA5j+TwvFsmTdXlL5vxQ0gugF0thQ7GM6hMBFjmqoIk9YWmz lVag== X-Gm-Message-State: APjAAAXsr+7NyvXOWvMegKI/wE8XWHDdLGDXIVqtt2mCCwOzv7cDbCqa jVu+i4BLHZudnORPYFaxFyRgCC9w X-Google-Smtp-Source: APXvYqxxb+IbnJHTebFM+ghZ51TGzGPX/PGNZ+KmhHqxonz8SuhSOO8pbcoKZgd+TDwHdiz5BbKY1w== X-Received: by 2002:a7b:cb94:: with SMTP id m20mr1500661wmi.144.1562710115777; Tue, 09 Jul 2019 15:08:35 -0700 (PDT) Received: from ?IPv6:2003:e9:ef1e:eb00:5cdc:22e8:e6d0:1efd? (p200300E9EF1EEB005CDC22E8E6D01EFD.dip0.t-ipconnect.de. [2003:e9:ef1e:eb00:5cdc:22e8:e6d0:1efd]) by smtp.googlemail.com with ESMTPSA id 2sm205362wrn.29.2019.07.09.15.08.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Jul 2019 15:08:35 -0700 (PDT) Subject: Re: UUID v1 optimizations... To: Peter Geoghegan Cc: pgsql-performance@lists.postgresql.org References: <8d5f4b67-d540-8d3d-9979-808b9c1e1ca7@googlemail.com> <20635.1558796270@sss.pgh.pa.us> <19faa3aa-a103-b991-ff20-b73852085f30@googlemail.com> <14074.1558821255@sss.pgh.pa.us> <20190525221428.3yc6hhvj7aawjpjv@development> <20190526010918.lrww6cw76halyu4w@development> <6043492f-f372-2887-c686-0995da409427@googlemail.com> <79fe30f9-42d8-eaf2-a600-8c3dd0197e38@googlemail.com> From: Ancoron Luciferis Openpgp: preference=signencrypt Autocrypt: addr=ancoron.luciferis@googlemail.com; prefer-encrypt=mutual; keydata= mQINBE3Z7bUBEAC3ZYDTnxOiu0JWJR+6XzFQmJEVncGMehyuE9GBfyaNYnsNKmFITkubNVB9 tN/xgn5FJ9eg0WediTaWXigHNDDOPSNHZGaf1nHu0AQNOgpEyJETtX/A56PXQ82+VwoKCNUN v8+m5CJ8njWZlZMCVA3AcQ1vR2VRR6O0pzEVPDCDMutPytkRl+XrPoPhxMTVEmwM4jfWwmfI NgiOZnsueU78VW8Go1qTN20YdVOdVpbPWfyp8VIGYBNjEEefv5f/l+zt4Z+CQMmvunDUdaKY 85opNIMLqC3dDY0AQG+FpcDLhHWLcuGLmE+Ghiix0G3kX4QX/fH0/2KtVNdfnZtcpq+5rim0 E97PVQe4EixVD/DivpwvNMWqQ2GJlOCx52+J13ZSfe/63XpjL7TNqhR3wMnNuMidLMgLoH5z RtQ2FH9zeYlKgqMUkmwvEHVI+M4oQRE0rzgqx6xHbkPIFEov9ZziQVwCtct+Ja9ho/BXoe/T VIFVOGEp7DG12QSaiLILhzTRUkDXqa+BH9H4V2Hsv77nT2JQ7KO9pM5gb4wq4gtLFo7MMTUq jlqjD2vOm3NY3tg1s7HTggVNgGsWhh9JlNR3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ocJru pCqLD/AdS3MZLBeRGmpDWkuj4uc4/4tLDIHcmCYia47FD2OuGSbLDz4BBeEmR37CkFsxIq6f eszCf1awGfZv7i0ddVFT3gtJTBoRE6VPkpcMrYaEjhtbrGI9PwB+7rNd4V9O6qPwV450KldB FwlHzOjWNRkfDUc3sgRB3QXlH3bVsHqUVBBTXf5YwqxeQtIRe/A7ICU3kLx8BKiUZXhOoTur jG7LftY+nte9Tt8CTQ== Message-ID: <7c77ae7a-3d89-15f7-7130-e60a61dc4406@googlemail.com> Date: Wed, 10 Jul 2019 00:08:34 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 08/07/2019 02:26, Peter Geoghegan wrote: > Please don't top post -- trim the your response down so that only > still-relevant text remains. > > On Tue, Jun 11, 2019 at 1:27 PM Ancoron Luciferis > wrote: >> Primary key indexes after an ANALYZE: >> table_name | bloat | index_mb | table_mb >> -------------------+----------------+----------+---------- >> uuid_v1 | 767 MiB (49 %) | 1571.039 | 1689.195 >> uuid_v1_timestamp | 768 MiB (49 %) | 1571.039 | 1689.195 >> uuid_seq | 759 MiB (49 %) | 1562.766 | 1689.195 >> uuid_serial | 700 MiB (47 %) | 1504.047 | 1689.195 >> >> OK, sadly no reclaim in any of them. > > I don't know how you got these figures, but most likely they don't > take into account the fact that the FSM for the index has free blocks > available. You'll only notice that if you have additional page splits > that can recycle that space. Or, you could use pg_freespacemap to get > some idea. Hm, I think I've already read quite a bit about the internals of the PG b-tree index implementation but still cannot get to the answer how I could influence that on my end as I want to stay compatible with the standard UUID data storage but need time sorting support. Anyway, I've made a bit of progress in testing and now have the full tests executing unattended with the help of a script: https://github.com/ancoron/pg-uuid-test I've uploaded one of the test run results here: https://gist.github.com/ancoron/d5114b0907e8974b6808077e02f8d109 After the first mass deletion, I can now see quite some savings for both, serial and for my new time-sorted index: table_name | bloat | index_mb | table_mb -------------+-----------------+----------+---------- uuid_v1 | 1500 MiB (48 %) | 3106.406 | 3378.383 uuid_serial | 800 MiB (33 %) | 2406.453 | 3378.383 uuid_v1_ext | 800 MiB (33 %) | 2406.453 | 3378.383 ...but in a second case (DELETE old + INSERT new), the savings are gone again in both cases: table_name | bloat | index_mb | table_mb -------------+-----------------+----------+---------- uuid_v1 | 1547 MiB (49 %) | 3153.859 | 3378.383 uuid_serial | 1402 MiB (47 %) | 3008.055 | 3378.383 uuid_v1_ext | 1403 MiB (47 %) | 3008.055 | 3378.383 So, the question for me would be: Is there any kind of data that plays optimal with space-savings in a rolling (e.g. last X rows) scenario? > >> 5.) REINDEX >> Table: uuid_v1 Time: 21549.860 ms (00:21.550) >> Table: uuid_v1_timestamp Time: 27367.817 ms (00:27.368) >> Table: uuid_seq Time: 19142.711 ms (00:19.143) >> Table: uuid_serial Time: 16889.807 ms (00:16.890) >> >> Even in this case it looks as if my implementation is faster than >> anything else - which I really don't get. > > Sorting already-sorted data is faster. CREATE INDEX is mostly a big > sort operation in the case of B-Tree indexes. Understood, this seems to be confirmed by my time-sorted index in the new tests: uuid_v1: 27632.660 ms (00:27.633) uuid_serial: 20519.363 ms (00:20.519) x1.35 uuid_v1_ext: 23846.474 ms (00:23.846) x1.16 > >> I might implement a different opclass for the standard UUID to enable >> time-wise index sort order. This will naturally be very close to >> physical order but I doubt that this is something I can tell PostgreSQL, or? > > PostgreSQL only knows whether or not your page splits occur in the > rightmost page in the index -- it fills the page differently according > to whether or not that is the case. > As I've implemented the new opclass and the new tests showing the results now, I think I can say that the time-sorting behavior as opposed to rather random really benefits the overall performance, which is what I actually care about most. Cheers, Ancoron