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.89) (envelope-from ) id 1i3LQI-0005wu-3u for pgsql-admin@arkaria.postgresql.org; Thu, 29 Aug 2019 14:29:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i3LQH-0003I4-11 for pgsql-admin@arkaria.postgresql.org; Thu, 29 Aug 2019 14:29:13 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i3LQG-00036z-KF for pgsql-admin@lists.postgresql.org; Thu, 29 Aug 2019 14:29:12 +0000 Received: from mail-io1-xd42.google.com ([2607:f8b0:4864:20::d42]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i3LQE-0007US-Gu for pgsql-admin@lists.postgresql.org; Thu, 29 Aug 2019 14:29:12 +0000 Received: by mail-io1-xd42.google.com with SMTP id u185so3484351iod.10 for ; Thu, 29 Aug 2019 07:29:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=t0vZ4uu8nUogp+9aSSutiCVN0GcDAryjqADvbdI4ev8=; b=rT+k/1Ecw30Wxsnp1ZXe0FB5ABobCVE4y4SVWIEHwDFIi4NmFyskCSEtWLKFnV5hWM 1L/1/ye9WNRwBBfQqW1rOpyZBZFBiHa4t0XiH7yD6tNuGIVbdyACQDxdbcuZqOCzpnt/ QrO37HqFBeniEIE3loyTndjMPe+9emMa+p8bWc9Hmvjly5HrxhL6E1zTDLqg56D+Y+ZM DUFTOL5m3RgxIiEHmI6GFjNc+TcgvqJnH4bZGqIpLXfi1sFW0osppIWozQWK8havtYgv BPVS1E2vz43hROC5C2itFgEcCBpxexV4ypQV37h4pc1rTDYN00sHjpqo1l96rm36kBFB HIig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=t0vZ4uu8nUogp+9aSSutiCVN0GcDAryjqADvbdI4ev8=; b=n6Zu5/J12gyu5A++iRCoSloXr9pT2z17WVdeDpXx/7VFyg/VgUR8pVD47AiUlBV0MV plHZZh5l1sMCoM4lac3JiyYIcDjk0zmIHtfIZ6soDiPCjfgQYgPHm5lb9iBvftoi7Dcp yX4OHavo1vKPdat1+PARomwLwnzC2KcJZvK/lkKSeY5Q/3DkJuVgZQMEibkflQFh2lLN m7woHDnTDBpPyOiKeo+/g9WZwPz06Z2eSKfutxFICNyfLvZUM+XjSnY6jx4T9MqzjsM3 XD53gQzCokCEYaMEoDwaBqj4jF63C+03WGxKo9JlOtZMi6lITrENzLZfy1IsQ1Tfmhjz nDCA== X-Gm-Message-State: APjAAAWy82g/lbqA57yWzDkaHQyb+33T8uRejKWUEOPNAcd+YHh57lB4 8UYFGfe0OuhY07qYVqHDY3gSwvgi X-Google-Smtp-Source: APXvYqyYrCmMF6OZL2VA8dtVshNU+gZ8db3KVcEHwS0wuHzwNRhXiitNcaHxZWuiOEP5J+8Bjj7NQg== X-Received: by 2002:a5e:c311:: with SMTP id a17mr1913917iok.140.1567088948861; Thu, 29 Aug 2019 07:29:08 -0700 (PDT) Received: from [172.17.53.230] (rouge-137-188-108-19.vzw.com. [137.188.108.19]) by smtp.gmail.com with ESMTPSA id y19sm952655ioq.69.2019.08.29.07.29.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Aug 2019 07:29:08 -0700 (PDT) Content-Type: multipart/alternative; boundary=Apple-Mail-7DD3DDA1-2817-44ED-A14A-33675296388E Mime-Version: 1.0 (1.0) Subject: Re: Index not always being used From: John Scalia X-Mailer: iPad Mail (16G102) In-Reply-To: <43ccec39-3be0-a47c-cd27-fff73d948f20@jakobs.com> Date: Thu, 29 Aug 2019 10:29:06 -0400 Cc: pgsql-admin@lists.postgresql.org Content-Transfer-Encoding: 7bit Message-Id: <8D7F747E-132E-4543-9933-583DE249850F@gmail.com> References: <180F96D3-690E-466E-B73E-F6B34C6409C7@gmail.com> <43ccec39-3be0-a47c-cd27-fff73d948f20@jakobs.com> To: Holger Jakobs List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail-7DD3DDA1-2817-44ED-A14A-33675296388E Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Good to know, thanks Sent from my iPad > On Aug 29, 2019, at 10:22 AM, Holger Jakobs wrote: >=20 > Hi, >=20 > A good solution would be to add another B-Tree index. The planner wo= uld choose this one in case of a search using "=3D" and the trigram index wh= en using "like", "similar to" or "~" (regexp). >=20 > A trigram index is not suitable for a "=3D" comparison. >=20 > Regards, >=20 > Holger >=20 >> Am 29.08.19 um 16:15 schrieb John Scalia: >> I=E2=80=99ve got a table with approximately 5.5 million rows, and one col= umn that is frequently searched is of type varchar(50) and we just put a tr= igram index on it. Now, if we search =E2=80=9Cwhere bld_city =3D =E2=80=98ba= skingridge=E2=80=99=E2=80=9D, explain says a sequential table scan is going t= o be used, but if I change the query to use =E2=80=9Cwhere bold_city like =E2= =80=98basking%=E2=80=99=E2=80=9D, then explain correctly shows that a bitmap= index scan will be performed. Why would these two forms use different appro= aches? I=E2=80=99m a bit confused. >> =E2=80=94 >> Jay >>=20 >> Sent from my iPad >>=20 > --=20 > Holger Jakobs, Bergisch Gladbach > instant messaging: xmpp:holger@jakobs.com > +49 178 9759012 oder +49 2202 817157 --Apple-Mail-7DD3DDA1-2817-44ED-A14A-33675296388E Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable Good to know, thanks

Sent from my iPad

On A= ug 29, 2019, at 10:22 AM, Holger Jakobs <holger@jakobs.com> wrote:

=20 =20 =20

Hi,

A good solution would be to add another B-Tree index. The planner would choose this one in case of a search using "=3D" and the trigram index when using "like", "similar to" or "~" (regexp).

A trigram index is not suitable for a "=3D" comparison.

Regards,

Holger

Am 29.08.19 um 16:15 schrieb John Scalia:
I=E2=80=99ve got a table with a=
pproximately 5.5 million rows, and one column that is frequently searched is=
 of type varchar(50)  and we just put a trigram index on it. Now, if we sear=
ch =E2=80=9Cwhere bld_city =3D =E2=80=98baskingridge=E2=80=99=E2=80=9D, expl=
ain says a sequential table scan is going to be used, but if I change the qu=
ery to use =E2=80=9Cwhere bold_city like =E2=80=98basking%=E2=80=99=E2=80=9D=
, then explain correctly shows that a bitmap index scan will be performed. W=
hy would these two forms use different approaches? I=E2=80=99m a bit confuse=
d.
=E2=80=94
Jay

Sent from my iPad

--

Holger Jakobs, Bergisch Gladbach
instant messaging: xmpp:holger@ja= kobs.com
+49 178 9759012 oder +49 2202 817157

=20
= --Apple-Mail-7DD3DDA1-2817-44ED-A14A-33675296388E--