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 1i3bd4-0006wt-GY for pgsql-bugs@arkaria.postgresql.org; Fri, 30 Aug 2019 07:47:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i3bd3-0004b5-3R for pgsql-bugs@arkaria.postgresql.org; Fri, 30 Aug 2019 07:47:29 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1i3anf-0007So-TD for pgsql-bugs@lists.postgresql.org; Fri, 30 Aug 2019 06:54:24 +0000 Received: from mail.verfriemelt.org ([138.201.40.18]) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1i3anS-0004t9-45 for pgsql-bugs@lists.postgresql.org; Fri, 30 Aug 2019 06:54:22 +0000 X-Spam-Status: No, hits=0.0 required=4.0 tests=BAYES_00: -1.665,HTML_MESSAGE: 0.001,TOTAL_SCORE: -1.664,autolearn=ham X-Spam-Level: Received: from localhost ([127.0.0.1]) by mail.verfriemelt.org for pgsql-bugs@lists.postgresql.org; Fri, 30 Aug 2019 08:54:04 +0200 To: pgsql-bugs@lists.postgresql.org From: easteregg@verfriemelt.org Subject: Re: BUG #15984: order of where in() query affects query planer In-Reply-To: 7528.1567117005@sss.pgh.pa.us Message-ID: <20190830065403.09dda823@mail.verfriemelt.org> Date: Fri, 30 Aug 2019 08:54:03 +0200 X-User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3759.4 Safari/537.36 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="-----------01f92f530274baf11ecab6a8f72c3feb" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. -------------01f92f530274baf11ecab6a8f72c3feb Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thank you for your reply, i used the given example only because in my original case, i have a 12gb= table totaling to 43gb with indices and an quite similar query along wi= th some other clauses in the wherecase and still see this behavior. that= table has constantly updates ( around 5-100 updates per second ) writte= n to it. i confirm, with the example table after the analyse, the result is consi= stent. but my real table still have different plans with different order of the= array, i attach an explain. the partial index is defined as followed ( = i have to blank out some fieldnames and tablenames ) create index sn=5F=5Fdetail=5Fall on
(districtid,datepubl= ished) where districtid in (3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19)= and statusid in (2,3,4,5); and the other index from the bitmap query is defined like this: (districtid, , dateplaced) =F0=9F=90=98 08:42:38 =C2=BB user@host.org:5432/user > analyse verbose =
; INFO: analyzing "public.
" INFO: "
": scanned 300000 of 1608676 pages, containing 1369182 li= ve rows and 120789 dead rows; 300000 rows in sample, 7341901 estimated t= otal rows Time: 93397.647 ms (01:33.398) =F0=9F=90=98 08:47:06 =C2=BB user@host.org:5432/user > explain (verbose= , analyse) select count(*) from
where districtid in (3,4,5,6,7,= 8,9,10,11,12,13,14,15,16,17,18,19) and statusid in (2,3,4,5); = QUERY PLAN =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90 Aggregate (cost=3D15644.10..15644.11 rows=3D1 width=3D8) (actual time= =3D68.883..68.883 rows=3D1 loops=3D1) Output: count(*) -> Index Only Scan using sn=5F
r=5Fdetail=5Fall on public. (cost=3D0.41..15487.10 rows=3D62803 width=3D0) (actual time=3D0.014.= .61.728 rows=3D60915 loops=3D1) Output: districtid, datepublished Heap Fetches: 11373 Planning Time: 1.636 ms Execution Time: 68.910 ms (7 rows) Time: 94.375 ms =F0=9F=90=98 08:47:28 =C2=BB user@host.org:5432/user > explain (verbose= , analyse) select count(*) from
where districtid in (4,5,6,7,8,= 9,10,11,12,13,14,15,16,17,18,19,3) and statusid in (2,3,4,5); = QUERY PLAN =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90 Aggregate (cost=3D3885.65..3885.66 rows=3D1 width=3D8) (actual time=3D1= 023.805..1023.805 rows=3D1 loops=3D1) Output: count(*) -> Bitmap Heap Scan on public.
(cost=3D3164.92..3728.64 rows= =3D62803 width=3D0) (actual time=3D258.616..999.205 rows=3D60915 loops= =3D1) Recheck Cond: ((
.districtid =3D ANY ('{3,4,5,6,7,8,9,10,1= 1,12,13,14,15,16,17,18,19}'::integer[])) AND (
.statusid =3D ANY (= '{2,3,4,5}'::integer[])) AND (
.districtid =3D ANY ('{4,5,6,7,8,9,= 10,11,12,13,14,15,16,17,18,19,3}'::integer[]))) Heap Blocks: exact=3D52047 -> BitmapAnd (cost=3D3164.92..3164.92 rows=3D544 width=3D0) (a= ctual time=3D224.005..224.005 rows=3D0 loops=3D1) -> Bitmap Index Scan on sn=5F
r=5Fdetail=5Fall (co= st=3D0.00..564.43 rows=3D62803 width=3D0) (actual time=3D75.655..75.655 = rows=3D60941 loops=3D1) -> Bitmap Index Scan on
=5Fdistrictid=5F
rid= =5Fdateplaced=5Fidx (cost=3D0.00..2568.84 rows=3D63650 width=3D0) (actu= al time=3D143.565..143.565 rows=3D61161 loops=3D1) Index Cond: (
.districtid =3D ANY ('{4,5,6,7,8= ,9,10,11,12,13,14,15,16,17,18,19,3}'::integer[])) Planning Time: 1.538 ms Execution Time: 1023.846 ms (11 rows) Time: 1054.731 ms (00:01.055) =5F=5F=5F=5F=5F =20 From: Tom Lane [mailto:tgl@sss.pgh.pa.us] To: easteregg@verfriemelt.org Cc: pgsql-bugs@lists.postgresql.org Sent: Fri, 30 Aug 2019 00:16:45 +0200 Subject: Re: BUG #15984: order of where in() query affects query planer PG Bug reporting form writes: > i have a partial index like in the following example and when reorde= r the > elements of the in() statement, > i get sometimes a bitmap indexscan instead of the expected index onl= y scan. > if i remove an element, i still get the index only, > but with the wrong order, i get a bitmap heap scan. is this expected= =3F =20 FWIW, I get the same plan shape with either order of the IN elements. =20 However, your example is probably going to be subject to plan instabil= ity because =20 (1) you used vacuum full not plain vacuum. That doesn't leave the tab= le in the all-visible condition that would favor an index-only scan. =20 (2) you didn't analyze the table. At some point, autovacuum will come along and rectify that oversight, likely causing the plan choice to change underneath you. =20 regards, tom lane =20 -------------01f92f530274baf11ecab6a8f72c3feb Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Thank you for your reply,

i used the given example only b= ecause in my original case, i have a 12gb table totaling to 43gb with in= dices and an quite similar query along with some other clauses in the wh= erecase and still see this behavior. that table has constantly updates (= around 5-100 updates per second ) written to it.

i confirm, with the= example table after the analyse, the result is consistent.
but my real table still have different plans with= different order of the array, i attach an explain. the partial index is= defined as followed ( i have to blank out some fieldnames and tablename= s )


and the othe= r index from the bitmap query is defined like this:

(districtid, <other= tableid>, dateplaced)

 =F0=9F=90=98 08:42:38 =C2=BB user@host.org:54= 32/user > analyse verbose <table>;
INFO:  analyzing "public.<table>"
INFO:  "<table>": scanned 30= 0000 of 1608676 pages, containing 1369182 live rows and 120789 dead rows= ; 300000 rows in sample, 7341901 estimated total rows
Time: 93397.647 ms (01:33.398)<= /div>


 =F0=9F=90= =98 08:47:06 =C2=BB user@host.org:5432/user > explain (verbose, analy= se)  select count(*) from <table> where districtid in (3,4,5,= 6,7,8,9,10,11,12,13,14,15,16,17,18,19) and statusid in (2,3,4,5);=
=          =                     &= nbsp;                   &nb= sp;                    = ;   QUERY PLAN
=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90<= /div>
Aggregate  (cost=3D15644.10..15644.11= rows=3D1 width=3D8) (actual time=3D68.883..68.883 rows=3D1 loops=3D1)
  Output: count(*)
  ->  Index Only Sca= n using sn=5F<table>r=5Fdetail=5Fall on public.<table> = (cost=3D0.41..15487.10 rows=3D62803 width=3D0) (actual time=3D0.014..61= .728 rows=3D60915 loops=3D1)
        Output: districtid, datepublished
        Heap Fetc= hes: 11373
Planning Time: 1.= 636 ms
Execution Time: 68.91= 0 ms
(7 rows)<= /div>

Time: 94.375 ms

<= /span>

 =F0=9F=90=98 08:47:28 =C2=BB user@host.org:54= 32/user > explain (verbose, analyse)  select count(*) from <t= able> where districtid in (4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,= 3) and statusid in (2,3,4,5);
=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90
Aggregate  (cost=3D3885.65..3885.66 rows=3D1 width=3D8) (actual = time=3D1023.805..1023.805 rows=3D1 loops=3D1)
  Output: count(*)
  ->  Bitmap Heap Scan on public.<table&g= t;  (cost=3D3164.92..3728.64 rows=3D62803 width=3D0) (actual time= =3D258.616..999.205 rows=3D60915 loops=3D1)
        Recheck Cond: ((<table>= ;.districtid =3D ANY ('{3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19}'::i= nteger[])) AND (<table>.statusid =3D ANY ('{2,3,4,5}'::integer[]))= AND (<table>.districtid =3D ANY ('{4,5,6,7,8,9,10,11,12,13,14,15,= 16,17,18,19,3}'::integer[])))
        ->  Bit= mapAnd  (cost=3D3164.92..3164.92 rows=3D544 width=3D0) (actual time= =3D224.005..224.005 rows=3D0 loops=3D1)
              -> = Bitmap Index Scan on sn=5F<table>r=5Fdetail=5Fall  (cost=3D0= .00..564.43 rows=3D62803 width=3D0) (actual time=3D75.655..75.655 rows= =3D60941 loops=3D1)
  &= nbsp;           ->  Bitmap Index Scan o= n <table>=5Fdistrictid=5F<table>rid=5Fdateplaced=5Fidx = (cost=3D0.00..2568.84 rows=3D63650 width=3D0) (actual time=3D143.565..1= 43.565 rows=3D61161 loops=3D1)
                   = Index Cond: (<table>.districtid =3D ANY ('{4,5,6,7,8,9,10,11,12,1= 3,14,15,16,17,18,19,3}'::integer[]))
= Planning Time: 1.538 ms
Execution Time: 1023.846 ms
(11 rows)

Time: 1054.731 ms (00:01.055)=


From: T= om Lane [mailto:tgl@sss.pgh.pa.us]
To: easteregg@verfriemelt.o= rg
Cc: pgsql-bugs@lists.postgresql.org
Sent: Fri, 30= Aug 2019 00:16:45 +0200
Subject: Re: BUG #15984: order of whe= re in() query affects query planer

PG Bug reporting form <noreply@postgresql.org> wri= tes:
> i have a partial index like in the following example and when reord= er the
> elements of the in() statement,
> i get sometimes a bitmap indexscan instead of the expected index on= ly scan.
> if i remove an element, i still get the index only,
> but with the wrong order, i get a bitmap heap scan. is this expecte= d=3F

FWIW, I get the same plan shape with either order of the IN elements.
However, your example is probably going to be subject to plan instabilit= y
because

(1) you used vacuum full not plain vacuum. That doesn't leave the table=
in the all-visible condition that would favor an index-only scan.

(2) you didn't analyze the table. At some point, autovacuum will come along and rectify that oversight, likely causing the plan choice to
change underneath you.

=09=09=09regards, tom lane
-------------01f92f530274baf11ecab6a8f72c3feb--