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 1lyZko-0001g1-8r for pgsql-hackers@arkaria.postgresql.org; Wed, 30 Jun 2021 12:55:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lyZkm-0000Oj-SB for pgsql-hackers@arkaria.postgresql.org; Wed, 30 Jun 2021 12:55:44 +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 1lyZkm-0000Oa-Go for pgsql-hackers@lists.postgresql.org; Wed, 30 Jun 2021 12:55:44 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lyZkj-0002lZ-BA for pgsql-hackers@lists.postgresql.org; Wed, 30 Jun 2021 12:55:44 +0000 Received: from Andreys-MacBook-Pro.local (cyclops.postgrespro.ru [93.174.131.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 942F021C8815; Wed, 30 Jun 2021 15:55:39 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1625057739; bh=IDx6YNJ3iny6Hk4X+ACe9JimuuGAFCgQKW31gQflWxM=; h=Subject:To:References:From:Date:In-Reply-To; b=FobmICAYHwd7/TFn3NiVdbc1yMDuORdAKrrShUmRyqjtGFFFJxWskEGbacgi/yaQ2 nmWrre2wFVsN2Y38PqP8h94Fas7Yb3Iilgs2U+/DJG+Gf5y3N2P/sQPXVQ+rDXTvly a7qPOSgO0W7kUUlZkuNtDbrs9KCLOfaDTtGXi54Q= Subject: Re: Merging statistics from children instead of re-sampling everything To: Tomas Vondra , PostgreSQL Hackers References: <078c36f0-fc9c-b2d9-2bae-8eebafcefe93@enterprisedb.com> <92ce5a13-f97f-b4e8-c0f7-01c53d917f4f@postgrespro.ru> From: Andrey Lepikhov Organization: Postgres Professional Message-ID: <82fcba0a-7c50-c714-2a6b-f2677affe65d@postgrespro.ru> Date: Wed, 30 Jun 2021 15:55:38 +0300 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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. > > > On 6/29/21 9:01 AM, Andrey Lepikhov wrote: >> On 30/3/21 03:51, Tomas Vondra wrote: >>> Of course, that assumes the merge is cheaper than processing the list of >>> statistics, but I find that plausible, especially the list needs to be >>> processed multiple (e.g. when considering different join orders, filters >>> and so on). >> I think your approach have a chance. But I didn't understand: why do >> you merge statistics? I think we could merge only samples of each >> children and build statistics as usual. >> Error of a sample merging procedure would be quite limited. >> > -- regards, Andrey Lepikhov Postgres Professional