Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YYfuu-00060L-CA for pgsql-performance@arkaria.postgresql.org; Thu, 19 Mar 2015 19:15:40 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YYfut-0003Uq-Ji for pgsql-performance@arkaria.postgresql.org; Thu, 19 Mar 2015 19:15:39 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YYfus-0003UZ-H4 for pgsql-performance@postgresql.org; Thu, 19 Mar 2015 19:15:38 +0000 Received: from mwork.nabble.com ([162.253.133.43]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YYfuo-0003Mx-Vz for pgsql-performance@postgresql.org; Thu, 19 Mar 2015 19:15:36 +0000 Received: from msam.nabble.com (unknown [162.253.133.85]) by mwork.nabble.com (Postfix) with ESMTP id 8E72717E8014 for ; Thu, 19 Mar 2015 12:15:46 -0700 (PDT) Date: Thu, 19 Mar 2015 12:15:33 -0700 (MST) From: Jake Magner To: pgsql-performance@postgresql.org Message-ID: <1426792533879-5842633.post@n5.nabble.com> In-Reply-To: <1426783249710-5842603.post@n5.nabble.com> References: <1426746214298-5842523.post@n5.nabble.com> <30571.1426775332@sss.pgh.pa.us> <1426783249710-5842603.post@n5.nabble.com> Subject: Re: Merge Join chooses very slow index scan MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -0.1 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org I think I understand now after reading the notes here on the merge join algorithm: https://github.com/postgres/postgres/blob/4ea51cdfe85ceef8afabceb03c446574daa0ac23/src/backend/executor/nodeMergejoin.c The index scanning node doesn't know the max id of the vehicle table and so can't know when to stop looking for the next tuple that matches the join. Doesn't seem like any easy way to improve that case. I imagine it is a fairly common pattern though. Any time metadata about entities modeled in different tables, is stored in the same table, and the distribution of the number of each entity type is skewed, this situation will arise. Best, Jake -- View this message in context: http://postgresql.nabble.com/Merge-Join-chooses-very-slow-index-scan-tp5842523p5842633.html Sent from the PostgreSQL - performance mailing list archive at Nabble.com. -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance