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 1gpxlk-0004s9-2j for pgsql-bugs@arkaria.postgresql.org; Sat, 02 Feb 2019 16:03:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gpxli-0003cK-Sb for pgsql-bugs@arkaria.postgresql.org; Sat, 02 Feb 2019 16:03:46 +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 1gpvuc-0003FQ-5D for pgsql-bugs@lists.postgresql.org; Sat, 02 Feb 2019 14:04:50 +0000 Received: from sonic314-20.consmr.mail.ne1.yahoo.com ([66.163.189.146]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gpvuX-00072p-JB for pgsql-bugs@lists.postgresql.org; Sat, 02 Feb 2019 14:04:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1549116282; bh=nUjvSFecdHZtwu5KxbUTlseJzeenTwaaVAfsq/6Jnyo=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From:Subject; b=BnJxoZi9E9d8ebn+QXjVmhu+7xckMRbUa7qeoxHvurrAC+YzYzAuNIYltzr3QHjPysH5F1vnLWe8tGG+BoV/nRECgYHQyeHTwX2fWQoz3ZoMChUVg+gJ7QVhR8miaSst3WRtzAY/daKa15CiSaLjR7P8cTU//7sNFoRJnl66GDk1FSA8xZBykRtHw5wWk73QPWksfuIXsZ5DVDNMAbTdosoAUAmK5VoWxNTZsFoEBO9708LA/WXzf3B3iNDLXYhPBgLJOdZ+AM/Fso9s+jDEuUOFFzRm3UzxlSY90e1A79JfRb3eO+W6I5c72iYkfdulfW5SW8N0peusno6Gc27+VQ== X-YMail-OSG: zfoltNsVM1lUehr0IqrlPS0eggr5J_iqQayd4R5W6R6MWjCY4v3fPmsJTffWBgp dai5XH9L2PlnmDAYV0HetqrdaY6OOhMoJqwvBXxGVJ3N3sW.1YRcXCdddTF.EmrZpuhUspkEgsMk AVW7xMgRY7V6rCIeTAv2SuZ1_UtXWndAl8a5P85Ipkgd8EN.w78XUA6TGoVQXY1H5eq1VFyWlUWE 78Lf9hNj.XBunb.yJxjxLUJL4S5sfKusX8obLjeWhrHr0NPZgdEgAC8iHEwBQ9duGduAoNS8rALs ikrV0y2pscOxlqLYu0C5_wjaBzpA.ldP87XkJwNmNndmvcCXmun.saiHDdEHgy4Mu9AuWxdm.N.S gsqT_HDIaXymTmytOZolmCOiqq046UCQu9Nxx5YMMeaHvHuRaOiKldS9FU32Jv0ZD9NKq9L_yx_b ZfhHNycV7oMSwZDZr5Y9sAIu525eCKOnj1zo1VaOPR8niFZn4yru2TmWRxLPZnqylWKbZZvNAA2a TsQ.PjDdB9Ja.XgBnPHSrrhfNESB..sCcd7FiOC_yegVGDaveMNcWmKLTj7Uvl6Qwd.VzoGuHAii HbdZmKza818j38JZIeFLBKk3xQrpq_S2H8RMkXcqrv1Z6NODQRksLOttoz9k6zQYr8lcgVEjtdMv ykG.cB8sWMfT7lkim45nSxJLGbSqkmG4_U4cYBW3i_NG_E7f4J6bKRULsCrhWLi55324pJswdxRo F1GTvO9Ndv9FppkUngMCIK65P2ecoJk5z00ANVD0LVzaxUjxd1iGASj6WXsUiUF4LojznXc61Rbe yYnlysM_CtBCZzGtmKtk94IQnd354VrqxHBpindOgifZL8zt_QnEQH50YpefQ_NgxoZKMr5Y63ED GuW_VrM6.QvbrjcK1yx3MusVXeQvA04j.b_zTHGxwe5r_Gss5QTo0HQPSABOc_TlFFdC_9DJqOsO wE83P9g_GAqvdgfLgywKkVUXEyezEyz.Y_AjfdnhmifojxLlSL74ayBBjOFH7n_uDTmBILI1UEQ5 skhytDWjVjBuuTwgz8nmXYdNYffd9AuuWWmNdfXi3gz2AsazTIkEQAXEZeckeSyhCu.Krb0MrZ7G VZQakw82e Received: from sonic.gate.mail.ne1.yahoo.com by sonic314.consmr.mail.ne1.yahoo.com with HTTP; Sat, 2 Feb 2019 14:04:42 +0000 Date: Sat, 2 Feb 2019 14:04:39 +0000 (UTC) From: Alex To: Pantelis Theodosiou Cc: pgsql-bugs@lists.postgresql.org, Pavel Stehule Message-ID: <197491491.1997073.1549116279483@mail.yahoo.com> In-Reply-To: <500463610.1979975.1549112877961@mail.yahoo.com> References: <15618-5357e448d7cbeb27@postgresql.org> <378349148.1969803.1549109284822@mail.yahoo.com> <500463610.1979975.1549112877961@mail.yahoo.com> Subject: Re: BUG #15618: Duplicating a join clause breaks index use MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_1997072_1787704392.1549116279477" X-Mailer: WebService/1.1.13027 YMailNorrin Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:64.0) Gecko/20100101 Firefox/64.0 Content-Length: 52823 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------=_Part_1997072_1787704392.1549116279477 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Also, note that if I remove any of the following joins and their columns fr= om select, while keeping the duplicate join, the issue doesn't reproduce an= ymore (query is fast):left outer join product_property_value ppv on pp.valu= e_id=3Dppv.idleft outer join description_value depv on dep.description_valu= e_id=3Ddepv.idleft outer join description_value dev on de.description_value= _id=3Ddev.id On Saturday, February 2, 2019, 3:07:57 PM GMT+2, Alex wrote: =20 =20 Yes. On Saturday, February 2, 2019, 2:31:23 PM GMT+2, Pantelis Theodosiou wrote: =20 =20 Is there a foreign key from product (shop_category) that references shop_c= ategory (id) ? On Sat, Feb 2, 2019 at 12:17 PM Alex wrote: Query: select =C2=A0pp.id as id1_13_0_, =C2=A0ppv.id as id2_14_1_, =C2=A0de.id as id1_3_2_, =C2=A0dev.id as id1_5_3_, =C2=A0dep.id as id1_3_4_, =C2=A0depv.id as id1_5_5_, =C2=A0pp.description_source as descript5_13_0_, =C2=A0pp.meaning as meaning2_13_0_, =C2=A0pp.secondary_meaning as secondar3_13_0_, =C2=A0pp.source as source4_13_0_, =C2=A0pp.value_id as value_id6_13_0_, =C2=A0ppv.first as first3_14_1_, =C2=A0ppv.third as third4_14_1_, =C2=A0ppv.second as second5_14_1_, =C2=A0ppv.text as text6_14_1_, =C2=A0ppv.type as type1_14_1_, =C2=A0de.parent as parent3_3_2_, =C2=A0de.pos as pos2_3_2_, =C2=A0de.description_value_id as descript4_3_2_, =C2=A0de.product as product5_3_2_, =C2=A0dev.language as language2_5_3_, =C2=A0dev.lexeme as lexeme3_5_3_, =C2=A0dev.value as value4_5_3_, =C2=A0dep.parent as parent3_3_4_, =C2=A0dep.pos as pos2_3_4_, =C2=A0dep.description_value_id as descript4_3_4_, =C2=A0dep.product as product5_3_4_, =C2=A0depv.language as language2_5_5_, =C2=A0depv.lexeme as lexeme3_5_5_, =C2=A0depv.value as value4_5_5_ from =C2=A0=C2=A0=C2=A0 product p =C2=A0=C2=A0=C2=A0 left outer join product_property pp on p.id=3Dpp.product= _id =C2=A0=C2=A0=C2=A0 left outer join product_property_value ppv on pp.value_i= d=3Dppv.id =C2=A0=C2=A0=C2=A0 left outer join description_element de on pp.description= _source=3Dde.id =C2=A0=C2=A0=C2=A0 left outer join description_value dev on de.description_= value_id=3Ddev.id =C2=A0=C2=A0=C2=A0 left outer join description_element dep on de.parent=3Dd= ep.id =C2=A0=C2=A0=C2=A0 left outer join description_value depv on dep.descriptio= n_value_id=3Ddepv.id =C2=A0=C2=A0=C2=A0 left outer join shop_category sc_dup on p.shop_category= =3Dsc_dup.id=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 --= duplicate join =C2=A0=C2=A0=C2=A0 left outer join shop_category sc on p.shop_category=3Dsc= .id =C2=A0=C2=A0=C2=A0 left outer join category c on sc.category=3Dc.id where =C2=A0=C2=A0=C2=A0 c.id=3D8511 Explain analyze with duplicate join: "Gather=C2=A0 (cost=3D134471.60..285324.15 rows=3D48 width=3D320) (actual t= ime=3D1746.142..3854.899 rows=3D90 loops=3D1)" "=C2=A0 Workers Planned: 2" "=C2=A0 Workers Launched: 2" "=C2=A0 ->=C2=A0 Hash Join=C2=A0 (cost=3D133471.60..284319.35 rows=3D20 wid= th=3D320) (actual time=3D1753.615..3702.835 rows=3D30 loops=3D3)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Hash Cond: (p.shop_category =3D= sc.id)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ->=C2=A0 Hash Left Join=C2=A0 (= cost=3D133454.98..283698.84 rows=3D160986 width=3D324) (actual time=3D1661.= 551..3691.094 rows=3D131278 loops=3D3)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 Hash Cond: (dep.description_value_id =3D depv.id)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 ->=C2=A0 Nested Loop Left Join=C2=A0 (cost=3D119237.57..253506.99 ro= ws=3D160986 width=3D218) (actual time=3D1465.635..3282.286 rows=3D131278 lo= ops=3D3)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ->=C2=A0 Hash Left Join=C2=A0 (c= ost=3D119237.14..175609.97 rows=3D160986 width=3D198) (actual time=3D1465.6= 25..2561.546 rows=3D131278 loops=3D3)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 Hash Cond: (de.description_value_id =3D dev.id)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 ->=C2=A0 Hash Left Join=C2=A0 (cost=3D105019.73..150448.12 rows=3D16098= 6 width=3D92) (actual time=3D1260.801..2160.415 rows=3D131278 loops=3D3)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Hash Cond: (pp.value_id =3D ppv.id)= " "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ->=C2=A0 Hash Left Join=C2=A0 (cost= =3D90691.88..127921.82 rows=3D160986 width=3D52) (actual time=3D1096.581..1= 811.725 rows=3D131278 loops=3D3)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= Hash Cond: (pp.description_source =3D de.id)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= ->=C2=A0 Hash Left Join=C2=A0 (cost=3D14036.24..34090.73 rows=3D160986 wid= th=3D32) (actual time=3D187.524..370.095 rows=3D131278 loops=3D3)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Hash Cond: (p.id =3D pp.product_id)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ->=C2=A0 Parallel Seq Scan on product = p=C2=A0 (cost=3D0.00..11757.46 rows=3D37946 width=3D8) (actual time=3D0.118= ..55.751 rows=3D30357 loops=3D3)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ->=C2=A0 Hash=C2=A0 (cost=3D6564.66..6= 564.66 rows=3D386366 width=3D32) (actual time=3D185.622..185.622 rows=3D386= 366 loops=3D3)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Bu= ckets: 65536=C2=A0 Batches: 8=C2=A0 Memory Usage: 3390kB" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ->= =C2=A0 Seq Scan on product_property pp=C2=A0 (cost=3D0.00..6564.66 rows=3D3= 86366 width=3D32) (actual time=3D0.103..80.719 rows=3D386366 loops=3D3)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= ->=C2=A0 Hash=C2=A0 (cost=3D36108.73..36108.73 rows=3D2208473 width=3D20) = (actual time=3D905.265..905.265 rows=3D2208473 loops=3D3)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Buckets: 65536=C2=A0 Batches: 64=C2=A0= Memory Usage: 2254kB" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ->=C2=A0 Seq Scan on description_eleme= nt de=C2=A0 (cost=3D0.00..36108.73 rows=3D2208473 width=3D20) (actual time= =3D0.101..359.710 rows=3D2208473 loops=3D3)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ->=C2=A0 Hash=C2=A0 (cost=3D6477.38= ..6477.38 rows=3D386438 width=3D40) (actual time=3D160.004..160.004 rows=3D= 386438 loops=3D3)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= Buckets: 65536=C2=A0 Batches: 8=C2=A0 Memory Usage: 3050kB" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= ->=C2=A0 Seq Scan on product_property_value ppv=C2=A0 (cost=3D0.00..6477.3= 8 rows=3D386438 width=3D40) (actual time=3D0.108..62.499 rows=3D386438 loop= s=3D3)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 ->=C2=A0 Hash=C2=A0 (cost=3D6865.96..6865.96 rows=3D252596 width=3D106)= (actual time=3D204.657..204.657 rows=3D252596 loops=3D3)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Buckets: 32768=C2=A0 Batches: 16=C2= =A0 Memory Usage: 2449kB" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ->=C2=A0 Seq Scan on description_va= lue dev=C2=A0 (cost=3D0.00..6865.96 rows=3D252596 width=3D106) (actual time= =3D0.102..80.803 rows=3D252596 loops=3D3)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ->=C2=A0 Index Scan using descri= ption_element_pkey on description_element dep=C2=A0 (cost=3D0.43..0.48 rows= =3D1 width=3D20) (actual time=3D0.005..0.005 rows=3D1 loops=3D393835)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 Index Cond: (de.parent =3D id)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 ->=C2=A0 Hash=C2=A0 (cost=3D6865.96..6865.96 rows=3D252596 width=3D1= 06) (actual time=3D195.776..195.776 rows=3D252596 loops=3D3)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Buckets: 32768=C2=A0 Batches: 16= =C2=A0 Memory Usage: 2449kB" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ->=C2=A0 Seq Scan on description= _value depv=C2=A0 (cost=3D0.00..6865.96 rows=3D252596 width=3D106) (actual = time=3D0.019..74.589 rows=3D252596 loops=3D3)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ->=C2=A0 Hash=C2=A0 (cost=3D16.= 61..16.61 rows=3D1 width=3D4) (actual time=3D0.232..0.232 rows=3D1 loops=3D= 3)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 Buckets: 1024=C2=A0 Batches: 1=C2=A0 Memory Usage: 9kB" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 ->=C2=A0 Nested Loop=C2=A0 (cost=3D0.56..16.61 rows=3D1 width=3D4) (= actual time=3D0.224..0.226 rows=3D1 loops=3D3)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ->=C2=A0 Index Scan using shop_c= ategory_category_idx on shop_category sc=C2=A0 (cost=3D0.28..8.30 rows=3D1 = width=3D8) (actual time=3D0.095..0.095 rows=3D1 loops=3D3)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 Index Cond: (category =3D 8511)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ->=C2=A0 Index Only Scan using c= ategory_pkey on category c=C2=A0 (cost=3D0.28..8.29 rows=3D1 width=3D4) (ac= tual time=3D0.125..0.126 rows=3D1 loops=3D3)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 Index Cond: (id =3D 8511)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 Heap Fetches: 1" "Planning time: 2.543 ms" "Execution time: 3857.492 ms" Explain analyze without duplicate join: "Nested Loop=C2=A0 (cost=3D3.40..216.69 rows=3D48 width=3D320) (actual time= =3D0.203..1.624 rows=3D90 loops=3D1)" "=C2=A0 ->=C2=A0 Index Only Scan using category_pkey on category c=C2=A0 (c= ost=3D0.28..8.29 rows=3D1 width=3D4) (actual time=3D0.049..0.049 rows=3D1 l= oops=3D1)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Index Cond: (id =3D 8511)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Heap Fetches: 1" "=C2=A0 ->=C2=A0 Nested Loop Left Join=C2=A0 (cost=3D3.12..207.91 rows=3D48= width=3D324) (actual time=3D0.152..1.556 rows=3D90 loops=3D1)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ->=C2=A0 Nested Loop Left Join= =C2=A0 (cost=3D2.70..186.48 rows=3D48 width=3D218) (actual time=3D0.149..1.= 416 rows=3D90 loops=3D1)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 ->=C2=A0 Nested Loop Left Join=C2=A0 (cost=3D2.27..163.25 rows=3D48 = width=3D198) (actual time=3D0.141..1.322 rows=3D90 loops=3D1)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ->=C2=A0 Nested Loop Left Join= =C2=A0 (cost=3D1.85..141.81 rows=3D48 width=3D92) (actual time=3D0.138..1.0= 84 rows=3D90 loops=3D1)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 ->=C2=A0 Nested Loop Left Join=C2=A0 (cost=3D1.42..110.35 rows=3D48 wid= th=3D72) (actual time=3D0.133..0.967 rows=3D90 loops=3D1)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ->=C2=A0 Nested Loop Left Join=C2= =A0 (cost=3D1.00..87.41 rows=3D48 width=3D32) (actual time=3D0.101..0.651 r= ows=3D90 loops=3D1)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= ->=C2=A0 Nested Loop=C2=A0 (cost=3D0.57..78.82 rows=3D11 width=3D8) (actua= l time=3D0.069..0.432 rows=3D27 loops=3D1)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ->=C2=A0 Index Scan using shop_categor= y_category_idx on shop_category sc=C2=A0 (cost=3D0.28..8.30 rows=3D1 width= =3D8) (actual time=3D0.036..0.036 rows=3D1 loops=3D1)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 In= dex Cond: (category =3D 8511)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ->=C2=A0 Index Scan using product_shop= _category_idx on product p=C2=A0 (cost=3D0.29..70.34 rows=3D18 width=3D8) (= actual time=3D0.031..0.390 rows=3D27 loops=3D1)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 In= dex Cond: (shop_category =3D sc.id)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= ->=C2=A0 Index Scan using product_property_product_id_idx on product_prope= rty pp=C2=A0 (cost=3D0.42..0.71 rows=3D7 width=3D32) (actual time=3D0.006..= 0.007 rows=3D3 loops=3D27)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Index Cond: (p.id =3D product_id)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ->=C2=A0 Index Scan using product_p= roperty_value_pkey on product_property_value ppv=C2=A0 (cost=3D0.42..0.48 r= ows=3D1 width=3D40) (actual time=3D0.003..0.003 rows=3D1 loops=3D90)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= Index Cond: (pp.value_id =3D id)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 ->=C2=A0 Index Scan using description_element_pkey on description_eleme= nt de=C2=A0 (cost=3D0.43..0.66 rows=3D1 width=3D20) (actual time=3D0.001..0= .001 rows=3D0 loops=3D90)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Index Cond: (pp.description_source = =3D id)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ->=C2=A0 Index Scan using descri= ption_value_pkey on description_value dev=C2=A0 (cost=3D0.42..0.45 rows=3D1= width=3D106) (actual time=3D0.002..0.002 rows=3D0 loops=3D90)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 Index Cond: (de.description_value_id =3D id)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 ->=C2=A0 Index Scan using description_element_pkey on description_el= ement dep=C2=A0 (cost=3D0.43..0.48 rows=3D1 width=3D20) (actual time=3D0.00= 1..0.001 rows=3D0 loops=3D90)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Index Cond: (de.parent =3D id)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ->=C2=A0 Index Scan using descr= iption_value_pkey on description_value depv=C2=A0 (cost=3D0.42..0.45 rows= =3D1 width=3D106) (actual time=3D0.001..0.001 rows=3D0 loops=3D90)" "=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 Index Cond: (dep.description_value_id =3D id)" "Planning time: 2.689 ms" "Execution time: 1.746 ms" Note that both query results are the same. Using order by all columns in se= lect results in same content. On Friday, February 1, 2019, 8:25:44 PM GMT+2, Pavel Stehule wrote: =20 =20 =20 p=C3=A1 1. 2. 2019 v=C2=A019:03 odes=C3=ADlatel PG Bug reporting form napsal: The following bug has been logged on the website: Bug reference:=C2=A0 =C2=A0 =C2=A0 15618 Logged by:=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 cd a Email address:=C2=A0 =C2=A0 =C2=A0 cdalxndr@yahoo.com PostgreSQL version: 10.3 Operating system:=C2=A0 =C2=A0Windows 10 Description:=C2=A0 =C2=A0 =C2=A0 =C2=A0=20 Adding a unused join clause to the query, modifies the run time from 50ms t= o 4seconds. No columns from the join clause are returned and the joined table is not used in other places. The join clause is a duplicate of another one that is used for further joining. The joined clause should have been automatically removed as it has no side effects, thus using indices and optimizing query runtime. Please, can you send a example. Generally, you can remove only some outer j= oin clauses. unused inner join cannot be removed, because it can has impact= on result. Regards Pavel Stehule =20 =20 ------=_Part_1997072_1787704392.1549116279477 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Also,= note that if I remove any of the following joins and their columns = from select, while keeping the duplicate join, the issue doesn't reproduce = anymore (query is fast):
left outer join product_property_v= alue ppv on pp.value_id=3Dppv.id
left outer join des= cription_value depv on dep.description_value_id=3Ddepv.id
= left outer join description_value dev on de.description_value_i= d=3Ddev.id
=20
On Saturday, February 2, 2019, 3:07:57 PM GMT+2, Alex &= lt;cdalxndr@yahoo.com> wrote:


Yes.

=20
=20
On Saturday, February 2, 2019, 2:31:23 PM GMT+2, Pantel= is Theodosiou <ypercube@gmail.com> wrote:


Is the= re a foreign key from product (shop_category) that references <= /span>shop_category (id) ?

On Sat, Feb 2, 2019 at 12:17 PM Alex <cdalxndr@yahoo.com> wrote:
Query:

<= /span>
select
 pp.id as id1_13_0_, ppv.id as id2_14_1_,
 de= .id as id1_3_2_,
 dev.id as id1_5_3_,
 dep.id as id1_3_4_,
 depv= .id as id1_5_5_,
 pp.description_source as descr= ipt5_13_0_,
 pp.meaning as meaning2_13_0_,
 pp.secondary_meaning as secondar3_13_0_,
=  pp.source as source4_13_0_,
 pp.value_id as va= lue_id6_13_0_,
 ppv.first as first3_14_1_,
 ppv.third as third4_14_1_,
 ppv.seco= nd as second5_14_1_,
 ppv.text as text6_14_1_,
 ppv.type as type1_14_1_,
 de.pare= nt as parent3_3_2_,
 de.pos as pos2_3_2_,
 de.description_value_id as descript4_3_2_,
 de.product as product5_3_2_,
 dev.language a= s language2_5_3_,
 dev.lexeme as lexeme3_5_3_,
 dev.value as value4_5_3_,
 dep.pa= rent as parent3_3_4_,
 dep.pos as pos2_3_4_,
 dep.description_value_id as descript4_3_4_,
 dep.product as product5_3_4_,
 depv.langua= ge as language2_5_5_,
 depv.lexeme as lexeme3_5_5_,<= br clear=3D"none"> depv.value as value4_5_5_
from    product p
  =   left outer join product_property pp on p.id=3Dpp.product_id
    left outer join product_property_value ppv = on pp.value_id=3Dppv.id
    left out= er join description_element de on pp.description_source=3Dde.id
    left outer join description_value dev on de.d= escription_value_id=3Ddev.id
    left= outer join description_element dep on de.parent=3Ddep.id
    left outer join description_value depv on dep.desc= ription_value_id=3Ddepv.id
    left = outer join shop_category sc_dup on p.shop_category=3Dsc_dup.id = ;          --duplicate join    left outer join shop_category sc on p.sh= op_category=3Dsc.id
    left outer joi= n category c on sc.category=3Dc.id
where
    c.id=3D8511

=
Explain analyze with duplicate j= oin:

"Gather  (cost=3D134471.60..285324.15 rows=3D48 w= idth=3D320) (actual time=3D1746.142..3854.899 rows=3D90 loops=3D1)"
"  Workers Planned: 2"
"  Workers La= unched: 2"
"  ->  Hash Join  (cost=3D13= 3471.60..284319.35 rows=3D20 width=3D320) (actual time=3D1753.615..3702.835= rows=3D30 loops=3D3)"
"     &nb= sp;  Hash Cond: (p.shop_category =3D sc.id)"
"&n= bsp;       ->  Hash Left Join  (= cost=3D133454.98..283698.84 rows=3D160986 width=3D324) (actual time=3D1661.= 551..3691.094 rows=3D131278 loops=3D3)"
"  &nbs= p;           Hash Cond: (= dep.description_value_id =3D depv.id)"
"  = ;            ->&n= bsp; Nested Loop Left Join  (cost=3D119237.57..253506.99 rows=3D160986= width=3D218) (actual time=3D1465.635..3282.286 rows=3D131278 loops=3D3)""         &nb= sp;          ->  Hash = Left Join  (cost=3D119237.14..175609.97 rows=3D160986 width=3D198) (ac= tual time=3D1465.625..2561.546 rows=3D131278 loops=3D3)"
= "            &n= bsp;            = ; Hash Cond: (de.description_value_id =3D dev.id)"
"=             &nb= sp;            = ->  Hash Left Join  (cost=3D105019.73..150448.12 rows=3D16098= 6 width=3D92) (actual time=3D1260.801..2160.415 rows=3D131278 loops=3D3)""         &nb= sp;            =           Hash Cond: (pp.value= _id =3D ppv.id)"
"     &nbs= p;            &= nbsp;           &nbs= p; ->  Hash Left Join  (cost=3D90691.88..127921.82 rows=3D1609= 86 width=3D52) (actual time=3D1096.581..1811.725 rows=3D131278 loops=3D3)"<= br clear=3D"none">"         &n= bsp;            = ;            &n= bsp;   Hash Cond: (pp.description_source =3D de.id)"
"          &nbs= p;            &= nbsp;           &nbs= p;  ->  Hash Left Join  (cost=3D14036.24..34090.73 rows= =3D160986 width=3D32) (actual time=3D187.524..370.095 rows=3D131278 loops= =3D3)"
"        &= nbsp;           &nbs= p;            &= nbsp;          Hash Cond: (p.id= =3D pp.product_id)"
"     &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p; ->  Parallel Seq Scan on product p  (cost=3D0.00..11757.46 = rows=3D37946 width=3D8) (actual time=3D0.118..55.751 rows=3D30357 loops=3D3= )"
"         = ;            &n= bsp;            = ;          ->  Hash&nb= sp; (cost=3D6564.66..6564.66 rows=3D386366 width=3D32) (actual time=3D185.6= 22..185.622 rows=3D386366 loops=3D3)"
"   =             &nb= sp;            =             &nb= sp;         Buckets: 65536  Ba= tches: 8  Memory Usage: 3390kB"
"   &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;         ->  Seq Scan on = product_property pp  (cost=3D0.00..6564.66 rows=3D386366 width=3D32) (= actual time=3D0.103..80.719 rows=3D386366 loops=3D3)"
"&n= bsp;            = ;            &n= bsp;            ->= ;  Hash  (cost=3D36108.73..36108.73 rows=3D2208473 width=3D20) (a= ctual time=3D905.265..905.265 rows=3D2208473 loops=3D3)"
= "            &n= bsp;            = ;            &n= bsp;      Buckets: 65536  Batches: 64  M= emory Usage: 2254kB"
"      = ;            &n= bsp;            = ;             -= >  Seq Scan on description_element de  (cost=3D0.00..36108.73 = rows=3D2208473 width=3D20) (actual time=3D0.101..359.710 rows=3D2208473 loo= ps=3D3)"
"        = ;            &n= bsp;           -> = ; Hash  (cost=3D6477.38..6477.38 rows=3D386438 width=3D40) (actual tim= e=3D160.004..160.004 rows=3D386438 loops=3D3)"
" &nb= sp;            =             &nb= sp;           Buckets: 65= 536  Batches: 8  Memory Usage: 3050kB"
" &= nbsp;           &nbs= p;            &= nbsp;           ->&nbs= p; Seq Scan on product_property_value ppv  (cost=3D0.00..6477.38 rows= =3D386438 width=3D40) (actual time=3D0.108..62.499 rows=3D386438 loops=3D3)= "
"         =             &nb= sp;    ->  Hash  (cost=3D6865.96..6865.96 rows= =3D252596 width=3D106) (actual time=3D204.657..204.657 rows=3D252596 loops= =3D3)"
"        &= nbsp;           &nbs= p;           Buckets: 327= 68  Batches: 16  Memory Usage: 2449kB"
" &= nbsp;           &nbs= p;            &= nbsp;     ->  Seq Scan on description_value dev=   (cost=3D0.00..6865.96 rows=3D252596 width=3D106) (actual time=3D0.10= 2..80.803 rows=3D252596 loops=3D3)"
"   &n= bsp;            = ;    ->  Index Scan using description_element_pkey o= n description_element dep  (cost=3D0.43..0.48 rows=3D1 width=3D20) (ac= tual time=3D0.005..0.005 rows=3D1 loops=3D393835)"
" = ;            &n= bsp;            Inde= x Cond: (de.parent =3D id)"
"    &nbs= p;         ->  Hash  (= cost=3D6865.96..6865.96 rows=3D252596 width=3D106) (actual time=3D195.776..= 195.776 rows=3D252596 loops=3D3)"
"   &nbs= p;            &= nbsp;   Buckets: 32768  Batches: 16  Memory Usage: 2449= kB"
"        &nbs= p;           ->  = Seq Scan on description_value depv  (cost=3D0.00..6865.96 rows=3D25259= 6 width=3D106) (actual time=3D0.019..74.589 rows=3D252596 loops=3D3)"
"        ->  Hash&n= bsp; (cost=3D16.61..16.61 rows=3D1 width=3D4) (actual time=3D0.232..0.232 r= ows=3D1 loops=3D3)"
"      =         Buckets: 1024  Batches: 1&n= bsp; Memory Usage: 9kB"
"     &n= bsp;        ->  Nested Loop = ; (cost=3D0.56..16.61 rows=3D1 width=3D4) (actual time=3D0.224..0.226 rows= =3D1 loops=3D3)"
"      &nb= sp;            = ->  Index Scan using shop_category_category_idx on shop_category s= c  (cost=3D0.28..8.30 rows=3D1 width=3D8) (actual time=3D0.095..0.095 = rows=3D1 loops=3D3)"
"      = ;            &n= bsp;       Index Cond: (category =3D 8511)""         &nb= sp;          ->  Index= Only Scan using category_pkey on category c  (cost=3D0.28..8.29 rows= =3D1 width=3D4) (actual time=3D0.125..0.126 rows=3D1 loops=3D3)"
"          &nbs= p;            &= nbsp;  Index Cond: (id =3D 8511)"
"   = ;            &n= bsp;          Heap Fetches: 1"=
"Planning time: 2.543 ms"
= "Execution time: 3857.492 ms"
Explain analyze without duplicate join:

"Nested Loop  (cost=3D3.40.= .216.69 rows=3D48 width=3D320) (actual time=3D0.203..1.624 rows=3D90 loops= =3D1)"
"  ->  Index Only Scan using category= _pkey on category c  (cost=3D0.28..8.29 rows=3D1 width=3D4) (actual ti= me=3D0.049..0.049 rows=3D1 loops=3D1)"
"   = ;     Index Cond: (id =3D 8511)"
"&nb= sp;       Heap Fetches: 1"
= "  ->  Nested Loop Left Join  (cost=3D3.12..207.91 rows= =3D48 width=3D324) (actual time=3D0.152..1.556 rows=3D90 loops=3D1)"
"        ->  Nested = Loop Left Join  (cost=3D2.70..186.48 rows=3D48 width=3D218) (actual ti= me=3D0.149..1.416 rows=3D90 loops=3D1)"
"  &nbs= p;           ->  = Nested Loop Left Join  (cost=3D2.27..163.25 rows=3D48 width=3D198) (ac= tual time=3D0.141..1.322 rows=3D90 loops=3D1)"
" &nb= sp;            =       ->  Nested Loop Left Join  (cos= t=3D1.85..141.81 rows=3D48 width=3D92) (actual time=3D0.138..1.084 rows=3D9= 0 loops=3D1)"
"       =             &nb= sp;      ->  Nested Loop Left Join  (= cost=3D1.42..110.35 rows=3D48 width=3D72) (actual time=3D0.133..0.967 rows= =3D90 loops=3D1)"
"      &n= bsp;            = ;             -= >  Nested Loop Left Join  (cost=3D1.00..87.41 rows=3D48 width= =3D32) (actual time=3D0.101..0.651 rows=3D90 loops=3D1)"
= "            &n= bsp;            = ;             -= >  Nested Loop  (cost=3D0.57..78.82 rows=3D11 width=3D8) (actu= al time=3D0.069..0.432 rows=3D27 loops=3D1)"
"  = ;            &n= bsp;            = ;            &n= bsp;    ->  Index Scan using shop_category_category_= idx on shop_category sc  (cost=3D0.28..8.30 rows=3D1 width=3D8) (actua= l time=3D0.036..0.036 rows=3D1 loops=3D1)"
"  &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;          Index Cond: (categ= ory =3D 8511)"
"       = ;            &n= bsp;            = ;            ->&n= bsp; Index Scan using product_shop_category_idx on product p  (cost=3D= 0.29..70.34 rows=3D18 width=3D8) (actual time=3D0.031..0.390 rows=3D27 loop= s=3D1)"
"        =             &nb= sp;            =             &nb= sp;    Index Cond: (shop_category =3D sc.id)"
"          &nbs= p;            &= nbsp;           &nbs= p;  ->  Index Scan using product_property_product_id_idx on pr= oduct_property pp  (cost=3D0.42..0.71 rows=3D7 width=3D32) (actual tim= e=3D0.006..0.007 rows=3D3 loops=3D27)"
"   = ;            &n= bsp;            = ;            &n= bsp;   Index Cond: (p.id =3D product_id)"
"&= nbsp;           &nbs= p;            &= nbsp;      ->  Index Scan using product_pr= operty_value_pkey on product_property_value ppv  (cost=3D0.42..0.48 ro= ws=3D1 width=3D40) (actual time=3D0.003..0.003 rows=3D1 loops=3D90)"
"          &n= bsp;            = ;            &n= bsp;  Index Cond: (pp.value_id =3D id)"
"  = ;            &n= bsp;           -> = ; Index Scan using description_element_pkey on description_element de = (cost=3D0.43..0.66 rows=3D1 width=3D20) (actual time=3D0.001..0.001 rows= =3D0 loops=3D90)"
"      &n= bsp;            = ;             I= ndex Cond: (pp.description_source =3D id)"
"  &= nbsp;           &nbs= p;     ->  Index Scan using description_value_p= key on description_value dev  (cost=3D0.42..0.45 rows=3D1 width=3D106)= (actual time=3D0.002..0.002 rows=3D0 loops=3D90)"
" = ;            &n= bsp;            Inde= x Cond: (de.description_value_id =3D id)"
"  &n= bsp;           -> = ; Index Scan using description_element_pkey on description_element dep = ; (cost=3D0.43..0.48 rows=3D1 width=3D20) (actual time=3D0.001..0.001 rows= =3D0 loops=3D90)"
"      &n= bsp;            = ; Index Cond: (de.parent =3D id)"
"   &nbs= p;    ->  Index Scan using description_value_pkey on= description_value depv  (cost=3D0.42..0.45 rows=3D1 width=3D106) (act= ual time=3D0.001..0.001 rows=3D0 loops=3D90)"
" &nbs= p;            Index = Cond: (dep.description_value_id =3D id)"
"Planning time: = 2.689 ms"
"Execution time: 1.746 ms"

Note that b= oth query results are the same. Using order by all columns in select result= s in same content.
=
=20
=20
On Friday, February 1, 2019, 8:25:44 PM GMT+2, Pavel St= ehule <pave= l.stehule@gmail.com> wrote:




p=C3=A1 1. 2. 2019 v 19:03 odes=C3= =ADlatel PG Bug reporting form <noreply@postgresql.org> napsal:
The following bug has been logged on th= e website:

Bug reference:      15618
Logged by:          cd a
Email address:      cdalxndr@yahoo.com
PostgreSQL version: 10.3
Operating system:   Windows 10
Description:       

Adding a unused join clause to the query, modifies the run time from 50ms t= o
4seconds.
No columns from the join clause are returned and the joined table is not used in other places.
The join clause is a duplicate of another one that is used for further
joining.

The joined clause should have been automatically removed as it has no side<= br clear=3D"none"> effects, thus using indices and optimizing query runtime.

Please, can you send a exa= mple. Generally, you can remove only some outer join clauses. unused inner = join cannot be removed, because it can has impact on result.

Regards

P= avel Stehule
------=_Part_1997072_1787704392.1549116279477--