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 1hUhfI-0002i1-Pf for pgsql-performance@arkaria.postgresql.org; Sun, 26 May 2019 01:09:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hUhfF-0003kM-37 for pgsql-performance@arkaria.postgresql.org; Sun, 26 May 2019 01:09:29 +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 1hUhfE-0003kF-Ia for pgsql-performance@lists.postgresql.org; Sun, 26 May 2019 01:09:28 +0000 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hUhfA-000333-Ry for pgsql-performance@lists.postgresql.org; Sun, 26 May 2019 01:09:27 +0000 Received: by mail-wm1-x344.google.com with SMTP id y3so12773799wmm.2 for ; Sat, 25 May 2019 18:09:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=260bWFCgA/6SLyePEcVWYo/HE/mgOOURoVMyuxk1ac4=; b=WtQe4XJmG7YCN6sgy8YTBGdd6JW0pb/WSYKCJnqDnbtd9IPBRmyJgS/ZBMno3iW3KS VH48XNtBr1XAy6+I11zkNFM9m09mNHnFYtJL8NlNVRkBGEfPlBtJjHV7uF2D1NhQTyPc DeBSgA3i3nM9vNuv9nD6vtoQhr43S5CtPL7cIDpkYZfSseIYZsmrnflMKakiiVurCHGK MYfaeKIna1Q2K6rmVlSoFbLV8uzCKnPsXUhV/azJYNcRo8vDVJz/C3n2UEt9pUTMbEuV UyYXzI3gqZ1ZlkYFvCV82u6U5os2x9UoHzE1KiS7ZcIaDxgJloB6aI1wMNuZDFBAaRjL 8bNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=260bWFCgA/6SLyePEcVWYo/HE/mgOOURoVMyuxk1ac4=; b=cNEa8rw47IGiehaNcTDLxAss1Cj6v0eSpIw7fSK1RB+qA802tdNeP/06fQjEDZajGS l56siLNYL+gkitBHPvAb6BKhZGYXAFciR4MiH89/xum0Vu5zlEg1aZVndrPkaxIqBjip Q4JA8tGRHE5JjdvXJ/wPvOWtuGBLpZETPMYAWyQrkBrZPG0/vRbbHzHGV7JFuYrK8rLs xlBeYzcSBSV/gR96VsHStpgYj3dO1zofDE2fqY9EFB+38yhrzVVZJZY7vKEack2SVrkD T9xohHQYVtBMjOVfk6p9FWiHg81iUuCGXlIunhEhLnm2aJ9IyZbTgFAqxDuXhqTnJEDP tduA== X-Gm-Message-State: APjAAAXc5d6TTTu8DZI1RJRAA57IXt3r5Jf0ditXMK18tY6sQwn4Cj9m k6jd+mifBhAW/kKlYs3GjKfQJA== X-Google-Smtp-Source: APXvYqxSTlQ0fWDz51ah/a8zCL9MbNTh7brxsk5jMk5QIF43NoSdOXBb1VPqHyIdMngIxeFX6gMHIQ== X-Received: by 2002:a1c:4107:: with SMTP id o7mr21112457wma.122.1558832961716; Sat, 25 May 2019 18:09:21 -0700 (PDT) Received: from localhost (ip-86-49-243-43.net.upcbroadband.cz. [86.49.243.43]) by smtp.gmail.com with ESMTPSA id 197sm9322436wma.36.2019.05.25.18.09.19 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 25 May 2019 18:09:20 -0700 (PDT) Date: Sun, 26 May 2019 03:09:18 +0200 From: Tomas Vondra To: Ancoron Luciferis Cc: pgsql-performance@lists.postgresql.org Subject: Re: UUID v1 optimizations... Message-ID: <20190526010918.lrww6cw76halyu4w@development> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20180716-1444-295967 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sun, May 26, 2019 at 01:49:30AM +0200, Ancoron Luciferis wrote: >On 26/05/2019 00:14, Tomas Vondra wrote: >> On Sat, May 25, 2019 at 05:54:15PM -0400, Tom Lane wrote: >>> Ancoron Luciferis writes: >>>> On 25/05/2019 16:57, Tom Lane wrote: >>>>> (4) it in fact *wouldn't* do anything useful, because we'd still have >>>>> to sort UUIDs in the same order as today, meaning that btree index >>>>> behavior >>>>> would remain the same as before.  Plus UUID comparison would get a lot >>>>> more complicated and slower than it is now. >>> >>>> I get your first sentence, but not your second. I know that when >>>> changing the internal byte order we'd have to completed re-compute >>>> everything on-disk (from table to index data), but why would the sorting >>>> in the index have to be the same? >>> >>> Because we aren't going to change the existing sort order of UUIDs. >>> We have no idea what applications might be dependent on that. >>> >>> As Vitalii correctly pointed out, your beef is not with the physical >>> storage of UUIDs anyway: you just wish they'd sort differently, since >>> that is what determines the behavior of a btree index.  But we aren't >>> going to change the sort ordering because that's an even bigger >>> compatibility break than changing the physical storage; it'd affect >>> application-visible semantics. >>> >>> What you might want to think about is creating a function that maps >>> UUIDs into an ordering that makes sense to you, and then creating >>> a unique index over that function instead of the raw UUIDs.  That >>> would give the results you want without having to negotiate with the >>> rest of the world about whether it's okay to change the semantics >>> of type uuid. >>> >> >> FWIW that's essentially what I implemented as an extension some time >> ago. See [1] for a more detailed explanation and some benchmarks. > >Yes, I've seen that before. Pretty nice work you but together there and >I'll surely have a look at it but we certainly need the node id in >compliance with v1 UUID's so that's why we've been generating UUID's at >the application side from day 1. > >> >> The thing is - it's not really desirable to get perfectly ordered >> ordering, because that would mean we never get back to older parts of >> the index (so if you delete data, we'd never fill that space). > >Wouldn't this apply also to any sequential-looking index (e.g. on >serial)? Yes, it does apply to any index on sequential (ordered) data. If you delete data from the "old" part (but not all, so the pages don't get completely empty), that space is lost. It's available for new data, but if we only insert to "new" part of the index, that's useless. > The main issue with the UUID's is that it almost instantly >consumes a big part of the total value space (e.g. first value is >'01...' and second is coming as 'f3...') which I would assume not being >very efficient with btrees (space reclaim? - bloat). > I don't understand what you mean here. Perhaps you misunderstand how btree indexes grow? It's not like we allocate separate pages for different values/prefixes - we insert the data until a page gets full, then it's split in half. There is some dependency on the order in which the values are inserted, but AFAIK random order is generally fine. >One of our major concerns is to keep index size small (VACUUM can't be >run every minute) to fit into memory next to a lot of others. > I don't think this has much to do with vacuum - I don't see how it's related to the ordering of generated UUID values. And I don't see where the "can't run vacuum every minute" comes from. >I've experimented with the rollover "prefix" myself but found that it >makes the index too big (same or larger index size than standard v1 >UUIDs) and VACUUM too slow (almost as slow as a standard V1 UUID), >although INSERT performance wasn't that bad, our sequential UUID's where >way faster (at least pre-generated and imported with COPY to eliminate >any value generation impact). > I very much doubt that has anything to do with the prefix. You'll need to share more details about how you did your tests. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services