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 1tPmHR-00FDdP-IG for pgsql-general@arkaria.postgresql.org; Mon, 23 Dec 2024 17:31:46 +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 1tPmHQ-00DLsH-Qr for pgsql-general@arkaria.postgresql.org; Mon, 23 Dec 2024 17:31:44 +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 1tPmHQ-00DLs9-Bq for pgsql-general@lists.postgresql.org; Mon, 23 Dec 2024 17:31:44 +0000 Received: from mail-oo1-xc30.google.com ([2607:f8b0:4864:20::c30]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tPmHO-000DD1-2V for pgsql-general@lists.postgresql.org; Mon, 23 Dec 2024 17:31:43 +0000 Received: by mail-oo1-xc30.google.com with SMTP id 006d021491bc7-5f2ed0b70d6so1754549eaf.3 for ; Mon, 23 Dec 2024 09:31:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734975102; x=1735579902; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=mq8KEfEycY/1xIfgw9gtEQ0BMDEo3Y28YKwXA7/o4Ss=; b=LcjawwL82BgXF908Gzxn/Q1dFPr0Naza67IBkeqwTM4B0Y9JHKXTRQyaX7487c60fG 1/cgKXqYteCak6Jvm4DuqJwzOUbXZr38ypQCRpJhns6VkWEsxxdmffDxj5E7cHWGMUod avthoBvYaD127G5I378tDYFxYM04l0Yh2vciiHtLV8BZbzMUSuXYTgrCit/arAR67okn opHO0/LEjHduiqV32Pf2nF7fAhPPuvhDNy2qyIMFtdzonRLk9NI/Ahskif/MDoryFVe1 145hVdxaenLHWRP42H3Rr8msf0HH4PLFCV7ar5DhylxVVA/GLUEOiuVRJpBtlU99j06c kTGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734975102; x=1735579902; h=cc: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=mq8KEfEycY/1xIfgw9gtEQ0BMDEo3Y28YKwXA7/o4Ss=; b=QAYMzcu10yEsd2Re7EbkL/tCpKfzXnb+ISkDJF8sipVm09aFLlHNVZf0JbnaVzDF/y ZQZLuCvo9Q4wIspqfPEtemrO+QE50J2uZUMTSI1UtftNr9H8w19vXsJ5ZLRs5bb8c0Pg XJ0Q41dnBaelZy+NPYxRMN8Ly85d5Wl7hIhjPVjGuj5IYWSC/Vj2lZq6AUV1298zHvUr DQE3/ynjb0/vo25GxMktA9qaj6WmbfNlHrp+ZYbcMhMjBGIB+BwsYYlojzbNIKGztsQA AkxRq9BFREfqzJtgmJC7iITbjpWINWY6yRrCn0VEa6On04Rj/NHfpTXYypye9e5RAel8 AQ3w== X-Forwarded-Encrypted: i=1; AJvYcCVF4qy1wHx/OCQu6OaGC0VIISPjXFb5Cx0E+6HMS1fccXlFrzdlrqgw1Vfhq+/+P3yE4vtICt7r1fxdeMnb@lists.postgresql.org X-Gm-Message-State: AOJu0YyqkyjlK5lUYvxSbeYNxQrlEqavv8rg91hFXc0VVaDit5bOiM8g yNXQW4wPZPNFC3klf21DGmufKvCpflV+K6Mdr+GG8mIhjiayr5HqWdLgoaSM4vW9B/rDkNU0WVN KlzvuG8voY9nXdd6O/9lz/OKIeIE= X-Gm-Gg: ASbGnctH2+exwBB+PdGzSRbS/5YN1lxgR9t2fzXBxDJyMzcchY0hxDSF1pS+otVA0Ql TDgoY4xGAastAEwxEVsr4GrKR5vsr3GyZQH0IcM2XTDrXI1pfI/UOWxjbkBO5cjBX4Ux4XQB6 X-Google-Smtp-Source: AGHT+IFi55XtOndXreN98r/2HaWD/vxlEdL8+2r9soSgpdO/PHhA4E4L/FnBs5N27RYs8GM3LmmWGEh8S6LWU5XaRTE= X-Received: by 2002:a05:6871:451:b0:29e:18cc:276f with SMTP id 586e51a60fabf-2a7fb0c10e6mr8019069fac.11.1734975102233; Mon, 23 Dec 2024 09:31:42 -0800 (PST) MIME-Version: 1.0 References: <06e1f1ee-74b2-43a2-9a63-da20ae455ae2@aklaver.com> In-Reply-To: From: Divyansh Gupta JNsThMAudy Date: Mon, 23 Dec 2024 23:01:31 +0530 Message-ID: Subject: Re: Need help in database design To: "David G. Johnston" Cc: Adrian Klaver , pgsql-general@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000a9b4ac0629f35e56" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000a9b4ac0629f35e56 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Empty JSONB by mistake, I wrote array sorry about that On Mon, 23 Dec 2024, 10:59=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. >>> >>> --000000000000a9b4ac0629f35e56 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Empty JSONB by mistake, I wrote array sorry about that


On Mon, 23 Dec 2024, 10:59=E2=80=AFpm Divyansh Gupta JNsThM= Audy, <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 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@g= mail.com> wrote:
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 2= 3, 2024, 10:01 Divyansh Gupta JNsThMAudy <ag1567827@gmail.co= m> wrote:


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

The relationa= l database engine is designed around the column-based approach.=C2=A0 Espec= ially if the columns are generally unchanging, combined with using fixed-wi= dth data types.

David J.=

<= blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l= eft:1px solid rgb(204,204,204);padding-left:1ex">
--000000000000a9b4ac0629f35e56--