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 1lybvx-0006L1-S0 for pgsql-hackers@arkaria.postgresql.org; Wed, 30 Jun 2021 15:15:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lybvv-00053z-QW for pgsql-hackers@arkaria.postgresql.org; Wed, 30 Jun 2021 15:15:23 +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 1lybvv-00053r-Ef for pgsql-hackers@lists.postgresql.org; Wed, 30 Jun 2021 15:15:23 +0000 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lybvq-0001BX-6y for pgsql-hackers@lists.postgresql.org; Wed, 30 Jun 2021 15:15:21 +0000 Received: by mail-ed1-x529.google.com with SMTP id w17so3748790edd.10 for ; Wed, 30 Jun 2021 08:15:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=lEK6s5+QAVRiOS+k9lqmtPE7BJtBabRKnXHjbkXp49c=; b=ROivp8mOHknxSqhxr/KXDjImuGEoKUVIQZKl+Wd7NK6CkrH2gav0Vs+3ajYZjpb0JL ZmEZhLW0YB4gFzSXbfcNSMTtNy1FvfaS1jjBcYzucNqoqBF9Lg2R2s+7skAS0pUF65jR h5A7gL2zkoN/+GIfBqU0Domg8RMsyO+DBGC/X8g0Z9xfMNKnySAMAG0z6g6A2k7ZxZNg hIroqw0a69gCNeaanJYAMOBPX6YU4nlPkLynwIFgghSCbnEzmbNkUcga6Z44OvSB9OG7 lAs1j4PPuotd9D6OZXSEqRO/CsaUjh0wOC1kaG2rH+sZ1jyAG4pcC8csJcmju2rT5dt2 Xvkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=lEK6s5+QAVRiOS+k9lqmtPE7BJtBabRKnXHjbkXp49c=; b=sEM2pAIpHFSGvnziH01gwcemSSs47uyWbSKM8LFPPVVqSJcByHZoiY8L3jJr2HrUid zCVvQ2qhq2VF5z7I9wztRqYxed1rP2ksPl4iKvrCRbiw97v8qo33T85OWJGszK9QAVmm 5yzdrUs6+uiHHt/WRAyl8qntDjUeTQBOsVQUr9IM44wyacmxmnZwnPNsXDYIAkVWulsa B8gYw0FtNTneT/9NZOeD12PsVwatP3mwv+R8qP+4KLNJ/8joM3MeomuZKYARxTyFKqFu KNyKDHL5fRRUKK6twD5vK+SJKD/uOB7a+zyr9V5t3ZsqxkOjeA48hOLBJRUv34oXjWfy jZ1Q== X-Gm-Message-State: AOAM531S0VWO28kvhrJo55fTko4GmQRMoHGgh2AwMFS1+SJhAyECrcLv Csv8NNcPHx/8AjNam6nSusLxzvrARHm0ks6HzriUvhBLcK89Kwu4d4aV1INcqNO5QrvQBpEj0b+ tB2jLdXNAzaLeTC/0Gft+ZsaT/3Bpr9JystfUXkZ5sCY3FBwGet0P1fs637/0/09gxKevzg33Ix 8gjPCMZWFzgvnzQ3CyEzILOVqyUYeE2A74aKLCiJ1jgKFMnl5v78BeftBjnmufwX9BxLTais1tx EXTDuZVO9kPzTQ7D50/X7LONuQA3DMS9GyHZyXH589LWY+9ZMFoWa9Y X-Google-Smtp-Source: ABdhPJzhWkdafEErIFv3YVzxcdYCT4TIMpMXCSmPQVlq0EDLd12Kg0NP1ug9X5eAq3H/YVGlHP5Kig== X-Received: by 2002:aa7:c548:: with SMTP id s8mr46773169edr.148.1625066115386; Wed, 30 Jun 2021 08:15:15 -0700 (PDT) Received: from [10.137.0.18] (ip-86-49-254-183.net.upcbroadband.cz. [86.49.254.183]) by smtp.gmail.com with ESMTPSA id b25sm13181498edv.9.2021.06.30.08.15.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 30 Jun 2021 08:15:14 -0700 (PDT) Subject: Re: Merging statistics from children instead of re-sampling everything 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> From: Tomas Vondra Message-ID: Date: Wed, 30 Jun 2021 17:15:11 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <82fcba0a-7c50-c714-2a6b-f2677affe65d@postgrespro.ru> Content-Type: text/plain; charset=utf-8; format=flowed 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 6/30/21 2:55 PM, Andrey Lepikhov wrote: > Sorry, I forgot to send CC into pgsql-hackers. > On 29/6/21 13:23, Tomas Vondra wrote: >> Because sampling is fairly expensive, especially if you have to do it >> for large number of child relations. And you'd have to do that every >> time *any* child triggers autovacuum, pretty much. Merging the stats >> is way cheaper. >> >> See the other thread linked from the first message. > Maybe i couldn't describe my idea clearly. > The most commonly partitioning is used for large tables. > I suppose to store a sampling reservoir for each partition, replace on > update of statistics and merge to build statistics for parent table. > It can be spilled into tuplestore on a disk, or stored in a parent table. > In the case of complex inheritance we can store sampling reservoirs only > for leafs. > You can consider this idea as an imagination, but the merging statistics > approach has an extensibility problem on another types of statistics. > Well, yeah - we might try that too, of course. This is simply exploring the "merge statistics" idea from [1], which is why it does not even attempt to do what you suggested. We may explore the approach with keeping per-partition samples, of course. You're right maintaining a per-partition samples and merging those might solve (or at least reduce) some of the problems, e.g. eliminating most of the I/O that'd be needed for sampling. And yeah, it's not entirely clear how to merge some of the statistics types (like ndistinct). But for a lot of the basic stats it works quite nicely, I think. I'm sure there'll be some complexity due to handling large / toasted values, etc. And we probably need to design this for large hierarchies (IMHO it should work with 10k partitions, not just 100), in which case it may still be quite a bit more expensive than merging the stats. So maybe we should really support both, and combine them somehow? regards https://www.postgresql.org/message-id/CAM-w4HO9hUHvJDVwQ8%3DFgm-znF9WNvQiWsfyBjCr-5FD7gWKGA%40mail.gmail.com -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company