Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1aeUgD-0000EP-Ky for pgsql-hackers@arkaria.postgresql.org; Fri, 11 Mar 2016 21:33:05 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aeUgD-0003S4-5d for pgsql-hackers@arkaria.postgresql.org; Fri, 11 Mar 2016 21:33:05 +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) (envelope-from ) id 1aeUgB-0003J7-It for pgsql-hackers@postgresql.org; Fri, 11 Mar 2016 21:33:03 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aeUg8-0003m7-QU for pgsql-hackers@postgresql.org; Fri, 11 Mar 2016 21:33:02 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u2BLWwxx013654; Fri, 11 Mar 2016 16:32:58 -0500 From: Tom Lane To: David Rowley cc: Tomas Vondra , Simon Riggs , PostgreSQL-development Subject: Re: Performance improvement for joins where outer side is unique In-reply-to: References: <20150320.121140.148610378.horiguchi.kyotaro@lab.ntt.co.jp> <27152324.eFKJb4Khb5@dinodell> <8608754a32d1325c2f83ba8b1df71585@xs4all.nl> <55DA1F9F.5040204@2ndquadrant.com> <5085.1440375543@sss.pgh.pa.us> <8907.1440383377@sss.pgh.pa.us> <56718B15.6060507@2ndquadrant.com> <5671FF0D.2010403@2ndquadrant.com> <56A25A72.2090505@2ndquadrant.com> <24304.1457482780@sss.pgh.pa.us> Comments: In-reply-to David Rowley message dated "Wed, 09 Mar 2016 13:38:52 +1300" Date: Fri, 11 Mar 2016 16:32:58 -0500 Message-ID: <13653.1457731978@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org So I started re-reading this thread in preparation for looking at the patch, and this bit in your initial message jumped out at me: > In all of our join algorithms in the executor, if the join type is SEMI, > we skip to the next outer row once we find a matching inner row. This is > because we don't want to allow duplicate rows in the inner side to > duplicate outer rows in the result set. Obviously this is required per SQL > spec. I believe we can also skip to the next outer row in this case when > we've managed to prove that no other row can possibly exist that matches > the current outer row, due to a unique index or group by/distinct clause > (for subqueries). I wondered why, instead of inventing an extra semantics-modifying flag, we couldn't just change the jointype to *be* JOIN_SEMI when we've discovered that the inner side is unique. Now of course this only works if the join type was INNER to start with. If it was a LEFT join, you'd need an "outer semi join" jointype which we haven't got at the moment. But I wonder whether inventing that jointype wouldn't let us arrive at a less messy handling of things in the executor and EXPLAIN. I'm not very enamored of plastering this "match_first_tuple_only" flag on every join, in part because it doesn't appear to have sensible semantics for other jointypes such as JOIN_RIGHT. And I'd really be happier to see the information reflected by join type than a new line in EXPLAIN, also. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers