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 1tPmYo-00FFh2-VM for pgsql-general@arkaria.postgresql.org; Mon, 23 Dec 2024 17:49:43 +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 1tPmYo-00DciD-3E for pgsql-general@arkaria.postgresql.org; Mon, 23 Dec 2024 17:49:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tPmYn-00DchU-NH for pgsql-general@lists.postgresql.org; Mon, 23 Dec 2024 17:49:41 +0000 Received: from mail-oo1-xc2b.google.com ([2607:f8b0:4864:20::c2b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tPmYk-001G0b-PC for pgsql-general@postgresql.org; Mon, 23 Dec 2024 17:49:40 +0000 Received: by mail-oo1-xc2b.google.com with SMTP id 006d021491bc7-5f2dee7d218so1952923eaf.2 for ; Mon, 23 Dec 2024 09:49:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734976177; x=1735580977; darn=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=ozAq2p2zcauws0n1sDvD57uszMhXSMJEfy2YvaYqM/Y=; b=JlGvQEhMKibEg/eIlNCgjsree8ObcV2cbbIB67imKpoWo44sggfJns/QytKDIvR321 maVYB1nVb7uPzUES/gvQ5CYtLRczqHvjRK1HzhW3ZNo2aLrK3iTTjaq4jQcs3hWQXG8R XKOQnMrUNRNw2CWsEoRrGZhaKeojOZMQjW5z8HkSSJ/XxvX79FoxKhD55myJHt1qFNJu /xjEvteRdZZEULw1aWQCh91u5OkSkmOjenKTHKMCZTPQA23/uZ9xGjAFm5n/3ofiL4So BSz+t9r54sJ0MtaqgCLcw+rnRG3UtHWGKiLWK3QfbMOSKCtrvgIpd4qtq00/VI4puHF3 XTfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734976177; x=1735580977; 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=ozAq2p2zcauws0n1sDvD57uszMhXSMJEfy2YvaYqM/Y=; b=Is+4YTSMfvXsWdETcYxT395dEcW8P37uOVTYz9LZueAeYXz9B4A+jBQWy4p4Z9XgOY g/m7ypv+oAgMXFYN52Ul1vTHXmFY9W5pJp0LSjL1mn4Cx2G1vkULj4OAj9GPNjogZIkI M3sffoWWN4LHsw24I0S5arTYOnG/eMv2m5Z9ml9gNUui2fk6okm6hOrpzLqV4kFFJbZ9 jqfcktK1wHWfIwiRjF2EX8mTUKusfiUQTY7V8ljoXu2CZ8It+NKE/C/IXeh3fswgBaQF PePcb/F+BHNMI6lf/KnW1WURIGhydZ80Dmyj+5/yBc/DlHQHFTDONBn/LgKndfwx4X4B SbsQ== X-Gm-Message-State: AOJu0Yw9VwdIYHaSfrp058uKJS7bO/jPdwoDlezSiJHTNBlI6l5VPCrQ 34KXzdTbZDqKFui9aBveL7jwNUm8DXWQn882w27s2JdRgS/6+JIC2rEcPYlLItc7iBZ8qbysAGe Xqm4YzHjix0Mz0As8lQ6/3fa7zeA= X-Gm-Gg: ASbGnct1sz5Kcz5KESjXOn2uD1TG95/scgSWYxstIuhWjN1WBnrGKlhWfEaXKgFzqIZ dgtcSrljWQe91z8iwmdsEINVNNtJQVn0tccdOaKIu0wxHyx2xsDt8nmG+y0EoneiCNK5KSAna X-Google-Smtp-Source: AGHT+IH3nVgvU9kzxgzEVWf/jAfVyLPlxCqoPibt8FOurQidFQsngpmqomJlBXbU5ZLlsqkexYGDoWA4BepjRJmMnQ0= X-Received: by 2002:a05:6820:4b95:b0:5f2:d799:ab91 with SMTP id 006d021491bc7-5f62e6f3a4dmr7414060eaf.2.1734976177184; Mon, 23 Dec 2024 09:49:37 -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:19:25 +0530 Message-ID: Subject: Re: Need help in database design To: Ron Johnson Cc: pgsql-general Content-Type: multipart/alternative; boundary="000000000000bc28160629f39ec6" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000bc28160629f39ec6 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I have one confusion with this design if I opt to create 50 columns I need to create 50 index which will work with userid index in Bitmap on the other hand if I create a JSONB column I need to create a single index ? On Mon, 23 Dec 2024, 11:10=E2=80=AFpm Ron Johnson, wrote: > 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 perfo= rms >> some actions that time the key value pairs will populate and update, bas= ed >> 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 loo= k >>> 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, combine= d >>>> with using fixed-width data types. >>>> >>>> David J. >>>> >>>> > > -- > Death to , and butter sauce. > Don't boil me, I'm still alive. > lobster! > --000000000000bc28160629f39ec6 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

I have one confusion with this design if I opt to create 50 = columns I need to create 50 index which will work with userid index in Bitm= ap on the other hand if I create a JSONB column I need to create a single i= ndex ?


On Mon, 23 Dec 2024, 11:10=E2=80=AFpm Ron Johnson, <ronljohnsonjr@gmail.com> wrot= e:
Given what= you just wrote, I'd stick with 50 separate t* columns.=C2=A0 Simplifie= s queries, simplifies updates, and eliminates JSONB conversions.

<= div class=3D"gmail_quote">
On Mon, Dec= 23, 2024 at 12:29=E2=80=AFPM Divyansh Gupta JNsThMAudy <ag1567827@gmai= l.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.googledoc= s_tbl (
gdid int8 GENERATED BY DEFAULT AS IDENTITY( INCREMENT BY 1 MINV= ALUE 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,<= br> 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 NUL= L,
t32 int4 NULL,
t33 int4 NULL,
t34 int4 NULL,
t35 int4 NU= LL,
t36 int4 NULL,
t37 int4 NULL,
t38 int4 NULL,
t39 int4 N= ULL,
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,
CONSTRA= INT googledocs_tbl_pkey PRIMARY KEY (gdid),
);

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

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

CREATE TABLE dbo.googledocs_tbl (
gdid i= nt8 GENERATED BY DEFAULT AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 92= 23372036854775807 START 1 CACHE 1 NO CYCLE) NOT NULL,
userid int8 NOT N= ULL,
addons_json jsonb default '{}'::jsonb
CONSTRAINT googl= edocs_tbl_pkey PRIMARY KEY (gdid),
);

and the query would be like= =C2=A0
where userid =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. Joh= nston <david.g.johnston@gmail.com> wrote:
<= /div>

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 consider= ing 50 columns will be more optimised.

The relational database engine is designed around the column-base= d approach.=C2=A0 Especially if the columns are generally unchanging, combi= ned 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!
--000000000000bc28160629f39ec6--