Re: Bad query plan when you add many OR conditions

Marco Colli <[email protected]> Fri, 10 Jan 2020 17:03:41 +0100
Newsgroups gmane.comp.db.postgresql.performance
Message-ID <CAFvCgN40o9v8dJ2=XXXfKHoY7DnXxKC7qHcnK2f69R-gKcBMwg@mail.gmail.com>
--000000000000a622f5059bcb455b
Content-Type: text/plain; charset="UTF-8"

Sorry, I didn't notice the SELECT * and I said something stupid...
However my reasoning should be still valid: I mean, PG could find the few
relevant rows (there's a LIMIT 30) using ONLY the index. It has all the
information required inside the index! Then it can simply access to that
rows on disk... It cannot take ~1 minute to access a few rows on disk (max
30 rows, actual 0 rows).



On Fri, Jan 10, 2020 at 4:18 PM Tom Lane <[email protected]> wrote:

> Marco Colli <[email protected]> writes:
> > As you can see it is a *index scan* and not an *index only* scan... I
> don't
> > understand why. The index includes all the fields used by the query... so
> > an index only scan should be possible.
>
> Huh?  The query is "select * from ...", so it retrieves *all* columns
> of the table.
>
>                         regards, tom lane
>

--000000000000a622f5059bcb455b
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr">Sorry, I didn&#39;t notice the SELECT * a=
nd I said something stupid...=C2=A0<div>However my reasoning should be stil=
l valid: I mean, PG could find the few relevant rows (there&#39;s a LIMIT 3=
0) using ONLY the index. It has all the information required inside the ind=
ex! Then it can simply access to that rows on disk... It cannot take ~1 min=
ute to=C2=A0access a few rows on disk (max 30 rows, actual 0 rows).</div><d=
iv><br></div><div><br></div></div></div><br><div class=3D"gmail_quote"><div=
 dir=3D"ltr" class=3D"gmail_attr">On Fri, Jan 10, 2020 at 4:18 PM Tom Lane =
&lt;<a href=3D"mailto:[email protected]">[email protected]</a>&gt; wrote:<b=
r></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex=
;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,20=
4,204);padding-left:1ex">Marco Colli &lt;<a href=3D"mailto:collimarco91@gma=
il.com" target=3D"_blank">[email protected]</a>&gt; writes:<br>
&gt; As you can see it is a *index scan* and not an *index only* scan... I =
don&#39;t<br>
&gt; understand why. The index includes all the fields used by the query...=
 so<br>
&gt; an index only scan should be possible.<br>
<br>
Huh?=C2=A0 The query is &quot;select * from ...&quot;, so it retrieves *all=
* columns<br>
of the table.<br>
<br>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 regards, tom lane<br>
</blockquote></div>

--000000000000a622f5059bcb455b--