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.92) (envelope-from ) id 1jFhHX-0008Sv-23 for pgsql-general@arkaria.postgresql.org; Sat, 21 Mar 2020 16:47:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jFhHU-00076V-0h for pgsql-general@arkaria.postgresql.org; Sat, 21 Mar 2020 16:47:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jFhHS-00076E-2M for pgsql-general@lists.postgresql.org; Sat, 21 Mar 2020 16:47:27 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jFhHN-0001dj-Se for pgsql-general@lists.postgresql.org; Sat, 21 Mar 2020 16:47:25 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id D43155C01A1; Sat, 21 Mar 2020 12:47:18 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Sat, 21 Mar 2020 12:47:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=3 HJ17t09atn+RJdE7eFmcmA+pYWTCx5x9Ohhh++BL/E=; b=RvS6o+N2dLu9Q1QVb pBK6J7tAUJnMms8yVdPqrsgnTuT0DX5XZ1QM/vi4X0MlES1WBvLxTIlj51xy4ya2 zU0sW9TCnNZRb+JsyNOoVFf48wISCQyAA0JIO/rVcogw5cuIfCoS4spDPtXKxZk9 8D5KRup06630FS2iRldpQwourNahpdtSQXV9n+3OvKwV74umGwN0vFUQYNoADUXL 89UjsHmTJLygn24OPrjyCiJwrCdvaGAQAUQP31yEXpVIFyZIQRHCYD/vUFLrlpdH S+A09XwXzOkxNEtEnDi6A3BcX6hECQvJR/xq75XZ9LpSlFG7qH+KsYEx8fotwvMs blnuQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=3HJ17t09atn+RJdE7eFmcmA+pYWTCx5x9Ohhh++BL /E=; b=396JqZ90v5mAoOrZF/XHN7bSoPQQuqbzTaRYuJC1je8U/o+Ad48mtkqki vn67/e+/jILyDgleuILts6xptRqPvj4ipxVL3k+e2u68JimBi1nn//Xpl3rn4FdN WqMwM4lUyKYDRB1VlJ4NUnow+fL5KleM8n9M1Zd2VICDvEDhFui+3MUR4CAmxlP6 90O+p3x2gvYNdUQ5k4SuUbzJN4DeAZddxcwX7gWXR18Gs913vMF8WrBiFzp7bjvp w8+ZLKaqBJMlqp8ZCJis324N2yb7LAtYkcvniiOtTH/RkUd416lDmiJz0xxiIeKE /GnZuP7AT51vbbxRmeFVu37yFf/4A== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrudegfedgleegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthejredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucfkphepjedurddvuddvrdduvdelrdduleefnecuvehluhhsthgvrhfuihiivgep tdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklh grvhgvrhdrtghomh X-ME-Proxy: Received: from [192.168.1.10] (unknown [71.212.129.193]) by mail.messagingengine.com (Postfix) with ESMTPA id EA69B328005A; Sat, 21 Mar 2020 12:47:17 -0400 (EDT) Subject: Re: Could postgres12 support millions of sequences? (like 10 million) To: pabloa98 Cc: "Peter J. Holzer" , "pgsql-generallists.postgresql.org" References: <20200320225842.GA18976@hjp.at> <0D8F2D62-C0E4-4D6C-B77C-9A2FEB78898C@gmail.com> <20200320232929.GA22868@hjp.at> <03223774-abab-f2c8-9f7c-824eb545a401@aklaver.com> From: Adrian Klaver Message-ID: <2c994f4f-6627-1c4d-fac5-d3c442d197e9@aklaver.com> Date: Sat, 21 Mar 2020 09:47:17 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 3/20/20 8:13 PM, pabloa98 wrote: > > Nothing I saw that said int could not become bigint. > > > My bad. The code cannot be a bigint. Or it could be a bigint between 1 > to 99999999 :) Aah, that was the counter Peter was talking about. I missed that. As to below that is going to require more thought. > I thought it was not important. The code could be a number from 1 to > 99999999 (so an Int will be OK) assigned in order-ish. This is because > of business requirements. The code should not change in case a row is > deleted. That rules out using windowed functions. At least for this > problem. There could be some gaps if they are not too big (similar to a > serial column when a transaction is rolled back). We are more concerned > about code generation collisions (for example 2 transactions calculating > the same code value) than gaps. For each pair (group, element) the code, > once assigned should remain constant. This is because the group, the > element, and the code will become an id (business-related). So: > > group, element, code = bid > 1, 3, 1 = bid 131 > 2, 1, 1 = bid 211 > etc > > This calculated bid follows the convention described here and it is used > as a reference in other tables. Therefore it should not change. > All this weirdness is because of business requirements. I am good with a > classic serial column. But that will not map our business rules. > > Regarding to the implementation of this. Our concern is to choose > something not slow (it does not need to be super fast because there will > be more operations in other tables using the same transaction) and I > thought that creating/dropping sequences could be a solution. But I was > not sure. I am not sure how it will behave with millions of sequences. > > If there is another solution different than millions of sequences that > do not block, generate few gaps (and those gaps are small) and never > generate collisions then I will happily use it. > > I hope I described the problem completely. > > Pablo > > > -- Adrian Klaver adrian.klaver@aklaver.com