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 1jZNeR-0006va-6A for pgsql-hackers@arkaria.postgresql.org; Thu, 14 May 2020 23:52:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jZNeP-0004bv-AC for pgsql-hackers@arkaria.postgresql.org; Thu, 14 May 2020 23:52:29 +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 1jZNeO-0004bg-W6 for pgsql-hackers@lists.postgresql.org; Thu, 14 May 2020 23:52:29 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jZNeL-0004qD-Hp for pgsql-hackers@lists.postgresql.org; Thu, 14 May 2020 23:52:28 +0000 Received: by mail-wr1-x441.google.com with SMTP id 50so1145289wrc.11 for ; Thu, 14 May 2020 16:52:25 -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=N0PHkSPOHzYvDWL72vKKZEwPCHhogS7XnJLNrE6j1Qg=; b=cbmo8faoLATuRpa4hwJ3sgSR12XxcDe3W9/ohZIGSIR2SCn5klRZMfel1DSh1Aw82c BU3BZb9yqazDbFfujkh5Jhsk5L4BVwWHyzIJwPeenJi+uaQ1ME+CvOgZpsSwhzd+AXIp uC/QVvBqVNMZ8Qt8I6uadpNmVlgbEEYREqFpcoMBREz21SsUYq/Zh4Gth4APT6I/qX3/ BGj5XLDWxoRYXIkk5BhKzuRPY5y5/MPHrCoSfjXFMkwJc2tDcbRY8mxQ8RM/IzgKX/4n aVmCTlNicFFUxk7BYJWokuqehGYoIrW2zYnr7SUn5Krb+gpjmmcF6yomIBEeafKSFjno yFtg== 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=N0PHkSPOHzYvDWL72vKKZEwPCHhogS7XnJLNrE6j1Qg=; b=P4mg19G5TMtSQACBQXyEKGtO3RJ34TE30vSSyDVqvygGeHM2zSqHHrN756iiI13XMi iTbVJ0DJngAwSLNIiMFULp/sgfV2Sn2KVDJAXC+2iWywHZ2+ZvhOqxcXZVpysD9h2JU3 Zk0q9dkTelrixl51uHRf2t4Yer17oi6eglS5UzQVue4kdem06iXxturk6kA5Z3R3hIzP bpa9VFuaFThowcnKiavqcM3JgcawIWwmar1LKISIaD7/F5WBqmrLs+vPLBqfrwIjghAk CsYzwRQbMkOHhkBQyKs/fgp/5aaH+sdDt/fRLQltf2QH4VfC7lcNn2aGDQqzrEmsUtQ8 2RJw== X-Gm-Message-State: AOAM5334Pub54GXH1a05Z0kvfqFp+VlW0D5S86kDM1pxKo6Fm0cNiCYw 64UmCgCKKri8ubKvcPOVTlHMdw== X-Google-Smtp-Source: ABdhPJzjKTL7tRcmHV3LsJ+TAMpiRnAXHyuDOI8HzSEGTFWhiaYuv36AK08Cquzcu06LYY/gYfEpRg== X-Received: by 2002:a5d:6b90:: with SMTP id n16mr1057602wrx.220.1589500343801; Thu, 14 May 2020 16:52:23 -0700 (PDT) Received: from localhost (ip-86-49-253-141.net.upcbroadband.cz. [86.49.253.141]) by smtp.gmail.com with ESMTPSA id q5sm914326wra.36.2020.05.14.16.52.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 May 2020 16:52:22 -0700 (PDT) Date: Fri, 15 May 2020 01:52:20 +0200 From: Tomas Vondra To: Dmitry Dolgov <9erthalion6@gmail.com> Cc: Teodor Sigaev , Gavin Flower , Andres Freund , Michael Paquier , PostgreSQL Developers Subject: Re: POC: GROUP BY optimization Message-ID: <20200514235220.xewrrwjvatxzn3g6@development> References: <0b3ee377-2f67-f58d-6177-bc2ed4626499@archidevsys.co.nz> <20181002021626.GF11712@paquier.xyz> <20190131112407.zpbysdvghjyh4z47@alap3.anarazel.de> <20190409152100.5q25whnxs27zws5m@development> <20190503215510.bcr5ycszntqg65tw@development> <20190524225725.embuha33qvc5avz3@development> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20190524225725.embuha33qvc5avz3@development> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, I wonder if anyone has plans to try again with this optimization in v14 cycle? The patches no longer apply thanks to the incremental sort patch, but I suppose fixing that should not be extremely hard. The 2020-07 CF is still a couple weeks away, but it'd be good to know if there are any plans to revive this. I'm willing to spend some time on reviewing / testing this, etc. I've only quickly skimmed the old thread, but IIRC there were two main challenges in getting the optimization right: 1) deciding which orderings are interesting / worth additional work I think we need to consider these orderings, in addition to the one specified in GROUP BY: 1) as specified in ORDER BY (if different from 1) 2) one with cheapest sort on unsorted input (depending on number of distinct values, cost of comparisons, etc.) 3) one with cheapest sort on partially sorted input (essentially what we do with the incremental sort paths, but matching the pathkeys in a more elaborate way) 2) costing the alternative orderings I think we've already discussed various ways to leverage as much available info as possible (extended stats, MCVs, ...) but I think the patch only does some of it. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services