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 1jds1p-0004Db-ET for pgsql-hackers@arkaria.postgresql.org; Wed, 27 May 2020 09:07:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jds1o-0004l3-4E for pgsql-hackers@arkaria.postgresql.org; Wed, 27 May 2020 09:07:12 +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 1jds1n-0004kw-OD for pgsql-hackers@lists.postgresql.org; Wed, 27 May 2020 09:07:11 +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 1jds1l-0005xU-5H for pgsql-hackers@postgresql.org; Wed, 27 May 2020 09:07:10 +0000 Received: by mail-ej1-x643.google.com with SMTP id x1so27125102ejd.8 for ; Wed, 27 May 2020 02:07:08 -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=WWT/qW27iggQZm0Fjh6PxkCMRRUaLKtRkFtcoX+yRug=; b=sQ2AX8BzYYs9tL4dqTZgP3uL7CqUL/qPtnX5FVqmOPkgEXswB/vg2TwucpQ3wAUcoM vKYMbw9bCPkNj4GpKNSXME46547SYGkV6ZnDviDL4FMOvM38a6Pkd87Lc8ffQ24bYU/W UEzoV6bKFg95CHw62Bk1qrhCtETfp/SrftQE92crV2hnrppN1V57sBsISFM4EZBQ3iYh htHSvgQEoNg30DI80+SVw7WIs5suurry6AIMEh+qKC7aPpYEXFdqtC8UwRB6+UsHGdc8 kotmnqCojDHTJmhLHdRl6vl6gQ9wUxju/TeHb12ctcylfxlc9QZU0e3wVKdYnLAPi9LZ v0RQ== 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=WWT/qW27iggQZm0Fjh6PxkCMRRUaLKtRkFtcoX+yRug=; b=WGWVpu7URpwsCJU551G+1xcJp+Gt/jbhosCGiVsw+ztRAcbggc1vdI/aFNoc2iA63a ZNbENO1Zs+RdAuEj5z5XQafKCTUq52GGBQ5Mdn1FHQeLC7EMeNaRULQJMCtLu6t2eQwf iXlYjvmBZ/f/tarHiPmaLlkCWHxK72rUePasclEN42w0VYiZZDIm2cQryAg/cmSY+ZCK 65y+MzOa7TZulIcHGvHBAa4j8OhpCuGaJdukAJ77H1A7hXMB4pCTrvHvgu6ARUXrUahm ihm+Q1DKhjhSfrMcPnmBHMVok9O6BlKBHDeIhwdyniYoI7aCaAfWrnqd3VMHzeBWzdW7 U7lw== X-Gm-Message-State: AOAM530vKvIyxyKJl+l6yhH31TmywFxYwtglLqZCIqWL52c6PzAyxlZ6 oga8jAtI8TvoCcU/JFoY/13Ccw== X-Google-Smtp-Source: ABdhPJwQav5G9uQ3Gl1eg1D+uQRxbzQIujsG5e0EapphphNdkwCrbRUJiTvLIeHebVQqiO/O8LayNA== X-Received: by 2002:a17:906:6d5a:: with SMTP id a26mr5240367ejt.410.1590570427543; Wed, 27 May 2020 02:07:07 -0700 (PDT) Received: from localhost (ip-86-49-253-141.net.upcbroadband.cz. [86.49.253.141]) by smtp.gmail.com with ESMTPSA id on20sm2100706ejb.70.2020.05.27.02.07.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2020 02:07:06 -0700 (PDT) Date: Wed, 27 May 2020 11:07:04 +0200 From: Tomas Vondra To: Melanie Plageman Cc: Jeff Davis , Thomas Munro , pgsql-hackers , HeikkiLinnakangas Subject: Re: Trouble with hashagg spill I/O pattern and costing Message-ID: <20200527090704.onkjogxeg34ib5cn@development> References: <20200525021045.dilgcsmgiu4l5jpa@development> <20200525121722.6wzcelweefyuwg54@development> <2df2e0728d48f498b9d6954b5f9080a34535c385.camel@j-davis.com> <20200525225909.aifxjm53hw4xyzxd@development> <20200526141524.ohtvrp23vxosgivl@development> <20200526191511.d7pwz4awrvdm4p6j@development> <0589f869969de2f3e9713689159c7c4fbe1fcfa5.camel@j-davis.com> 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 Tue, May 26, 2020 at 06:42:50PM -0700, Melanie Plageman wrote: >On Tue, May 26, 2020 at 5:40 PM Jeff Davis wrote: > >> On Tue, 2020-05-26 at 21:15 +0200, Tomas Vondra wrote: >> > >> > As for the tlist fix, I think that's mostly ready too - the one thing >> > we >> > should do is probably only doing it for AGG_HASHED. For AGG_SORTED >> > it's >> > not really necessary. >> >> Melanie previously posted a patch to avoid spilling unneeded columns, >> but it introduced more code: >> >> >> >> https://www.postgresql.org/message-id/CAAKRu_aefEsv+UkQWqu+ioEnoiL2LJu9Diuh9BR8MbyXuZ0j4A@mail.gmail.com >> >> and it seems that Heikki also looked at it. Perhaps we should get an >> acknowledgement from one of them that your one-line change is the right >> approach? >> >> >I spent some time looking at it today, and, it turns out I was wrong. > >I thought that there was a case I had found where CP_SMALL_TLIST did not >eliminate as many columns as could be eliminated for the purposes of >spilling, but, that turned out not to be the case. > >I changed CP_LABEL_TLIST to CP_SMALL_TLIST in >create_groupingsets_plan(), create_agg_plan(), etc and tried a bunch of >different queries and this 2-3 line change worked for all the cases I >tried. Is that where you made the change? I've only made the change in create_agg_plan, because that's what was in the query plan I was investigating. You may be right that the same fix is needed in additional places, though. >And then are you proposing to set it based on the aggstrategy to either >CP_LABEL_TLIST or CP_SMALL_TLIST here? > Yes, something like that. The patch I shared on on 5/21 just changed that, but I'm wondering if that could add overhead for sorted aggregation, which already does the projection thanks to the sort. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services