Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jz091-0003X9-Tm for pgsql-hackers@arkaria.postgresql.org; Fri, 24 Jul 2020 16:02:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jz090-0007lc-95 for pgsql-hackers@arkaria.postgresql.org; Fri, 24 Jul 2020 16:01:58 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jz08z-0007lU-SW for pgsql-hackers@lists.postgresql.org; Fri, 24 Jul 2020 16:01:58 +0000 Received: from mail-ej1-x643.google.com ([2a00:1450:4864:20::643]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jz08x-0001Zd-De for pgsql-hackers@postgresql.org; Fri, 24 Jul 2020 16:01:56 +0000 Received: by mail-ej1-x643.google.com with SMTP id w9so10472568ejc.8 for ; Fri, 24 Jul 2020 09:01:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=TXF29or923qWdTJclSglSjr9NlNerBHHZ/Vx6cV/HQY=; b=N/l4NuB8tmOb0srdzJssL+PU0wVjIK6RKTOxpSZsMRhgeSHl79ldrYxQJsFdnzUXQL T0b7p5T/ShVMtGjaQJL1MGj+sWlDs9nuUmO0MOCcv9y2eot5d3k/JPSg3xfPoTFr73f2 sLa8ZA72EfjwAyCyB9KwyLSYXwrZHVTIHRp75ad+YEfdhtnyrEJdfG0iCni3gC4cBX8Z Hy3wJZ6/UK5CqQSxIpYKfvKWCE3c89LBCh/lfGEP6IF7RBSbFYmDOCNJk+VCvrZbOkY1 BZgdzusVvB3OC40DuCXYQva0Cq8RnZAiGs6ETRCzidUEasBAhCGaiFJ4AYJNWETWO7G5 oyxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=TXF29or923qWdTJclSglSjr9NlNerBHHZ/Vx6cV/HQY=; b=t/F317QA9GV6kvyWKki2cVdokxPM9mYtLbdwwuoutDDTqfMY4KKoef1jROa6VuxILq 8ZcNNbrOHbb2m+UIwcgLg5lISm36bo1GcHtkYVVzgEDS8gzLluwaTXw69vc684+Oyljt CBhdfpQ+EnwHsn5R9xv04nWN3OZN8Si0z0qJqc/K0lqaPADLl4zM1tosTT6nhQspipUi 6ucpgc7vFC2BnnZEIw2JPPsMeDZEKcfmCvh+7moABlqgmNNyWFhEbsBYLedLAfjkPHc5 9Wi7WjtztpOs/nKdlIndk3geSjCBZg4jE1yDYtAOnD2EvjSK3zb3wj8ySUWhkULVEGvn zF9A== X-Gm-Message-State: AOAM530hlYTZJBbjM3t3T7lTMw/O1RBGUcW/wGSa44VnA7/1FnHDsnNb 2kHfd1h3BpsgB0twn34oA332Cg== X-Google-Smtp-Source: ABdhPJy5L469WiFSVEuOJ3utGNAar3I2wrNxOw7etweAEkPdQ9Trb+DbG/ph5U12qD9VVtqcFzvcqQ== X-Received: by 2002:a17:906:414c:: with SMTP id l12mr10144893ejk.417.1595606514157; Fri, 24 Jul 2020 09:01:54 -0700 (PDT) Received: from localhost (ip-86-49-253-141.net.upcbroadband.cz. [86.49.253.141]) by smtp.gmail.com with ESMTPSA id a5sm1005486eda.35.2020.07.24.09.01.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jul 2020 09:01:51 -0700 (PDT) Date: Fri, 24 Jul 2020 18:01:47 +0200 From: Tomas Vondra To: Robert Haas Cc: Tom Lane , Jeff Davis , Peter Geoghegan , Alvaro Herrera , David Rowley , Stephen Frost , Andres Freund , Bruce Momjian , Justin Pryzby , Melanie Plageman , "pgsql-hackers@postgresql.org" Subject: Re: Default setting for enable_hashagg_disk Message-ID: <20200724160147.l673k4yflz7flkh5@development> References: <6d0aba397625df79bdc3ca85adc11b9e48ecb0da.camel@j-davis.com> <4118680.1595097043@sss.pgh.pa.us> <571473265c5d5309f4012855ebd2131c136073ab.camel@j-davis.com> <32871.1595121333@sss.pgh.pa.us> <88c0af01ad9ac105e424768808a214d855e29a77.camel@j-davis.com> <20200720004827.4c46ikcdrfum6xyu@development> <400617.1595251041@sss.pgh.pa.us> <20200720172539.6jov6ynljly4wj6i@development> <20200724012248.y77rpqc73agrsvb3@development> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, Jul 24, 2020 at 11:18:48AM -0400, Robert Haas wrote: >On Thu, Jul 23, 2020 at 9:22 PM Tomas Vondra > wrote: >> 2MB 4MB 8MB 64MB 256MB >> ----------------------------------------------------------- >> hash 6.71 6.70 6.73 6.44 5.81 >> hash CP_SMALL_TLIST 5.28 5.26 5.24 5.04 4.54 >> sort 3.41 3.41 3.41 3.57 3.45 >> >> So sort writes ~3.4GB of data, give or take. But hashagg/master writes >> almost 6-7GB of data, i.e. almost twice as much. Meanwhile, with the >> original CP_SMALL_TLIST we'd write "only" ~5GB of data. That's still >> much more than the 3.4GB of data written by sort (which has to spill >> everything, while hashagg only spills rows not covered by the groups >> that fit into work_mem). >> >> I initially assumed this is due to writing the hash value to the tapes, >> and the rows are fairly narrow (only about 40B per row), so a 4B hash >> could make a difference - but certainly not this much. Moreover, that >> does not explain the difference between master and the now-reverted >> CP_SMALL_TLIST, I think. > >This is all really good analysis, I think, but this seems like the key >finding. It seems like we don't really understand what's actually >getting written. Whether we use hash or sort doesn't seem like it >should have this kind of impact on how much data gets written, and >whether we use CP_SMALL_TLIST or project when needed doesn't seem like >it should matter like this either. > I think for CP_SMALL_TLIST at least some of the extra data can be attributed to writing the hash value along with the tuple, which sort obviously does not do. With the 32GB data set (the i5 machine), there are ~20M rows in the lineitem table, and with 4B hash values that's about 732MB of extra data. That's about the 50% of the difference between sort and CP_SMALL_TLIST, and I'd dare to speculate the other 50% is due to LogicalTape internals (pointers to the next block, etc.) The question is why master has 2x the overhead of CP_SMALL_TLIST, if it's meant to write the same set of columns etc. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services