Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tPmPQ-00FEUo-TG for pgsql-general@arkaria.postgresql.org; Mon, 23 Dec 2024 17:40:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tPmPQ-00DUi6-2I for pgsql-general@arkaria.postgresql.org; Mon, 23 Dec 2024 17:39:59 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tPmPP-00DUeB-Is for pgsql-general@lists.postgresql.org; Mon, 23 Dec 2024 17:39:59 +0000 Received: from mail-oa1-x31.google.com ([2001:4860:4864:20::31]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tPmPN-000DOU-2g for pgsql-general@postgresql.org; Mon, 23 Dec 2024 17:39:58 +0000 Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-29fbba47ca4so2001299fac.3 for ; Mon, 23 Dec 2024 09:39:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734975597; x=1735580397; darn=postgresql.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=KR9VxK6brM/6gNlRhWXctrREACWRiO4IZnRXSZf+Y9k=; b=bX3cDewO2LVfT1YLfMOr71pU4XfBrHQNH4XfYSChT8Mi0GFjc58l55iZ8vAqiNceIC ZK8ohplgFIM/BisHxyOIw5mQjn8X2rVT4pyeY+SfPX+5keTDj+uSpAoxQ18ka4aHWuYZ jMFSOg3f8aFj9TfjEpF0UH0NY6jn+LPk+RJqfMZ1Wv92wg7F55I6q4PVpBIaWrE2lEqL 29/TiDLKdcXpJRxejfKi16qhSRihoKQGsMop+9w34fjuwQXuBVqTcrtSHPGs1B/N2HCB czlHHSOCeFe5XKjch2/8tgzza2J/hXWYEqvVDBC2wDMquO9pHgzXHRJOuIDwfhpA9n8l AXSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734975597; x=1735580397; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KR9VxK6brM/6gNlRhWXctrREACWRiO4IZnRXSZf+Y9k=; b=jx8ZsBx/PF3xeJok9riV+7DZF9HNX8gN6BN+KwE6ryQaedLK2g+zvZcS7I46tvupnc 02sljfNdDx1iY+ikKhEp/ypSA86tvpILXt3unbfqCd+YFk9XsfQqOEGHY8asoslDsttA XlIOaynIL60brpysPra3Vg+IIpZ0HOwInxkpkN/kanhYqRkq7UmO2DGJDmJU51Q85mPj L8ivYnrnPzf/kYUi0rYtYEzAkro3MNWbVXQuWIeYN0zDLiUAip+JTIu0Gkp2TLO16Ig6 fKqvPR71BSJp6LHo9PQ229FdsfhUg3YIOZeKKpCrqLKZSW7ytda7eAm6SdjyPLdew+o1 IR0A== X-Gm-Message-State: AOJu0YyBGa9oMdhr5qCaBBD92g1f1cRHIXKnFU+bkdt3HxH+sXaJyUSl 12Sl2CVhx9b90OKZDjguZOZUbrTLew9IN9RwKamLdKQWI0s6rTdkYCyPtumxKzKgZtopSnIcNM9 d1zrrre5ECJ7ZdQZRszWWbuwcGaY+hw== X-Gm-Gg: ASbGncu4aR5Bq/jq5FI3oNjiT4hYRwkz1LzxXtH3Ztdyxm1EW4y3V6C5HGhgNcHVZE0 H46mWRAQZ9ds+jwwKMzeDr6XxV9K/qCCfGBg9AtKsfKF/IkZnSx85s5r9cGuovPijkfecN5h4 X-Google-Smtp-Source: AGHT+IHQpSwxdRY4Pr7KRlN7V4BBEPM6uivrEFI6Gj+YnsDHHIgMpIcH2j+ZOa5Zw8+MAEAfKGBvskVBtccIE72Zu5s= X-Received: by 2002:a05:6870:b528:b0:296:a67c:d239 with SMTP id 586e51a60fabf-2a7fb0bfda2mr6905686fac.12.1734975597003; Mon, 23 Dec 2024 09:39:57 -0800 (PST) MIME-Version: 1.0 References: <06e1f1ee-74b2-43a2-9a63-da20ae455ae2@aklaver.com> In-Reply-To: From: Ron Johnson Date: Mon, 23 Dec 2024 12:39:46 -0500 Message-ID: Subject: Re: Need help in database design To: pgsql-general Content-Type: multipart/alternative; boundary="000000000000274c520629f37c7a" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000274c520629f37c7a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Given what you just wrote, I'd stick with 50 separate t* columns. Simplifies queries, simplifies updates, and eliminates JSONB conversions. On Mon, Dec 23, 2024 at 12:29=E2=80=AFPM Divyansh Gupta JNsThMAudy < ag1567827@gmail.com> wrote: > Values can be updated based on customer actions > > All rows won't have all 50 key value pairs always if I make those keys > into columns the rows might have null value on the other hand if it is > JSONB then the key value pair will not be there > > Yes in UI customers can search for the key value pairs > > During data population the key value pair will be empty array in case of > JSONB column or NULL in case of table columns, later when customer perfor= ms > some actions that time the key value pairs will populate and update, base= d > on what action customer performs. > > On Mon, 23 Dec 2024, 10:51=E2=80=AFpm Divyansh Gupta JNsThMAudy, < > ag1567827@gmail.com> wrote: > >> Let's make it more understandable, here is the table schema with 50 >> columns in it >> >> CREATE TABLE dbo.googledocs_tbl ( >> gdid int8 GENERATED BY DEFAULT AS IDENTITY( INCREMENT BY 1 MINVALUE 1 >> MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL, >> userid int8 NOT NULL, >> t1 int4 NULL, >> t2 int4 NULL, >> t3 int4 NULL, >> t4 int4 NULL, >> t5 int4 NULL, >> t6 int4 NULL, >> t7 int4 NULL, >> t8 int4 NULL, >> t9 int4 NULL, >> t10 int4 NULL, >> t11 int4 NULL, >> t12 int4 NULL, >> t13 int4 NULL, >> t14 int4 NULL, >> t15 int4 NULL, >> t16 int4 NULL, >> t17 int4 NULL, >> t18 int4 NULL, >> t19 int4 NULL, >> t20 int4 NULL, >> t21 int4 NULL, >> t22 int4 NULL, >> t23 int4 NULL, >> t24 int4 NULL, >> t25 int4 NULL, >> t26 int4 NULL, >> t27 int4 NULL, >> t28 int4 NULL, >> t29 int4 NULL, >> t30 int4 NULL, >> t31 int4 NULL, >> t32 int4 NULL, >> t33 int4 NULL, >> t34 int4 NULL, >> t35 int4 NULL, >> t36 int4 NULL, >> t37 int4 NULL, >> t38 int4 NULL, >> t39 int4 NULL, >> t40 int4 NULL, >> t41 int4 NULL, >> t42 int4 NULL, >> t43 int4 NULL, >> t44 int4 NULL, >> t45 int4 NULL, >> t46 int4 NULL, >> t47 int4 NULL, >> t48 int4 NULL, >> t49 int4 NULL, >> t50 int4 NULL, >> CONSTRAINT googledocs_tbl_pkey PRIMARY KEY (gdid), >> ); >> >> Every time when i query I will query it along with userid >> Ex : where userid =3D 12345678 and t1 in (1,2,3) and t2 in (0,1,2) >> more key filters if customer applies >> >> On the other hand if I create a single jsonb column the schema will look >> like : >> >> CREATE TABLE dbo.googledocs_tbl ( >> gdid int8 GENERATED BY DEFAULT AS IDENTITY( INCREMENT BY 1 MINVALUE 1 >> MAXVALUE 9223372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL, >> userid int8 NOT NULL, >> addons_json jsonb default '{}'::jsonb >> CONSTRAINT googledocs_tbl_pkey PRIMARY KEY (gdid), >> ); >> >> and the query would be like >> where userid =3D 12345678 and ((addons_json @> {t1:1}) or (addons_json = @> >> {t1:2}) or (addons_json @> {t1:3}) >> more key filters if customer applies >> >> >> >> On Mon, Dec 23, 2024 at 10:38=E2=80=AFPM David G. Johnston < >> david.g.johnston@gmail.com> wrote: >> >>> >>> >>> On Mon, Dec 23, 2024, 10:01 Divyansh Gupta JNsThMAudy < >>> ag1567827@gmail.com> wrote: >>> >>>> >>>> So here my question is considering one JSONB column is perfect or >>>> considering 50 columns will be more optimised. >>>> >>> The relational database engine is designed around the column-based >>> approach. Especially if the columns are generally unchanging, combined >>> with using fixed-width data types. >>> >>> David J. >>> >>> --=20 Death to , and butter sauce. Don't boil me, I'm still alive. lobster! --000000000000274c520629f37c7a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Given what you just wrote, I'd stick with 50 sepa= rate t* columns.=C2=A0 Simplifies queries, simplifies updates, and eliminat= es JSONB conversions.

On Mon, Dec 23, 2024 at 12:29=E2= =80=AFPM Divyansh Gupta JNsThMAudy <ag1567827@gmail.com> wrote:

Values can be updated based on custome= r actions

All rows won't have all 50 key value pairs always if I m= ake those keys into columns the rows might have null value on the other han= d if it is JSONB then the key value pair will not be there

Yes in UI customers can search for the key value pairs

During data population the key value pair will be empty arra= y in case of JSONB column or NULL in case of table columns, later when cust= omer performs some actions that time the key value pairs will populate and = update, based on what action customer performs.


On Mon= , 23 Dec 2024, 10:51=E2=80=AFpm Divyansh Gupta JNsThMAudy, <ag1567827@gmail.com> wr= ote:
Let's make it more understandable, here is the table schema with = 50 columns in it=C2=A0

CREATE TABLE dbo.googledocs_tbl (
gdid in= t8 GENERATED BY DEFAULT AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 922= 3372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL,
userid int8 NOT NU= LL,
t1 int4 NULL,
t2 int4 NULL,
t3 int4 NULL,
t4 int4 NULL,=
t5 int4 NULL,
t6 int4 NULL,
t7 int4 NULL,
t8 int4 NULL, t9 int4 NULL,
t10 int4 NULL,
t11 int4 NULL,
t12 int4 NULL, t13 int4 NULL,
t14 int4 NULL,
t15 int4 NULL,
t16 int4 NULL, t17 int4 NULL,
t18 int4 NULL,
t19 int4 NULL,
t20 int4 NULL,<= br> t21 int4 NULL,
t22 int4 NULL,
t23 int4 NULL,
t24 int4 NULL,=
t25 int4 NULL,
t26 int4 NULL,
t27 int4 NULL,
t28 int4 NULL= ,
t29 int4 NULL,
t30 int4 NULL,
t31 int4 NULL,
t32 int4 NUL= L,
t33 int4 NULL,
t34 int4 NULL,
t35 int4 NULL,
t36 int4 NU= LL,
t37 int4 NULL,
t38 int4 NULL,
t39 int4 NULL,
t40 int4 N= ULL,
t41 int4 NULL,
t42 int4 NULL,
t43 int4 NULL,
t44 int4 = NULL,
t45 int4 NULL,
t46 int4 NULL,
t47 int4 NULL,
t48 int4= NULL,
t49 int4 NULL,
t50 int4 NULL,
CONSTRAINT googledocs_tbl_= pkey PRIMARY KEY (gdid),
);

Every time when i query I will query = it along with userid=C2=A0
Ex : where userid =3D 12345678 and t1 in (1,2= ,3) and t2 in (0,1,2)
more key filters if customer applies=C2=A0

= On the other hand if I create a single jsonb column the schema will look li= ke :

CREATE TABLE dbo.googledocs_tbl (
gdid int8 GENERATED BY DE= FAULT AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 S= TART 1 CACHE 1 NO CYCLE) NOT NULL,
userid int8 NOT NULL,
addons_jso= n jsonb default '{}'::jsonb
CONSTRAINT googledocs_tbl_pkey PRIM= ARY KEY (gdid),
);

and the query would be like=C2=A0
where use= rid =3D 12345678 and ((addons_json=C2=A0@> {t1:1}) or=C2=A0 (addons_json=C2=A0@> {t1:2}= ) or=C2=A0 (addons_json=C2=A0@> {t1:3}= )
more key filters if customer applies=C2=A0



On Mon, Dec = 23, 2024 at 10:38=E2=80=AFPM David G. Johnston <david.g.johnston= @gmail.com> wrote:


On Mon, Dec 23, 2024, 10:01 Divyans= h Gupta JNsThMAudy <ag1567827@gmail.com> wrote:

So here my question is considering one JSONB column is = perfect or considering 50 columns will be more optimised.

The relational database engine is designed aro= und the column-based approach.=C2=A0 Especially if the columns are generall= y unchanging, combined with using fixed-width data types.

David J.



--
Death to <Redacted>, and butter sauce.Don't boil me, I'm still alive.
<Redacted> lobs= ter!
--000000000000274c520629f37c7a--