Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e9pIj-000471-1s for pgsql-general@arkaria.postgresql.org; Wed, 01 Nov 2017 09:27:09 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1e9pIi-0001JL-JD for pgsql-general@arkaria.postgresql.org; Wed, 01 Nov 2017 09:27:08 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e9pGE-0005Bl-Ja for pgsql-general@postgresql.org; Wed, 01 Nov 2017 09:24:34 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1e9pG8-0005We-Jj for pgsql-general@postgresql.org; Wed, 01 Nov 2017 09:24:32 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id 0A8921297; Wed, 1 Nov 2017 10:24:25 +0100 (CET) Date: Wed, 1 Nov 2017 10:24:25 +0100 From: "Peter J. Holzer" To: pgsql-general@postgresql.org Subject: Query plan for Merge Semi Join Message-ID: <20171101092425.4m2wttlnf7tsv4qw@hjp.at> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="jpb2tqdiiphxqos5" Content-Disposition: inline User-Agent: NeoMutt/20170113 (1.7.2) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-general Precedence: bulk Sender: pgsql-general-owner@postgresql.org --jpb2tqdiiphxqos5 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable [PostgreSQL 9.5.9 on x86_64-pc-linux-gnu, compiled by gcc (Debian 4.9.2-10) 4.9.2, 64-bit] While investigating a performance issue, I found this query plan: wds=3D> explain analyze select facttablename, columnname, term, concept_id, t.hidden, languag= e, register, c.id, canonicalname, description, parent, type, r.sortorder from term t, concept c, relation r where facttablename=3D'facttable_kon_eh' and columnname=3D'arbeitsvol= umen' and exists (select 1 from facttable_kon_eh f where f.arbeitsvolumen= =3Dt.term and thema in (values (E'E'))) and c.id=3Dconcept_id and r.child=3Dconcept_id; =E2=95=94=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=97 =E2=95=91 = QUERY PLAN = =E2=95=91 =E2=95=9F=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=95=A2 =E2=95=91 Nested Loop (cost=3D22984.13..241822.98 rows=3D1 width=3D169) (a= ctual time=3D667.608..3275.037 rows=3D6 loops=3D1) = =E2= =95=91 =E2=95=91 -> Nested Loop (cost=3D22983.70..241822.50 rows=3D1 width=3D1= 54) (actual time=3D667.587..3274.972 rows=3D6 loops=3D1) = =E2= =95=91 =E2=95=91 -> Merge Semi Join (cost=3D22983.27..241819.04 rows=3D1= width=3D87) (actual time=3D667.559..3274.877 rows=3D6 loops=3D1) = =E2= =95=91 =E2=95=91 Merge Cond: ((t.term)::text =3D (f.arbeitsvolumen):= :text) = =E2=95=91 =E2=95=91 -> Index Scan using term_term_idx on term t (cost= =3D0.56..206841.09 rows=3D18 width=3D87) (actual time=3D667.467..2929.430 r= ows=3D7 loops=3D1) =E2= =95=91 =E2=95=91 Filter: (((facttablename)::text =3D 'facttabl= e_kon_eh'::text) AND ((columnname)::text =3D 'arbeitsvolumen'::text)) = =E2=95=91 =E2=95=91 Rows Removed by Filter: 3874190 = = =E2=95=91 =E2=95=91 -> Materialize (cost=3D0.43..399167.10 rows=3D354= 8798 width=3D7) (actual time=3D0.086..295.708 rows=3D184791 loops=3D1) = =E2= =95=91 =E2=95=91 -> Nested Loop Semi Join (cost=3D0.43..3902= 95.10 rows=3D3548798 width=3D7) (actual time=3D0.076..278.006 rows=3D184791= loops=3D1) =E2= =95=91 =E2=95=91 Join Filter: ((f.thema)::text =3D ('E':= :text)) = =E2=95=91 =E2=95=91 -> Index Scan using facttable_kon_eh_a= rbeitsvolumen_idx on facttable_kon_eh f (cost=3D0.43..337063.11 rows=3D354= 8798 width=3D9) (actual time=3D0.052..199.733 rows=3D184791 loops=3D1) =E2= =95=91 =E2=95=91 -> Materialize (cost=3D0.00..0.03 row= s=3D1 width=3D32) (actual time=3D0.000..0.000 rows=3D1 loops=3D184791) = =E2= =95=91 =E2=95=91 -> Result (cost=3D0.00..0.01 ro= ws=3D1 width=3D0) (actual time=3D0.001..0.001 rows=3D1 loops=3D1) = =E2= =95=91 =E2=95=91 -> Index Scan using concept_pkey on concept c (cost=3D0= =2E43..3.45 rows=3D1 width=3D67) (actual time=3D0.011..0.012 rows=3D1 loops= =3D6) = =E2=95=91 =E2=95=91 Index Cond: (id =3D t.concept_id) = = =E2=95=91 =E2=95=91 -> Index Scan using relation_child_idx on relation r (cost=3D= 0.43..0.47 rows=3D1 width=3D19) (actual time=3D0.008..0.009 rows=3D1 loops= =3D6) =E2= =95=91 =E2=95=91 Index Cond: (child =3D c.id) = = =E2=95=91 =E2=95=91 Planning time: 15.624 ms = = =E2=95=91 =E2=95=91 Execution time: 3275.341 ms = = =E2=95=91 =E2=95=9A=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=9D That is almost certainly not ideal, but this is not my question. My question is what does that merge semi join actually do? In general a merge join needs two inputs sorted by the merge key. It walks both in parallel and joins matching lines. Correct? The first input is the index scan.=20 The second is the output of the materialize. Since we need only the column arbeitsvolumen this would be something like select arbeitsvolumen from facttable_kon_eh where thema=3D'E' order by arbeitsvolumen; So far so good. But there are a few things I don't understand: Where does Rows Removed by Filter: 3874190 come from? The number doesn't match any count I can come up with: It is a bit larger than the total number of rows where term is not null but smaller than the total number of rows where the filter doesn't match. And it is much larger than the number of rows I would expect if the merge stopped once there could not be a possible match any more. And does it really check the filter condition even for rows that don't satisfy the merge condition? Of course it makes sense from a modularization point of view, but that's a lot of random accesses, most of which are unneccessary. The materialize returns 184791 rows. This one I understand: There are 6 non-null distinct values of arbeitsvolumen in facttable_kon_eh, and each appears 36958 times. 36958 * 5 + 1 =3D 184791. So it stops once it reaches the largest value. Although now I'm wondering how it knows that this is the largest value without scanning to the end). hp - - _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | hjp@hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson --jpb2tqdiiphxqos5 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAln5ksQACgkQ8g5IURL+ KF009BAAh/5W7BhgazMm4KCj6d65Xy7bXXZwYY1sm22uovvYR5MnUKFkR/E6CMQc Ou5ROkJED682A/Batm9GVw7fUz2PbS2mujslFXVWF75C212WcM2AANwG4g+zc4Yh omR+enBMvmSuZhKxjg46YJR5Ofmb07MFuVrJYlqFX73/OotXLQ4ZF8hN6ygNSWO+ I2Z52h7dC21NFK9GG3dAQTEm5laz7B6z3LuL49kbQZQl4WCnJpqUu8uudivQH5vO 10pyDPbRp1Tzu5uJtUgxpzPJbH2VNArHGU5uAkWOV4jPs3JU3f0U+aNk1T0GTRok KqDrEqkOHk0PC1rqkV4agMZdd5KNeE0TMopJ9SVao4uTbmLEWi8Ej+1hW6JcbvDw LDCMuZZ3Cj1CGhe9p4eTnYSsDxBF7gLW5ZePSRcwzzvKjhA0UWTHx/PxcThwzgY0 N0pmMrwBo32K+G77zm00bLooAx13PIxMdJm/LpJ+Admcdps6UGnnoLc8VtObd25J XBAcHbV8YVc+L/myPeKRbRI0RGeQGaf1U0jeOkxuBNDm0XMjWYqKmbUJ6Y4+5Epx nwHKjryyDMVql15Gg0VuxQkBD0yS90Jiv0HiOD3VsRUI8WbI2p8OZioW/A7NzANt LuN/g+kEJWZT+rd5V4AXUIkRQLWdedtM7j5/SQyNBC9xssHhH/U= =ytPj -----END PGP SIGNATURE----- --jpb2tqdiiphxqos5--