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 1hZLNK-0004rS-5I for pgsql-general@arkaria.postgresql.org; Fri, 07 Jun 2019 20:22:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hZLNH-0008NZ-M6 for pgsql-general@arkaria.postgresql.org; Fri, 07 Jun 2019 20:22:07 +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 1hZLNH-0008NS-9U for pgsql-general@lists.postgresql.org; Fri, 07 Jun 2019 20:22:07 +0000 Received: from mail-qt1-x843.google.com ([2607:f8b0:4864:20::843]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hZLNE-0000sq-CH for pgsql-general@lists.postgresql.org; Fri, 07 Jun 2019 20:22:06 +0000 Received: by mail-qt1-x843.google.com with SMTP id x2so2900556qtr.0 for ; Fri, 07 Jun 2019 13:22:03 -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:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=7wlljoXRerLtfByviFNHBFVek+5yVvg6l+DaRDB85QU=; b=LkH30Lz4N+RoabMTPQCV94H6BJfTVS99ASBc48xJ104gOS1ZPgl0daUmaFYI74r7T1 XnDuraLfa4y1hLz1dkvq92MvoJvXt3x9TK429x3ZbkQ5BmohPkDHiVWStkN/LsAbP/p+ j4bRTKyEFaejxUyakvueIxaAzL0cDOopsRpgRD/HtDefs5AA9zktMHyQtBgLXyyLsYgh uJewoVG/X3ofg24V7nM01uV1bxKlk2hZyz2ZtHjSp3pa9TnCRrzzrp7rdXuqjyBIKHaa gN/MVE2lCfEILOWeeJeE/IHYI2nFkA+gv5hpsPeHT1Eot/Ac2Ig6g4XBTEsZaMKN5FbD +TYw== 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:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=7wlljoXRerLtfByviFNHBFVek+5yVvg6l+DaRDB85QU=; b=kUs8902zhSowTtihirh9Z4nGXTfT9/29h4MEOwKx8rpOswoewiPSfuhIdWcpQO6C7P VuArzdB6+Cy/Nr6evEg/UwU8aGMMGdoU1KBIfY+YPjHDWHA+B+9zu4h/Z6LqK3L7gKfo RQksgmH1jWVMOHXoT0QCgGrTKSfHLXLQVNo7nsG8FBK7sb1/Z34PVIQXHpQup52y1SZL QUj4K9dTGecBxmhboTC9qlRrkJ0wrcMucFYL/2S8PmwMhgVzXkguiKtIg0uX5Y0axDJm mASQaCTbqqAW8tU0enjWNaFNW6AVKxKzn7mRwA0G/4MywfqqmCRzYvjBv3IDRroYEHvv 9ePw== X-Gm-Message-State: APjAAAXwIKohrfCPv5m3sIepTdTP/9MNZncg0Mh4yDwi1S4oaF/JG0a8 GII2kTSHVuzo45W8psIoGclX4cSFa+7jQg== X-Google-Smtp-Source: APXvYqwTYAUHXXdJH1dU2RXkE3INT7Z1hHwn9pE3XXdnp79rA7r+14mh0CAX4ZB+vhXr7oXJYt7kAg== X-Received: by 2002:a0c:afa4:: with SMTP id s33mr29296042qvc.194.1559938923294; Fri, 07 Jun 2019 13:22:03 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([177.154.145.98]) by smtp.gmail.com with ESMTPSA id k58sm1829598qtc.38.2019.06.07.13.22.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 07 Jun 2019 13:22:02 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id B455712097D; Fri, 7 Jun 2019 16:21:58 -0400 (-04) Date: Fri, 7 Jun 2019 16:21:58 -0400 From: Alvaro Herrera To: Peter Geoghegan Cc: David Rowley , "Alex V." , pgsql-general , tgl Subject: Re: Table partition with primary key in 11.3 Message-ID: <20190607202158.GA24592@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Somehow we ended up discussing this topic in a rather mistitled thread ... oh well :-) (Nowadays I hesitate to change threads' subject lines, because gmail). On 2019-Jun-07, Peter Geoghegan wrote: > On Fri, Jun 7, 2019 at 12:43 PM Alvaro Herrera wrote: > > Well, "quickly" might mean within a week. If it takes that long to > > fully remove a monthly partition to make that partition ID available to > > some future month's partition, that seems acceptable. Blocking > > DROP/DETACH for one hour is certainly not acceptable. > > I agree that synchronous clean-up of global indexes wouldn't make > sense there, and might not be very compelling in practice. > > It occurs to me that we could add a code path to nbtree page splits, > that considered removing dropped partition tuples to avert a page > split. This would be a bit like the LP_DEAD/kill_prior_tuple thing. > Technically the space used by index tuples that point to a dropped > partitions wouldn't become reclaimable immediately, but it might not > matter with this optimization. This seems useful on the surface: you drop a partition, and slowly and incrementally any index items that point to it are removed by processes scanning the index. You can't rely solely on this, though: as pointed out by Robert in the indirect index thread, doing this only means that non-scanned parts of the index to retain entries for arbitrary long, which is bad. Also, this adds latency to client-connected processes. Because you can't rely on that exclusively, and you want to reuse the partition ID eventually, you still need a cleanup process that removes those remaining index entries. This cleanup process is a background process, so it doesn't affect latency. I think it's not a good idea to add latency to clients in order to optimize a background process. > > If this scheme means that you can keep the partition identifiers stored > > in the index to, for instance, 10 bits (allowing for 1024 partitions to > > exist at any one time, including those in the process of being cleaned > > up) instead of having to expand to (say) 24 because that covers a couple > > of years of operation before having to recreate the index, it seems > > worthwhile. > > I think that we should have no inherent limit on the number of > partitions available at once, on general principle. Limiting the > number of partitions is a design that probably has a lot of sharp > edges. Yeah, I misspoke. The way I see this working is this: when a new partition is created/attached, we scan the set of partitions for that partitioned table to determine the lowest unused one; use that as partition ID for the new partition. Index entries for that partition will use the smallest possible representation for that partition ID. When a partition is dropped, a vestigial catalog entry for it remains, until all global index entries for it have been removed. This prevents reuse of the partition ID until it no longer causes harm. This way, when a partition is dropped, we have to take the time to scan all global indexes; when they've been scanned we can remove the catalog entry, and at that point the partition ID becomes available to future partitions. > The nbtree heap TID column and partition number column should probably > be a single varwidth column (not two separate columns), that is often > no wider than 6 bytes, but can be wider when there are many partitions > and/or very large partitions. That will be challenging, but it seems > like the right place to solve the problem. I think that I could make > that happen. Maybe this same representation could be used for all > nbtree indexes, not just global nbtree indexes. Maybe local nbtree indexes would have a partition ID of length 0, since that many bits are necessary to identify which table is pointed to by each index item. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services