Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eK8aK-0003yw-Mw for pgsql-general@arkaria.postgresql.org; Wed, 29 Nov 2017 20:03:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eK8aJ-0007nE-UD for pgsql-general@arkaria.postgresql.org; Wed, 29 Nov 2017 20:03:55 +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 1eK8aJ-0007n3-Jk for pgsql-general@lists.postgresql.org; Wed, 29 Nov 2017 20:03:55 +0000 Received: from mx1.mailbox.org ([80.241.60.212]) by makus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eK8aC-0003fH-GY for pgsql-general@postgresql.org; Wed, 29 Nov 2017 20:03:54 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.mailbox.org (Postfix) with ESMTPS id 5BD20470C4; Wed, 29 Nov 2017 21:03:44 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter01.heinlein-hosting.de (spamfilter01.heinlein-hosting.de [80.241.56.115]) (amavisd-new, port 10030) with ESMTP id JPUkUSOm9rJl; Wed, 29 Nov 2017 21:03:42 +0100 (CET) Message-ID: <1511985820.6899.5.camel@cybertec.at> Subject: Re: seq vs index scan in join query From: Laurenz Albe To: Andres Freund Cc: Emanuel Alvarez , pgsql-general@postgresql.org Date: Wed, 29 Nov 2017 21:03:40 +0100 In-Reply-To: <20171129174640.o7q2ge4f3lk25cmo@alap3.anarazel.de> References: <1511975838.2309.12.camel@cybertec.at> <20171129174640.o7q2ge4f3lk25cmo@alap3.anarazel.de> Organization: Cybertec Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Andres Freund wrote: > On 2017-11-29 18:17:18 +0100, Laurenz Albe wrote: > > That is because the execution with the sequential scan touched > > 26492 + 80492 = 106984 blocks, while the second execution touched > > 311301 + 48510 = 359811 blocks, more than three times as many. > > That's not necessarily said. What those count are buffer *accesses*, > *not* the number of distinct blocks accessed. You'll very commonly have > more buffer accesses in indexscans but still fewer total reads because a > lot of those accesses will be reads previously done in the same > scan. Just imagine a scan of an index with a leaf page pointing to 100 > tuples of the same value - that'd result in at least a 100 buffer > accesses, but it'd be highly likely that they'll be in cache. Thanks for explaining that. Yours, Laurenz Albe