Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dlGeP-0002d0-0F for pgsql-performance@arkaria.postgresql.org; Fri, 25 Aug 2017 15:36:01 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dlGeN-0002F6-BC for pgsql-performance@arkaria.postgresql.org; Fri, 25 Aug 2017 15:35:59 +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 1dlGcb-0007UF-Hk for pgsql-performance@postgresql.org; Fri, 25 Aug 2017 15:34:09 +0000 Received: from mail-wm0-x22d.google.com ([2a00:1450:400c:c09::22d]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1dlGcT-000710-IA for pgsql-performance@postgresql.org; Fri, 25 Aug 2017 15:34:08 +0000 Received: by mail-wm0-x22d.google.com with SMTP id b189so1261347wmd.0 for ; Fri, 25 Aug 2017 08:34:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=euE5YEl0fG+c7xZ6xsMSknM2ToDLTaYcZjig/A5PMSw=; b=t7BQ/MUZDQJkUQbfbWYYCKtc4Wxh17GZAVMem6peVuzIMkl5fi/q7iY7djwmla3xV8 OIXu2uvL09loUHJGr/MEWmbbFgePyAIvkJw/m6VNuah11ViM2teWsiJHOQoOQkpx8FaO HIjtLrw/NaspxtqITlcwhj2XnNOucGUxT4tUZXoHlncbUByG8vVFrF3hgNbVCAvb48fJ g172Ce97HuImphDK5NLWIDA2PZugfKWwuVBEez1P242WgqTaD89RQsZT0g6nvBqcMuyO NCDJaGOqefJGMZcL+fa2EVXqjYMHmiyL6fwsncU4m9gDom1nT1uSTtfKxPbKVLwPrr5x 9bag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=euE5YEl0fG+c7xZ6xsMSknM2ToDLTaYcZjig/A5PMSw=; b=qi0/PTf+HFqpK7tcX+pEd30z46I9JXAGIKZlWhPhD9M2M5NMifz3Qg493CA1vCvF4j VvW9VfKQMoke9byrzD3B1j2fEbECgYSPbWsi5Ff/4wlKyGyHySZ5ELgrJkPeSGhIBHhx A8qMR0WdxP1pVOqA8+eQFZNie4K2aZ2ulz6zAXal+TK826lU1uL1HUwibvdIP1/62Pw9 04/XWruj1bjJHEjI7DVX4qeVXrlPv3ZJcD76AcPk5ygiaI8BRPhy9LNRF6ZRNeKx8+Oq bT+PobhoPiaepJMfDXtIOwTY0ZvvGNlqkR7BOg+A5LlakahwYMwXJrFAXThJSjM1L26E jq8A== X-Gm-Message-State: AHYfb5g3rVycGRexqTIOYfym2LgPP7wTUWBpk1fLT1Mk4UH/7n7JzSCH WlBLcG9GoEf14cjI7w7ajms2k8mFoTERAFm/4gDPBjMl4LwhH6C5LaKpO2gycDj6jlI7JZq0mA8 dNdq/RPGWSp8sVrVE6thh35Gi23SI3nuWzhIJsI26w5QCTavPDg1b8w25/ivZEJSgmTXaDEYFf/ Tr0/Dq X-Received: by 10.28.8.140 with SMTP id 134mr1670607wmi.108.1503675239232; Fri, 25 Aug 2017 08:33:59 -0700 (PDT) Received: from [10.137.2.17] (ip-78-102-97-226.net.upcbroadband.cz. [78.102.97.226]) by smtp.gmail.com with ESMTPSA id q45sm14424623wrb.3.2017.08.25.08.33.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Aug 2017 08:33:58 -0700 (PDT) Subject: Re: Execution plan analysis To: Neto pr , pgsql-performance@postgresql.org References: From: Tomas Vondra Message-ID: <9fdf19f5-a49f-2d85-1e9e-a3cdb335eb80@2ndquadrant.com> Date: Fri, 25 Aug 2017 17:33:54 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit 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 Hi, So looking at the plans, essentially the only part that is different is the scan node at the very bottom - in one case it's a sequential scan, in the other case (the slow one) it's the bitmap index scan. Essentially it's this: -> Seq Scan on lineitem (cost=0.00..2624738.17 ...) (actual time=0.839..74391.087 ...) vs. this: -> Bitmap Heap Scan on lineitem (cost=336295.10..1970056.39 ...) (actual time=419620.817..509685.421 ...) -> Bitmap Index Scan on idx_l_shipmodelineitem000 (cost=0.00..336227.49 ...) (actual time=419437.172..419437.172 ...) All the nodes are the same and perform about the same in both cases, so you can ignore them. This difference it the the root cause you need to investigate. The question is why is the sequential scan so much faster than bitmap index scan? Ideally, the bitmap heap scan should scan the index (in a mostly sequential way), build a bitmap, and then read just the matching part of the table (sequentially, by skipping some of the pages). Now, there are a few reasons why this might not work that well. Perhaps the table fits into RAM, but table + index does not. That would make the sequential scan much faster than the index path. Not sure if this is the case, as you haven't mentioned which TPC-H scale are you testing, but you only have 4GB of RAM which if fairly low. Another bit is prefetching - with sequential scans, the OS is able to prefetch the next bit of data automatically (read-ahead). With bitmap index scans that's not the case, producing a lot of individual synchronous I/O requests. See if increasing effective_cache_size (from default 1 to 16 or 32) helps. Try generating the plans with EXPLAIN (ANALYZE, BUFFERS), that should tell us more about how many blocks are found in shared buffers, etc. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance