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 1gpuEr-0006sQ-Lv for pgsql-bugs@arkaria.postgresql.org; Sat, 02 Feb 2019 12:17:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gpuEp-0004Ym-PD for pgsql-bugs@arkaria.postgresql.org; Sat, 02 Feb 2019 12:17:35 +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 1gpu5r-0000kV-EZ for pgsql-bugs@lists.postgresql.org; Sat, 02 Feb 2019 12:08:20 +0000 Received: from sonic310-21.consmr.mail.ne1.yahoo.com ([66.163.186.202]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gpu5n-0001bI-QV for pgsql-bugs@lists.postgresql.org; Sat, 02 Feb 2019 12:08:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1549109292; bh=m4awHP5FJMHKTLxZbl6acPUOA6YxeCVQhZS3VO0hEMk=; h=Date:From:To:In-Reply-To:References:Subject:From:Subject; b=r4I3EaMWiy2ndV74UYpC1m7RLCfTkFty7wfsINcfrV+E1bV6XHQQEOQzBNDEY1JseFfTaim3DMn3Wf66jMRuBmxyn38RW5+M33BBaVIr2Ryw7rdHCOZ1ANuwt/BMMvHqS5Y7HX5QNG5H2Z5ULxqSQnOq+oC70oM4muJ1HJcL4trxN2rosH3nt2z7ITtkf1G1q2mg2BFn4Awwjdf3LcjuOaPB/AcyhT8k+PWZELgKjTTsepJ4O468798wMuzFRulVqWDoWbpbwdqgNs6EdO0SrwnoDOGnyvvAQ7WvMVXeh2/5c0YO9gYfO2Qb2/74UvcKhxwZVr9rYpsii7UH9OiKMA== X-YMail-OSG: wcXGdBUVM1nxXKpgf8y_fVnrk1Wuc5ayEm7sYuTuy9kX3vg7SoMSpTM5jjAYLCk PB8vR7U.9jOjX2Txqd5mXw2FKTltX1jmdW6ILx0LJsECX5M0uSaT08xhUQh9yeUM8FIfXxTXYiOt PhEa9kGoku.vBILnNHGtfsP0W7R7C..lj83XNvXa3S1RJGgGwMzPZQXDQM2fZHGV.TeWlWri_tcC 5o_qeumHtifivg.8JEM16KW5x5GGSf5dNuD0FOP_NsYnBxIgYtIm_2QVGoEJNWyPbvxOEMpq70r8 nxz8GLyq6_U5.4rZUYr_AAKRmDn49Bnk7WbzAnQE0WEk1shmKXAZCicXLSMQbzXugij6X0A.crzU QTDn02XsAZVj6TbvpLm7JOkmuJNLKJyj5215QblN0V2b7.PJjeYNOn6zMUNQw_2fmL.tEObb_WW7 EXbo.GgaC1FGQkqifOZUzqxSm6s0UtcQT.jpN41QMYuJVDymG3kH90ZYqZJipFC3cnayoxdjI1ld pK3JROkSlnoh9eipGXJD8TcUqIMq85pdIclpQnH9SxB.0AlSgR2sjfLax9LEapsTz.0mDp.QMlI9 05wgqiKNVHo3hU7yh3M8kwOHniOdREYkDLcPg2mThpoJFG0_VWAMh5fziXQT8q47QWERKSm4wndP feV5n2dg0Cu0Q73gr1tfYHy1443B4npXvIzOTWKsmhmO45iG5Vp37svhNvpMJxh6SqZ5LyYRWB9F I7CtVSkmWZnLT4.5ue05ufFDrxmJPzOItnzJ0BAa0RU4PFZ.Ba5ae8qIZ9HC4wUupbHqc463MTQ. ahCsTeE4JkvuL2XySpDNyL1MxO6yPUYX7gn7x6GTpi3tFyoGegZJCNrYsCI0ZUhpHdvRGWjgp5lA W3YKfhDKW59XTScGO3iHuORJZ4yMVH11s1v_GOfxq3CE.dFovhYIg.h7LvamiVfXsRZwuqoHisqY Wr0HQZGJIe8RRtd8IudOib1RFxUXFGV57utHwL1rKMyBIOycvUw.Kodxa4JrAJ4K0S1AhNrQET_c zEpqXigxH.AYKuRqho7Yn26yCqhb6yOtqR9QNNas5m.qVYLA0hKecja.5RlaxtAmSj7KusZjDHiA - Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.ne1.yahoo.com with HTTP; Sat, 2 Feb 2019 12:08:12 +0000 Date: Sat, 2 Feb 2019 12:08:04 +0000 (UTC) From: Alex To: pgsql-bugs@lists.postgresql.org, Pavel Stehule Message-ID: <378349148.1969803.1549109284822@mail.yahoo.com> In-Reply-To: References: <15618-5357e448d7cbeb27@postgresql.org> Subject: Re: BUG #15618: Duplicating a join clause breaks index use MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_1969802_1345853908.1549109284818" 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: 44553 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------=_Part_1969802_1345853908.1549109284818 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 ------=_Part_1969802_1345853908.1549109284818 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Query:

select
 pp.id as id1_13_0_,
 ppv.id as id2_14_1_,
&nb= sp;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 descri= pt5_13_0_,
 pp.meaning as meaning2_13_0_,
 pp.secondary_mea= ning as secondar3_13_0_,
 pp.source as source4_13_0_,
 pp.v= alue_id as value_id6_13_0_,
 ppv.first as first3_14_1_,
 pp= v.third as third4_14_1_,
 ppv.second as second5_14_1_,
 ppv= .text as text6_14_1_,
 ppv.type as type1_14_1_,
 de.parent = as parent3_3_2_,
 de.pos as pos2_3_2_,
 de.description_valu= e_id as descript4_3_2_,
 de.product as product5_3_2_,
 dev.= language as language2_5_3_,
 dev.lexeme as lexeme3_5_3_,
 d= ev.value as value4_5_3_,
 dep.parent as parent3_3_4_,
 dep.= pos as pos2_3_4_,
 dep.description_value_id as descript4_3_4_,
&= nbsp;dep.product as product5_3_4_,
 depv.language as language2_5_5_= ,
 depv.lexeme as lexeme3_5_5_,
 depv.value as value4_5_5_<= br>from
    product p
    left outer jo= in product_property pp on p.id=3Dpp.product_id
    left o= uter join product_property_value ppv on pp.value_id=3Dppv.id
  = ;  left outer join description_element de on pp.description_source=3Dd= e.id
    left outer join description_value dev on de.desc= ription_value_id=3Ddev.id
    left outer join description= _element dep on de.parent=3Ddep.id
    left outer join de= scription_value depv on dep.description_value_id=3Ddepv.id
  &= nbsp; left outer join shop_category sc_dup on p.shop_category=3Dsc_dup.id&n= bsp;          --duplicate join=
    left outer join shop_category sc on p.shop_category= =3Dsc.id
    left outer join category c on sc.category=3D= c.id
where
    c.id=3D8511

Explain analyze with duplicate join:
=

"Gather  (cost=3D134471.6= 0..285324.15 rows=3D48 width=3D320) (actual time=3D1746.142..3854.899 rows= =3D90 loops=3D1)"
"  Workers Planned: 2"
"  Workers Launche= d: 2"
"  ->  Hash Join  (cost=3D133471.60..284319.35 r= ows=3D20 width=3D320) (actual time=3D1753.615..3702.835 rows=3D30 loops=3D3= )"
"        Hash Cond: (p.shop_catego= ry =3D sc.id)"
"        ->  H= ash Left Join  (cost=3D133454.98..283698.84 rows=3D160986 width=3D324)= (actual time=3D1661.551..3691.094 rows=3D131278 loops=3D3)"
" &nbs= p;            Hash C= ond: (dep.description_value_id =3D depv.id)"
"    &n= bsp;         ->  Nested Loo= p 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) (actual time=3D1465.625..2561.546= rows=3D131278 loops=3D3)"
"       &n= bsp;            = ;      Hash Cond: (de.description_value_id =3D dev= .id)"
"           = ;            &n= bsp;  ->  Hash Left Join  (cost=3D105019.73..150448.12 ro= ws=3D160986 width=3D92) (actual time=3D1260.801..2160.415 rows=3D131278 loo= ps=3D3)"
"          &n= bsp;            = ;         Hash Cond: (pp.value_id = =3D ppv.id)"
"         &nbs= p;            &= nbsp;         ->  Hash Left= Join  (cost=3D90691.88..127921.82 rows=3D160986 width=3D52) (actual t= ime=3D1096.581..1811.725 rows=3D131278 loops=3D3)"
"   &n= bsp;            = ;            &n= bsp;         Hash Cond: (pp.descrip= tion_source =3D de.id)"
"        = ;            &n= bsp;            = ;     ->  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.i= d =3D pp.product_id)"
"        &= nbsp;           &nbs= p;            &= nbsp;          ->  Par= allel 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;            = ;            &n= bsp;    ->  Hash  (cost=3D6564.66..6564.66 rows= =3D386366 width=3D32) (actual time=3D185.622..185.622 rows=3D386366 loops= =3D3)"
"          &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp; Buckets: 65536  Batches: 8  Memory Usage: 3390kB"
" = ;            &n= bsp;            = ;            &n= bsp;           -> = ; 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)"
"&nb= sp;            =             &nb= sp;            ->=   Hash  (cost=3D36108.73..36108.73 rows=3D2208473 width=3D20) (ac= tual time=3D905.265..905.265 rows=3D2208473 loops=3D3)"
"  &nb= sp;            =             &nb= sp;            =     Buckets: 65536  Batches: 64  Memory Usage: 225= 4kB"
"           =             &nb= sp;            =         ->  Seq Scan on descript= ion_element de  (cost=3D0.00..36108.73 rows=3D2208473 width=3D20) (act= ual time=3D0.101..359.710 rows=3D2208473 loops=3D3)"
"   =             &nb= sp;            =     ->  Hash  (cost=3D6477.38..6477.38 rows=3D3= 86438 width=3D40) (actual time=3D160.004..160.004 rows=3D386438 loops=3D3)"=
"           &nbs= p;            &= nbsp;           &nbs= p; Buckets: 65536  Batches: 8  Memory Usage: 3050kB"
" &n= bsp;            = ;            &n= bsp;           -> = ; 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)"
" = ;            &n= bsp;            = ;      Buckets: 32768  Batches: 16  Memo= ry Usage: 2449kB"
"         = ;            &n= bsp;          ->  Seq = Scan on description_value dev  (cost=3D0.00..6865.96 rows=3D252596 wid= th=3D106) (actual time=3D0.102..80.803 rows=3D252596 loops=3D3)"
" =             &nb= sp;      ->  Index Scan using description_= element_pkey on description_element dep  (cost=3D0.43..0.48 rows=3D1 w= idth=3D20) (actual time=3D0.005..0.005 rows=3D1 loops=3D393835)"
" =             &nb= sp;            Index= Cond: (de.parent =3D id)"
"       &n= bsp;      ->  Hash  (cost=3D6865.96..= 6865.96 rows=3D252596 width=3D106) (actual time=3D195.776..195.776 rows=3D2= 52596 loops=3D3)"
"         = ;           Buckets: 3276= 8  Batches: 16  Memory Usage: 2449kB"
"    = ;            &n= bsp;   ->  Seq Scan on description_value depv  (cost= =3D0.00..6865.96 rows=3D252596 width=3D106) (actual time=3D0.019..74.589 ro= ws=3D252596 loops=3D3)"
"        ->= ;  Hash  (cost=3D16.61..16.61 rows=3D1 width=3D4) (actual time=3D= 0.232..0.232 rows=3D1 loops=3D3)"
"      &= nbsp;       Buckets: 1024  Batches: 1&nb= sp; Memory Usage: 9kB"
"        =       ->  Nested Loop  (cost=3D0.56..= 16.61 rows=3D1 width=3D4) (actual time=3D0.224..0.226 rows=3D1 loops=3D3)"<= br>"            = ;        ->  Index Scan using sh= op_category_category_idx on shop_category sc  (cost=3D0.28..8.30 rows= =3D1 width=3D8) (actual time=3D0.095..0.095 rows=3D1 loops=3D3)"
" =             &nb= sp;            Index= Cond: (category =3D 8511)"
"       &= nbsp;            -&g= t;  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= )"
"           &n= bsp;            = ;  Index Cond: (id =3D 8511)"
"      =             &nb= sp;       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 w= idth=3D320) (actual time=3D0.203..1.624 rows=3D90 loops=3D1)"
"  -&= gt;  Index Only Scan using category_pkey on category c  (cost=3D0= .28..8.29 rows=3D1 width=3D4) (actual time=3D0.049..0.049 rows=3D1 loops=3D= 1)"
"        Index Cond: (id =3D 8511= )"
"        Heap Fetches: 1"
"&nbs= p; ->  Nested Loop Left Join  (cost=3D3.12..207.91 rows=3D48 w= idth=3D324) (actual time=3D0.152..1.556 rows=3D90 loops=3D1)"
" &nb= sp;      ->  Nested Loop Left Join  (= cost=3D2.70..186.48 rows=3D48 width=3D218) (actual time=3D0.149..1.416 rows= =3D90 loops=3D1)"
"         = ;     ->  Nested Loop Left Join  (cost=3D2= .27..163.25 rows=3D48 width=3D198) (actual time=3D0.141..1.322 rows=3D90 lo= ops=3D1)"
"          &= nbsp;         ->  Nested Lo= op Left Join  (cost=3D1.85..141.81 rows=3D48 width=3D92) (actual time= =3D0.138..1.084 rows=3D90 loops=3D1)"
"     &nb= sp;            =         ->  Nested Loop Left Joi= n  (cost=3D1.42..110.35 rows=3D48 width=3D72) (actual time=3D0.133..0.= 967 rows=3D90 loops=3D1)"
"       &nb= sp;            =             ->&nb= sp; Nested Loop Left Join  (cost=3D1.00..87.41 rows=3D48 width=3D32) (= actual time=3D0.101..0.651 rows=3D90 loops=3D1)"
"   &nbs= p;            &= nbsp;           &nbs= p;         ->  Nested Loop&= nbsp; (cost=3D0.57..78.82 rows=3D11 width=3D8) (actual time=3D0.069..0.432 = rows=3D27 loops=3D1)"
"        &= nbsp;           &nbs= p;            &= nbsp;          ->  Ind= ex Scan using shop_category_category_idx on shop_category sc  (cost=3D= 0.28..8.30 rows=3D1 width=3D8) (actual time=3D0.036..0.036 rows=3D1 loops= =3D1)"
"          &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp; Index Cond: (category =3D 8511)"
"     &n= bsp;            = ;            &n= bsp;            = ; ->  Index Scan using product_shop_category_idx on product p = (cost=3D0.29..70.34 rows=3D18 width=3D8) (actual time=3D0.031..0.390 rows= =3D27 loops=3D1)"
"         = ;            &n= bsp;            = ;            &n= bsp;   Index Cond: (shop_category =3D sc.id)"
"  &nb= sp;            =             &nb= sp;          ->  Index= Scan using product_property_product_id_idx on product_property pp  (c= ost=3D0.42..0.71 rows=3D7 width=3D32) (actual time=3D0.006..0.007 rows=3D3 = loops=3D27)"
"         &nbs= p;            &= nbsp;           &nbs= p;         Index Cond: (p.id =3D pr= oduct_id)"
"          =             &nb= sp;         ->  Index Scan = using product_property_value_pkey on product_property_value ppv  (cost= =3D0.42..0.48 rows=3D1 width=3D40) (actual time=3D0.003..0.003 rows=3D1 loo= ps=3D90)"
"          &= nbsp;           &nbs= p;            &= nbsp;  Index Cond: (pp.value_id =3D id)"
"    &= nbsp;           &nbs= p;         ->  Index Scan u= sing 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)= "
"           &nb= sp;            =         Index Cond: (pp.description_sour= ce =3D id)"
"          = ;          ->  Index S= can using description_value_pkey on description_value dev  (cost=3D0.4= 2..0.45 rows=3D1 width=3D106) (actual time=3D0.002..0.002 rows=3D0 loops=3D= 90)"
"           =             &nb= sp;  Index Cond: (de.description_value_id =3D id)"
"  &nb= sp;           -> = 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)"
"         = ;           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) (actual time=3D0.001..0.001 rows= =3D0 loops=3D90)"
"         = ;     Index Cond: (dep.description_value_id =3D id)""Planning time: 2.689 ms"
"Execution time: 1.746 ms"<= /span>

Note that both query res= ults are the same. Using order by all columns in select results in same con= tent.
=20
=20
On Friday, February 1, 2019, 8:25:44 PM GMT+2, Pavel St= ehule <pavel.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 the website:

Bug reference:      15618
Logged by:          cd a
Email address:      cdal= xndr@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> effects, thus using indices and optimizing query runtime.
<= div>
Please, can you send a example. Generally, you can remov= e only some outer join clauses. unused inner join cannot be removed, becaus= e it can has impact on result.

Regards
<= br>
Pavel Stehule
------=_Part_1969802_1345853908.1549109284818--