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 1jxJyw-0001bI-Fd for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Jul 2020 00:48:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jxJyu-0007OG-4h for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Jul 2020 00:48:36 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jxJyt-0007O9-Ny for pgsql-hackers@lists.postgresql.org; Mon, 20 Jul 2020 00:48:35 +0000 Received: from mail-ed1-x543.google.com ([2a00:1450:4864:20::543]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jxJyq-0004l3-I8 for pgsql-hackers@postgresql.org; Mon, 20 Jul 2020 00:48:35 +0000 Received: by mail-ed1-x543.google.com with SMTP id b15so11588260edy.7 for ; Sun, 19 Jul 2020 17:48:32 -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=ABglrw9y5BoKGP6aSqGRzsaHKQaJKF25pGjrQd0l+mU=; b=2J6tR+IR94ZeHrsoRFjGTvy7V3J054zmYylsd4Ale/GuDRJ54zt649wILHLXMtvL+u JxoRZC9CczHy/saXzSt0ww40EjgftQIUVLRiqC/rDYKObNICrWNAcFUsOLcgsVudTs3F axq8U9MQlOKT2U4X0t0KaNbFSaqZ42oQ4c62qeh/+TqfwuN2aPwnDap4K2F7dOM3AIgh pt61WpLPw4j6vHfmOshrjO3nDZvpDcazITn43LiQEiFZfeDN1uURH9QeSnOC2LjMgJa6 u5LEIqCu9JGljjvH5knPXMKL6y5DNtm72xB09mS6doo6xVUYaG/0204Ha+pPL009zd5F EhfA== 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=ABglrw9y5BoKGP6aSqGRzsaHKQaJKF25pGjrQd0l+mU=; b=dM2U9AtFI3WPJJCGGuEXSOK9BNgi+BJsvLfT0pgxtDxKqGsr8Hor4z7JPJZ8qsrshF b+Uwvq+6//KXssC06DaWlZuMbxIsmC7JmYlhzMtIPTHx9oT8XHKG2NW5cLYOob+41e7V ueFuWFLiCNvHrq4bkYHUuTnbrAZGONll8AUi/K6oPJt+Ynseb5g4ta3Ic3AGXmgVcWQh oz2lsf1trRQ8PLUoiPOf8qafczXhL/6yFkegkrZs9Fbng0rsozgYB714nE8NwC3UsMF5 m6IOKdV2mL0+GA/b/dRlwkt33Y6k2VlPPUu8cVnkqQwRDgEwzdIRslatLeIGJOgeDqxU x0uQ== X-Gm-Message-State: AOAM531NwgbYGWozkzqYV3oTgBeNiIH9GzrT7kcoVEIBhbLCzUMdV+eH KBhQnSfoQv+1cIJrOIHCYRvxgw== X-Google-Smtp-Source: ABdhPJzA7/gMj8HI+PyaGH+CXqdpL1ZBCETjmHcaaEFpd8AIxFgC9bgOysZwkHSPmAfHIAvJj2hwzw== X-Received: by 2002:aa7:db53:: with SMTP id n19mr19627830edt.338.1595206111620; Sun, 19 Jul 2020 17:48:31 -0700 (PDT) Received: from localhost (ip-86-49-253-141.net.upcbroadband.cz. [86.49.253.141]) by smtp.gmail.com with ESMTPSA id p9sm13507446ejd.50.2020.07.19.17.48.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jul 2020 17:48:30 -0700 (PDT) Date: Mon, 20 Jul 2020 02:48:27 +0200 From: Tomas Vondra To: Jeff Davis Cc: Tom Lane , Peter Geoghegan , Alvaro Herrera , David Rowley , Stephen Frost , Andres Freund , Bruce Momjian , Robert Haas , Justin Pryzby , Melanie Plageman , "pgsql-hackers@postgresql.org" Subject: Re: Default setting for enable_hashagg_disk Message-ID: <20200720004827.4c46ikcdrfum6xyu@development> References: <5cf74833a830e76cc7cc7506aa77bd6ab0c94f4c.camel@j-davis.com> <20200713164736.GA25726@alvherre.pgsql> <9e4a4cffe3eee0543e5b94c90821d39e03b81d29.camel@j-davis.com> <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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <88c0af01ad9ac105e424768808a214d855e29a77.camel@j-davis.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sun, Jul 19, 2020 at 02:17:15PM -0700, Jeff Davis wrote: >On Sat, 2020-07-18 at 21:15 -0400, Tom Lane wrote: >> Jeff Davis writes: >> > What is your opinion about pessimizing the HashAgg disk costs (not >> > affecting HashAgg plans expected to stay in memory)? Tomas Vondra >> > presented some evidence that Sort had some better IO patterns in >> > some >> > cases that weren't easily reflected in a principled way in the cost >> > model. >> >> Hm, was that in some other thread? I didn't find any such info >> in a quick look through this one. > > >https://www.postgresql.org/message-id/2df2e0728d48f498b9d6954b5f9080a34535c385.camel%40j-davis.com > FWIW the two messages to look at are these two: 1) report with initial data https://www.postgresql.org/message-id/20200519151202.u2p2gpiawoaznsv2%40development 2) updated stats, with the block pre-allocation and tlist projection https://www.postgresql.org/message-id/20200521001255.kfaihp3afv6vy6uq%40development But I'm not convinced we actually need to tweak the costing - we've ended up fixing two things, and I think a lot of the differences in I/O patterns disappeared thanks to this. For sort, the stats of request sizes look like this: type | bytes | count | pct ------+---------+-------+------- RA | 131072 | 26034 | 59.92 RA | 16384 | 6160 | 14.18 RA | 8192 | 3636 | 8.37 RA | 32768 | 3406 | 7.84 RA | 65536 | 3270 | 7.53 RA | 24576 | 361 | 0.83 ... W | 1310720 | 8070 | 34.26 W | 262144 | 1213 | 5.15 W | 524288 | 1056 | 4.48 W | 1056768 | 689 | 2.93 W | 786432 | 292 | 1.24 W | 802816 | 199 | 0.84 ... And for the hashagg, it looks like this: type | bytes | count | pct ------+---------+--------+-------- RA | 131072 | 200816 | 70.93 RA | 8192 | 23640 | 8.35 RA | 16384 | 19324 | 6.83 RA | 32768 | 19279 | 6.81 RA | 65536 | 19273 | 6.81 ... W | 1310720 | 18000 | 65.91 W | 524288 | 2074 | 7.59 W | 1048576 | 660 | 2.42 W | 8192 | 409 | 1.50 W | 786432 | 354 | 1.30 ... so it's actually a tad better than sort, because larger proportion of both reads and writes is in larger chunks (reads 128kB, writes 1280kB). I think the device had default read-ahead setting, which I assume explains the 128kB. For the statistics of deltas between requests - for sort type | block_delta | count | pct ------+-------------+-------+------- RA | 256 | 13432 | 30.91 RA | 16 | 3291 | 7.57 RA | 32 | 3272 | 7.53 RA | 64 | 3266 | 7.52 RA | 128 | 2877 | 6.62 RA | 1808 | 1278 | 2.94 RA | -2320 | 483 | 1.11 RA | 28928 | 386 | 0.89 ... W | 2560 | 7856 | 33.35 W | 2064 | 4921 | 20.89 W | 2080 | 586 | 2.49 W | 30960 | 300 | 1.27 W | 2160 | 253 | 1.07 W | 1024 | 248 | 1.05 ... and for hashagg: type | block_delta | count | pct ------+-------------+--------+------- RA | 256 | 180955 | 63.91 RA | 32 | 19274 | 6.81 RA | 64 | 19273 | 6.81 RA | 128 | 19264 | 6.80 RA | 16 | 19203 | 6.78 RA | 30480 | 9835 | 3.47 At first this might look worse than sort, but 256 sectors matches the 128kB from the request size stats, and it's good match (64% vs. 70%). There's a minor problem here, though - these stats were collected before we fixed the tlist issue, so hashagg was spilling about 10x the amount of data compared to sort+groupagg. So maybe that's the first thing we should do, before contemplating changes to the costing - collecting fresh data. I can do that, if needed. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services