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 1lQxUz-0007lH-Rx for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Mar 2021 19:24:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lQxUy-0000Ds-Gg for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Mar 2021 19:24:28 +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 1lQxUy-0000Dk-4f for pgsql-hackers@lists.postgresql.org; Mon, 29 Mar 2021 19:24:28 +0000 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lQxUu-0004DR-RO for pgsql-hackers@postgresql.org; Mon, 29 Mar 2021 19:24:26 +0000 Received: by mail-ej1-x62a.google.com with SMTP id jy13so21222957ejc.2 for ; Mon, 29 Mar 2021 12:24:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=dTTYNzj/mDZXRSTu2BYqe20V5DdM0nyGlKnu2ZL5SjY=; b=EL3S1/nVdq425xEMugHkM1qBgGrrGprDOSp5dDVTJK0pSqMP6a908uHi8bN1rTnU4W OND93flBQrucCKCTrihRM/6jn7YMzcvK7ZEcoVkkfaHRwfugP6rxncCh7aUh/eST/N+6 Q1h8bFnUlBK0iL4zOAW9uY9LALRPhNtO80xuoVy44zMQPfgYOlAx7EO75hp/G9+s4MOf zn7+8KbWfNQKJBqAMDv2/NPgzW+hDIznHsdh2iVRvvY81dKF24/Qvp4Dcw2+H+kpolam /9l7QAF2bt7kk1GGSLvZftQt9PLd2oSv6b65mPGChtPG1iSBlIYOtuQChVajn7OuINu4 UElw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=dTTYNzj/mDZXRSTu2BYqe20V5DdM0nyGlKnu2ZL5SjY=; b=DwbGGzth+nO9FAcjOvphhxyB/FF32OlTcw4TMVwggCjP6zvpj/8V6CkU5OWucIM043 O69/EbuzyzmKRyCzyZINL2vow4jSkOB4B7tbM/M9xuivCV7RgYsjdwADLzTpLhgcf7j4 a4uumVbJeNYkmKgvjCDIVW6VXvTpqLWyr54OSBdQAAy4iagWP3cQ9pm6v+DNohtB/7Zf ZAs9FGXbDx03pEdy/9uby/ewM13FH6VUmlKXmcgtvs+KtbmbnM9uhZZ0MALzJe9DemRq 6oUjnBs1ppxJGHIpiU5l3uODaHJzma6HQWVmUzGOs2ymIlNFqYIedhRXU9eAxkUUNkHi RbPQ== X-Gm-Message-State: AOAM5336VHJIIb15AUo0yj0n46dMNsVCF9AbUbv5an8EFBiSYaShlAT8 TxyZkIGYK0atWiT6T8YrgastfmysPbZ5eeAmL0WiONSiyByswVYhxmnYMapPhk4/aJVkhfYMCu3 N9Jff7yNpjkHYtKcDBEsnnMBvgXZsjTAgp8n+7O1A/lUPnVFHcBIbty0KlBkQSqOmK9SZXz76Pl Q/LFMoWNUb1uy/Ju/MpupAxgA7kw6rnw6YfJ5Zt1Wm6eRpIzd61pG0kGHEXYwOBdeE2LgG1UrFC rod71ipyORydDxsRlWRz3jk4Yv8fTiGpgDS8w== X-Google-Smtp-Source: ABdhPJz8fuh9QtdYULPboRIH4uf8ELdVqHGMHkJHsPj3Z41C9golByQGxHsyvrVnoWD5ruXvINWVtA== X-Received: by 2002:a17:906:3b84:: with SMTP id u4mr29850023ejf.431.1617045862934; Mon, 29 Mar 2021 12:24:22 -0700 (PDT) Received: from [10.137.0.20] (ip-86-49-253-127.net.upcbroadband.cz. [86.49.253.127]) by smtp.gmail.com with ESMTPSA id q2sm8835136eje.24.2021.03.29.12.24.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 29 Mar 2021 12:24:22 -0700 (PDT) Subject: Re: Merging statistics from children instead of re-sampling everything To: Justin Pryzby Cc: pgsql-hackers@postgresql.org References: <20210329183624.GC4431@telsasoft.com> From: Tomas Vondra Message-ID: <0c3db54d-c06d-7fef-ad47-8aa4bd8485b2@enterprisedb.com> Date: Mon, 29 Mar 2021 21:24:19 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210329183624.GC4431@telsasoft.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 3/29/21 8:36 PM, Justin Pryzby wrote: > Thanks for taking a fresh look at this. > > As you've written it, this can apply to either/both partitioned or inheritence. > I imagine when "MERGE" goes away, this should apply only to partitioned tables. > (Actually, personally I would advocate to consider applying it to *both*, but I > don't think that's been the tendency over the last 4 years. I wrote here about > some arguably-gratuitous differences between inheritence and partitioning. > https://www.postgresql.org/message-id/20180601221428.GU5164@telsasoft.com) > Haven't thought about that too much at this point, but I don't see any reason to not apply it only to both cases. I might be missing something, but the fact that with declarative partitioning we analyze the children, while with inheritance we don't, seems a bit strange. Not sure. >> + if (*mcv_items > default_statistics_target) >> + n = default_statistics_target; > > It should use any non-default stats target of the parent's column > Yeah. That's a simplification, the non-PoC code would have to look at per-column statistics target for the target / all the children, and make some calculation based on that. I ignored that in the PoC. >> + * ignore anything but valid leaf relatiins with data, but release > > sp: relatiins. > >> + elog(WARNING, "stats for %d %d not found", >> + RelationGetRelid(rels[j]), vacattrstats[i]->attr->attnum); > > should be %u %d > > This code duplication is undesirable: >> + /* Log the action if appropriate */ >> + * Determine which columns to analyze Yeah. Fine for PoC, but needs to be cleaned up in future patch. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company