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 1nINZZ-00040p-Ua for pgsql-hackers@arkaria.postgresql.org; Fri, 11 Feb 2022 04:30:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nINZ1-00066S-Mu for pgsql-hackers@arkaria.postgresql.org; Fri, 11 Feb 2022 04:29:43 +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 1nINZ1-00066J-Cl for pgsql-hackers@lists.postgresql.org; Fri, 11 Feb 2022 04:29:43 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nINYy-0002mZ-Mp for pgsql-hackers@lists.postgresql.org; Fri, 11 Feb 2022 04:29:42 +0000 Received: from [192.168.28.53] (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 1B69921C98E9; Fri, 11 Feb 2022 07:29:39 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1644553779; bh=7NhJBf8/s917pscMqT59S7P9r7lOPLu27xOaNxoghrs=; h=Date:Subject:To:References:From:Cc:In-Reply-To; b=pAXHhAupMdCnnjW3hxLFq0s7yfxQ1DDdSmpuwNMnSibNIgzEPcmSEGKZ+nX+JuUWO QagAUSHMo5CAUAU7e9/XaF6fCVN+ISOP6EtNPK2EtUXG5gaIZVGjOLO5+8ETGZxHzj o3OnBU+H8f9BuE/bW3LXAIl5ZB7mgXcTrtd4js7k= Message-ID: <90e400a2-9afa-15c6-8c3c-bac9f68cb9f3@postgrespro.ru> Date: Fri, 11 Feb 2022 09:29:38 +0500 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: Tomas Vondra , 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> <4e86ae74-4e2c-b40f-4405-035d2f818e5d@enterprisedb.com> From: "Andrey V. Lepikhov" Organization: Postgres Professional Cc: d.belyalov@postgrespro.ru In-Reply-To: <4e86ae74-4e2c-b40f-4405-035d2f818e5d@enterprisedb.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2/11/22 03:37, Tomas Vondra wrote: > 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. IMO, to solve the problem we should do two things: 1. Avoid repeatable partition scans in the case inheritance tree. 2. Avoid to re-analyze everything in the case of active changes in small subset of partitions. For (1) i can imagine a solution like multiplexing: on the stage of defining which relations to scan, group them and prepare parameters of scanning to make multiple samples in one shot. It looks like we need a separate logic for analysis of partitioned tables - we should form and cache samples on each partition before an analysis. It requires a prototype to understand complexity of such solution and can be done separately from (2). Task (2) is more difficult to solve. Here we can store samples from each partition in values[] field of pg_statistic or in specific table which stores a 'most probable values' snapshot of each table. Most difficult problem here, as you mentioned, is ndistinct value. Is it possible to store not exactly calculated value of ndistinct, but an 'expected value', based on analysis of samples and histograms on partitions? Such value can solve also a problem of estimation of a SETOP result grouping (joining of them, etc), where we have statistics only on sources of the union. -- regards, Andrey Lepikhov Postgres Professional