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 1nII4K-0008FC-8a for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Feb 2022 22:37:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nII4I-0006mM-QB for pgsql-hackers@arkaria.postgresql.org; Thu, 10 Feb 2022 22:37:38 +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 1nII4I-0006mC-4T for pgsql-hackers@lists.postgresql.org; Thu, 10 Feb 2022 22:37:38 +0000 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nII4B-0008Bh-Us for pgsql-hackers@lists.postgresql.org; Thu, 10 Feb 2022 22:37:36 +0000 Received: by mail-ej1-x634.google.com with SMTP id y22so6808617eju.9 for ; Thu, 10 Feb 2022 14:37:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to:content-transfer-encoding; bh=KNDjCR2CQ1cRgjZd3x+eG0I16u9paV+UVe+La5InCDc=; b=GSW8XLcBtnTNQavQgFV8I/SqgPHlQIG3ojT/zcOBBx2FoHu2F0Cv/PJVNEXq8Uhnb+ s76lht31poxZmTiXDfCy3X0I4oYiOx2knMYqQ9ms5EGbA1SthPyNWHYwtWpx3hdxAsPo 7wq0HmwPuDolxafe2NkTutjlg2AbzT3UhgV5DExn/M/GmVx2AKzbW9F2Z8aWwjP+T1pu H+GghuOtI1DoTbOBBr0MtnwMEKIKaaM3VBOkOXbbqOyIsCA8Oq795ANiQtxrc6uezkDp EBARuHH5R0dHNtxZ+2RmB9/XVgGaNjrySiIyvkyKvnYpTp10gt+TD4NOMInlpcFL5YhQ zIbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=KNDjCR2CQ1cRgjZd3x+eG0I16u9paV+UVe+La5InCDc=; b=FA9k5btOWiqcu4oCssowb351LAM/v7d1JCPXattCgh2G68MLRumKrvYXJ3LCNZu68s bMMU+Skk8YTFbwcQH2MVlzsy8r9yC6J8xQapQMwa7y+X0AU4AXwpLRU9l40tzqXUyh/q Ka+DiS7pOwTdkphbSfpf9JogAcOH71Vpbfi74dxBNZIZpaIDkRnYv6lBddR+nJJWN+by krW61yQcFb+/vJED5q0eOSUVd631QLyrsHF4YeTVNRtdHZQYXaxxlXrl23BJl1hFe9cT 08aaLrC7ZcQ4o7k6+6SYrDSmmecxOwguCd0Hc4CEpYIJtWW0ZOYsTcCZT7nQq/iTaJbA ZtQw== X-Gm-Message-State: AOAM530+/XlfmD4JR+QXtE8ULc8IDttqKxnjz3iO69f+lgF/ivwWLFBo +sPkyQ2CfdeGsjCG1lM9OQADAv8I6acEQ10Pl0ThcLkIo9rnNFreADm6/1fOHx85S8a5PUP/t8L gCSMUQ0+pPUbBvkr/1PhubVA3iSVkaUNOkoFnuWAUkZKkfNx32EmYcUCxpBinFhy5nHNYv6akoQ guWWg6Hx/VgQgChB8ixUdRNrAjuAwyVcpfx1sENdd+IeJJ4z8iErlx X-Google-Smtp-Source: ABdhPJzy289GL3yJksx+5/AsU7+cHs47+kieg2lHj6qQWvm12Jvd2Kxkd7pARIbYUAatt0cnduIpBg== X-Received: by 2002:a17:906:31d0:: with SMTP id f16mr8154118ejf.627.1644532650180; Thu, 10 Feb 2022 14:37:30 -0800 (PST) Received: from [10.137.0.19] (ip-86-49-251-241.net.upcbroadband.cz. [86.49.251.241]) by smtp.gmail.com with ESMTPSA id fi16sm3981342ejc.193.2022.02.10.14.37.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 10 Feb 2022 14:37:29 -0800 (PST) Message-ID: <4e86ae74-4e2c-b40f-4405-035d2f818e5d@enterprisedb.com> Date: Thu, 10 Feb 2022 23:37:26 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: Merging statistics from children instead of re-sampling everything Content-Language: en-US To: Andrey Lepikhov , PostgreSQL Hackers References: <078c36f0-fc9c-b2d9-2bae-8eebafcefe93@enterprisedb.com> <92ce5a13-f97f-b4e8-c0f7-01c53d917f4f@postgrespro.ru> <82fcba0a-7c50-c714-2a6b-f2677affe65d@postgrespro.ru> <949f204b-44e2-4e41-67ff-f93643828f4a@enterprisedb.com> From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8 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 2/10/22 12:50, Andrey Lepikhov wrote: > On 21/1/2022 01:25, Tomas Vondra wrote: >> But I don't have a very good idea what to do about statistics that we >> can't really merge. For some types of statistics it's rather tricky to >> reasonably merge the results - ndistinct is a simple example, although >> we could work around that by building and merging hyperloglog counters. > > I think, as a first step on this way we can reduce a number of pulled > tuples. We don't really needed to pull all tuples from a remote server. > To construct a reservoir, we can pull only a tuple sample. Reservoir > method needs only a few arguments to return a sample like you read > tuples locally. Also, to get such parts of samples asynchronously, we > can get size of each partition on a preliminary step of analysis. > In my opinion, even this solution can reduce heaviness of a problem > drastically. > Oh, wow! I haven't realized we're fetching all the rows from foreign (postgres_fdw) partitions. For local partitions we already do that, because that uses the usual acquire function, with a reservoir proportional to partition size. I have assumed we use tablesample to fetch just a small fraction of rows from FDW partitions, and I agree doing that would be a pretty huge benefit. I actually tried hacking that together - there's a couple problems with that (e.g. determining what fraction to sample using bernoulli/system), but in principle it seems quite doable. Some minor changes to the FDW API may be necessary, not sure. Not sure about the async execution - that seems way more complicated, and the sampling reduces the total cost, async just parallelizes it. That being said, this thread was not really about foreign partitions, but about re-analyzing inheritance trees in general. And sampling foreign partitions doesn't really solve that - we'll still do the sampling over and over. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company