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 1syz5a-003S6B-Tn for pgsql-general@arkaria.postgresql.org; Thu, 10 Oct 2024 19:44:47 +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 1syz5Z-0065Zs-KB for pgsql-general@arkaria.postgresql.org; Thu, 10 Oct 2024 19:44:45 +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 1syz5Z-0065ZT-43 for pgsql-general@lists.postgresql.org; Thu, 10 Oct 2024 19:44:45 +0000 Received: from mail-vs1-xe35.google.com ([2607:f8b0:4864:20::e35]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1syz5W-000FdU-GW for pgsql-general@lists.postgresql.org; Thu, 10 Oct 2024 19:44:44 +0000 Received: by mail-vs1-xe35.google.com with SMTP id ada2fe7eead31-4a3a8cef4d2so467237137.0 for ; Thu, 10 Oct 2024 12:44:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728589481; x=1729194281; 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=wBQUTKeCPnhNV69wp8aDA/2pwlVjT1xecj64f8UOMxc=; b=epk+620ha0C5+bfaPaHD+svV877rAdk6jztJZojIV6jPOPqfSF2lopd4Hy06MkIRSl C2aaGHNPGO/xtiIrFpw/CGzGMVbBz0gEirz2fp/f0WNLKwrTo7uR2V7gYTSYzmJJlLGo +35MLdbi0q0L+v+x0+abyL+lxuMXVSk0Bc10Qm+Qi1EDHANboMPdClzUXPEvwfyAzmA1 hn/9968SNGnkLPx3W+Xd6xejicsXeLhewZi2gjKQorwYSs+WVV/wWA+sugJ8qBLnzwih hNrhR7yKIyzYTDlG3anaXDGKyKo6KVGp28ggc6+zanq64GafJUrYcOUgsmXlgIHvwe82 Nlow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728589481; x=1729194281; 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=wBQUTKeCPnhNV69wp8aDA/2pwlVjT1xecj64f8UOMxc=; b=IcK3gsMIKZ6kxxvh/hmg3GYFkp0dRQA+bX0fVS0zJv4DbULEEpDdsc8Xbn2UYODgvE cmOOGQAuKzXfEOTFj5Uijp9T1DfpRlXFrKb/SkY0jnrndJE+lwipKVmp7yxY/v+W2r0r 2YM16yO25H4SbktS8OIM+Qak9OasLPGAZvnkb01Pa0xMy4ypslGV198j/pRmL+mXJM/o rYYbst8iDE8YXND5CntpcOa0Y2+nUuFboQ1kqooEPh1yCc+3pFT2YNt+KiZU3VwSFLPL 5pouANHWyakLHy1TdGqAP24oRgmc7flob6B+c7JmUNIewC4rsT61S8zPVCLgk0qWB7+j qgBA== X-Gm-Message-State: AOJu0YzhrCKjuHsSD1/YSwWJZy8T8bzL7+dMJcp4UT2/KD1lXtO339gC 7oBaoyOY1kjTexASsXLVsyWsOHYnZeGT99GrPP8A+ipZIP5DHbF5QgjTnKpV1gP25A+yLCKiYHf l6TT6iE150lRpQOrKLy1d+4pVE8y8Tw== X-Google-Smtp-Source: AGHT+IG6LXW17kpgaU5H6rt3TtsZAgvI+aEBqvW0BGvPnQ8yOuSZQMxQVNaEE3Risnutp2lP63sJoPvP9BkCtAXR7hk= X-Received: by 2002:a05:6102:3908:b0:4a3:cf4f:e19 with SMTP id ada2fe7eead31-4a465a764cemr98350137.24.1728589481001; Thu, 10 Oct 2024 12:44:41 -0700 (PDT) MIME-Version: 1.0 References: <88e5c335-c70e-4973-9b71-6c12e251e5b7@ewie.name> In-Reply-To: <88e5c335-c70e-4973-9b71-6c12e251e5b7@ewie.name> From: sud Date: Fri, 11 Oct 2024 01:14:28 +0530 Message-ID: Subject: Re: Question on indexes To: Erik Wienhold , xof@thebuild.com Cc: pgsql-general Content-Type: multipart/alternative; boundary="000000000000fa4d520624249956" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000fa4d520624249956 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Oct 11, 2024 at 12:51=E2=80=AFAM Erik Wienhold wro= te: > On 2024-10-10 20:49 +0200, sud wrote: > > However, we are seeing that one of the databases has multiple hash > indexes > > created. So I wanted to understand from experts here, if it's advisable > in > > any specific scenarios over B-tre despite such downsides? > > Two things come to my mind: > > 1. Btree puts a limit on the size of indexed values, whereas hash > indexes only store the 32-bit hash code. > > 2. Of the core index types, only btree supports unique indexes. > > Example of btree's size limit: > > CREATE TABLE b (s text); > CREATE INDEX ON b USING btree (s); > INSERT INTO b (s) VALUES (repeat('x', 1000000)); > ERROR: index row requires 11464 bytes, maximum size is 8191 > > The docs have more details: > https://www.postgresql.org/docs/current/btree.html > https://www.postgresql.org/docs/current/hash-index.html > > > Thank you. Not yet confirmed, but actually somehow we see the DB crashed repetitively a few times and teammates suspecting the cause while it tried extending this hash index. Did you experience any such thing with hash index? However, as you mentioned ,if we have any column with large string/text values and we want it to be indexed then there is no choice but to go for a hash index. Please correct me if I'm wrong. --000000000000fa4d520624249956 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

On Fri, Oct 11, 2024 at 12:51=E2=80=AFAM = Erik Wienhold <ewie@ewie.name> = wrote:
On 2024-1= 0-10 20:49 +0200, sud wrote:
> However, we are seeing that one of the databases has multiple hash ind= exes
> created. So I wanted to understand from experts here, if it's advi= sable in
> any specific scenarios over B-tre despite such downsides?

Two things come to my mind:

1. Btree puts a limit on the size of indexed values, whereas hash
=C2=A0 =C2=A0indexes only store the 32-bit hash code.

2. Of the core index types, only btree supports unique indexes.

Example of btree's size limit:

=C2=A0 =C2=A0 CREATE TABLE b (s text);
=C2=A0 =C2=A0 CREATE INDEX ON b USING btree (s);
=C2=A0 =C2=A0 INSERT INTO b (s) VALUES (repeat('x', 1000000));
=C2=A0 =C2=A0 ERROR:=C2=A0 index row requires 11464 bytes, maximum size is = 8191

The docs have more details:
https://www.postgresql.org/docs/current/btree.html=
https://www.postgresql.org/docs/current/hash-= index.html


Thank you.

Not yet confi= rmed, but actually somehow we see the DB crashed repetitively a few times a= nd teammates=C2=A0suspecting=C2=A0the cause while it tried extending this h= ash index. Did you experience any such thing with hash index? However, as y= ou mentioned ,if we have any column with large string/text values and we wa= nt it to be indexed then there is no choice but to go for a hash index. Ple= ase correct me if I'm wrong.
--000000000000fa4d520624249956--