Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eK6Re-0003iG-Gw for pgsql-general@arkaria.postgresql.org; Wed, 29 Nov 2017 17:46:50 +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 1eK6Rd-0006R6-Pr for pgsql-general@arkaria.postgresql.org; Wed, 29 Nov 2017 17:46:49 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eK6Rd-0006Qw-IR for pgsql-general@lists.postgresql.org; Wed, 29 Nov 2017 17:46:49 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eK6RX-0007CP-1I for pgsql-general@postgresql.org; Wed, 29 Nov 2017 17:46:49 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id DD97C200FE; Wed, 29 Nov 2017 12:46:41 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute5.internal (MEProxy); Wed, 29 Nov 2017 12:46:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=8fFlUywUIRu6W/cbngsXV7QMvqnE0 ZYpud9l/teNBoo=; b=Iqe5edxarjT86Uf9A6Z0FE3vIthcFToYQsYrh92TFPbGJ zlO04t+oFUXBb54MIhhfa4f7ttBhbg3Wjao/hQpjLs0mGqiuKzx5zALJOPLubPo5 k/xIPrEj9XLV+0Mevd+/t8RuoD1tIgBjmM4OdviWBfumGaF+64EB4VHqVbqTtMp1 ugWfxdE5GrFUoSqmD9Dnx32GX1o/WdkYogoL2UKjPLlF0bxZM+SVtQEdAGlLI2DI BCrkdWtE9iGscyv+URPXlRuTbLUgnjGU8/g+MQwWVUAxb/UQHG/TURs2VmAsdLpE OviqnArPirLHdXr0jnLJtxc49gSDJb6G6LyTzk/kQ== X-ME-Sender: Received: from intern.anarazel.de (unknown [136.24.76.189]) by mail.messagingengine.com (Postfix) with ESMTPA id 95410249FA; Wed, 29 Nov 2017 12:46:41 -0500 (EST) Date: Wed, 29 Nov 2017 09:46:40 -0800 From: Andres Freund To: Laurenz Albe Cc: Emanuel Alvarez , pgsql-general@postgresql.org Subject: Re: seq vs index scan in join query Message-ID: <20171129174640.o7q2ge4f3lk25cmo@alap3.anarazel.de> References: <1511975838.2309.12.camel@cybertec.at> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1511975838.2309.12.camel@cybertec.at> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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. Greetings, Andres Freund