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 1jF3U9-0004y4-Om for pgsql-general@arkaria.postgresql.org; Thu, 19 Mar 2020 22:17:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jF3U8-0005se-Eu for pgsql-general@arkaria.postgresql.org; Thu, 19 Mar 2020 22:17:52 +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 1jF3U7-0005sX-W1 for pgsql-general@lists.postgresql.org; Thu, 19 Mar 2020 22:17:52 +0000 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jF3U5-0000vg-FK for pgsql-general@lists.postgresql.org; Thu, 19 Mar 2020 22:17:50 +0000 Received: by mail-pf1-x42b.google.com with SMTP id u68so2178622pfb.2 for ; Thu, 19 Mar 2020 15:17:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=5/B6Iz7QyYXMHABaXg85vBMOrr5rnrz8PPuq5WpHjAo=; b=B8PZUARMOUmnGXiQUMz+STFAnICBheX7tmaGZ2MzjhKoDEznlKaZjRfgDGD+Fs/Got fbJQtWKNy9EiOGkGhWF0ILxTl6MAmfjiHbYzedxbpxGyfGvvBOWRwbalIGcU+dYGOe/R NE5qENyEl5oXHxa85JSdu4snnW31X1IpM6nAL/hIcSQmeEy9f3fmCwiGzqFuLyNfXo63 pyrGc54X/MNA6yAcIUsJp7M7G9QNSNQo4gJ5qRStMntJiY11bxLRXILoOSTSwl9jXbBj AXb/plBQCYlDatLexDcyNkS2dx8XJFPvUXVvBZMLnBGH7T19Q0lRXvutUtCZj73EvG/n fBnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=5/B6Iz7QyYXMHABaXg85vBMOrr5rnrz8PPuq5WpHjAo=; b=cxYZc81P81suGjIblT5aIMmiDdtkK7OzTW4J99t89vn1BbYL9x/XMOuYzt4xja3jP6 tPNRtmPU3HZUzB/huDKntJ3mg8iduhcs9Ty3QPe7Q3+vmQ/jaTjuRrySOKh2/8NisqeF p03f1AfbA0EEedRjkC42UHbCgmQWyODX/gjqq4dlCLW/Q4tcKZzyi4822u2SK2xiClxW 8eUmGPVgz6NCqaERcIPv/M37jFQxXNJ0EAsdeJU0CA+WfU4YdYxv9DFny8HuWk7L2xfI +RsEaiCKr7IVbmBtqb8EVUNH5UfWU/bBhRcPkD2Elo1Xe8HXQowcPtKfnCe7Z6nc6E1b 6nGw== X-Gm-Message-State: ANhLgQ0GnviYDLtZDJBrN7B2DZNfjbLLHDzCNGmzVAUpLxRKI21b/kNh 0kv/76YwYgja5QQNQljbppg= X-Google-Smtp-Source: ADFU+vvjWY6G5xNLN5EC91LxDJmNmmFDE3k8xQ5fGQhY2gcMg6VDXSSOSIP6BVqjvmmZaEuDARy+NA== X-Received: by 2002:a63:33c2:: with SMTP id z185mr5491019pgz.125.1584656268174; Thu, 19 Mar 2020 15:17:48 -0700 (PDT) Received: from [192.168.1.108] (c-73-63-59-118.hsd1.ut.comcast.net. [73.63.59.118]) by smtp.gmail.com with ESMTPSA id 71sm3541502pfv.8.2020.03.19.15.17.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Mar 2020 15:17:47 -0700 (PDT) From: Rob Sargent Message-Id: <7CF69CD4-AE4A-4C2B-9621-4462B4AE1726@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_8D62A5AD-A2FB-4557-9C6C-D23B2FBAF34B" Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3608.60.0.2.5\)) Subject: Re: Could postgres12 support millions of sequences? (like 10 million) Date: Thu, 19 Mar 2020 16:17:46 -0600 In-Reply-To: Cc: "pgsql-generallists.postgresql.org" To: pabloa98 References: X-Mailer: Apple Mail (2.3608.60.0.2.5) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail=_8D62A5AD-A2FB-4557-9C6C-D23B2FBAF34B Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Mar 19, 2020, at 4:13 PM, pabloa98 wrote: >=20 >=20 >=20 > On Thu, Mar 19, 2020 at 2:50 PM Rob Sargent > wrote: >=20 >=20 > > On Mar 19, 2020, at 3:36 PM, pabloa98 > wrote: > >=20 > > Hello, > >=20 > > My schema requires a counter for each combination of 2 values. = Something like: > >=20 > > CREATE TABLE counter( > > group INT NOT NULL, > > element INT NOT NULL, > > seq_number INT NOT NULL default 0, > > CONSTRAINT PRIMARY KEY (group, element) > > ); > >=20 > > For each entry in counter, aka for each (group, element) pair, the = model requires a seq_number. > >=20 > > If I use a table "counter", I could still have counter collisions = between 2 transactions. I need truly sequence behavior. Is that possible = by using a table like "counter" table, where the counter could be = increased out of the transaction so it performs as a sequence without = having race conditions between concurrent transactions? > >=20 > > The other option is to create sequences for each new pair of (group, = element) using triggers. There are millions of pairs. So this approach = will generate millions of sequences. > >=20 > > How a PostgreSQL database would behave having millions of sequences = in a schema? Would it degrade its performance? Is there any negative = impact? > >=20 > > Regards > >=20 > > Pablo > >=20 >=20 > To clarify, are you hoping for consecutive numbers as the each row is = added to the table, i.e. =E2=80=9Cserial=E2=80=9D? >=20 > What is the intension of =E2=80=9Cseq_number=E2=80=9D? > >=20 > >=20 >=20 >=20 > the idea is to have like a serial sequence, but for each pair of = (group, element). >=20 > so that when we insert rows in another table, we could have something = like: >=20 >=20 > group, element, event_id, ... > 1, 1, 1 > 1, 1, 2 > 1, 1, 3 > 2, 1, 1 > 1, 1, 4 > 1, 3, 1 > 1, 1, 5 > 1, 3, 2 > 2, 1, 2 > 2, 1, 3 >=20 > The 3rd column is the sequence number we get from the appropriate = sequence created by the trigger. > =20 > I want to implement a variation of = https://stackoverflow.com/a/30204854 = and that will generate millions = of sequences. >=20 >=20 Then I don=E2=80=99t thing group/element can be a PRIMARY KEY=20 --Apple-Mail=_8D62A5AD-A2FB-4557-9C6C-D23B2FBAF34B Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

On Mar 19, 2020, at 4:13 PM, pabloa98 <pabloa98@gmail.com> = wrote:



On Thu, Mar 19, 2020 at 2:50 PM Rob = Sargent <robjsargent@gmail.com> wrote:


> On Mar 19, 2020, at 3:36 PM, pabloa98 <pabloa98@gmail.com> wrote:
>
> Hello,
>
> My schema requires a counter for each combination of 2 values. = Something like:
>
> CREATE TABLE counter(
> group INT NOT NULL,
> element INT NOT NULL,
> seq_number INT NOT NULL default 0,
> CONSTRAINT PRIMARY KEY (group, element)
> );
>
> For each entry in counter, aka for each (group, element) pair, the = model requires a seq_number.
>
> If I use a table "counter", I could still have counter collisions = between 2 transactions. I need truly sequence behavior. Is that possible = by using a table like "counter" table, where the counter could be = increased out of the transaction so it performs as a sequence without = having race conditions between concurrent transactions?
>
> The other option is to create sequences for each new pair of = (group, element) using triggers. There are millions of pairs. So this = approach will generate millions of sequences.
>
> How a PostgreSQL database would behave having millions of sequences = in a schema? Would it degrade its performance? Is there any negative = impact?
>
> Regards
>
> Pablo
>

To clarify, are you hoping for consecutive numbers as the each row is = added to the table, i.e. =E2=80=9Cserial=E2=80=9D?

What is the intension of =E2=80=9Cseq_number=E2=80=9D?
>
>


the idea is to have like a serial sequence, = but for each pair of (group, element).

so that when we insert rows in another = table, we could have something like:


group, element, event_id, ...
1, 1, = 1
1, 1, 2
1, 1, 3
2, 1, 1
1, 1, 4
1, = 3, 1
1, 1, 5
1, 3, 2
2, 1, 2
2, 1, 3

The 3rd column is the sequence number = we get from the appropriate sequence created by the = trigger.
 
I want to implement a = variation of https://stackoverflow.com/a/30204854 and that will = generate millions of sequences.


Then I don=E2=80=99t thing group/element can be a = PRIMARY KEY 


= --Apple-Mail=_8D62A5AD-A2FB-4557-9C6C-D23B2FBAF34B--