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 1nIXb0-0006wx-CT for pgsql-hackers@arkaria.postgresql.org; Fri, 11 Feb 2022 15:12:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nIXaz-0004YG-4Z for pgsql-hackers@arkaria.postgresql.org; Fri, 11 Feb 2022 15:12:25 +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 1nIXay-0004Y4-HI for pgsql-hackers@lists.postgresql.org; Fri, 11 Feb 2022 15:12:24 +0000 Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nIXau-0006Rs-Ks for pgsql-hackers@lists.postgresql.org; Fri, 11 Feb 2022 15:12:23 +0000 Received: by mail-ed1-x532.google.com with SMTP id ch26so16836613edb.12 for ; Fri, 11 Feb 2022 07:12:20 -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 :cc:references:from:in-reply-to:content-transfer-encoding; bh=+Y2Ke2KOnSyRZC1z0EnqgfZljIr8XDyovKKHoAEtN+Q=; b=dqV+cnzCZxgaEYcLQKVm+h1bUut5cT3E6kkSUVDVzGy/1E6kMdim/Nb7Nxl73bxy/R 5xu2VWGgPTLNc2hpCj7Rek2kTMlleA+WJFC7bK/AmQ++C04RY8d+XUJuTO/AdqbbylXV z6++swTyqU0uAEIhrQS6Y0fS4G2gZ6jzKNFO6kMmMvtRxo3Uq4V0RiUUUmfBC00bpWJ4 zJPXnCJEAxejroMKPvvAAslnjRiDioJowan7STXGlBUWUNDqzm3vha6ErB75VcB81ght Ondb9NC2CrV+x8jog4forPaPJjhOjXnypKmeO253aUJ2PW5g6WpBjVhW03Wbiie5WHt2 PCHw== 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:cc:references:from:in-reply-to :content-transfer-encoding; bh=+Y2Ke2KOnSyRZC1z0EnqgfZljIr8XDyovKKHoAEtN+Q=; b=eL6qe5ZgrswLBE5IGgrJiwCF3e4R3Xr7vJh/LGCFYmkMJn3qMc8YGEpea4s38Kd7Ov /ZwyTsGIbNSQLO+5YdQu1HgroRoHwLta7/dIUkEMYxLhF41iM43Iqj6JaNEAbtqmYOms jcZoOoyTllCcd9hGLTHIi81k6d7Lb+6bFQ6tGbxg4jSmwrJS/atugVIFjihlz1TrFMeT jiNjBI0QOtZ/S4rjWlX1CiOWjf4ejD3wZ9Xbs5JjgP4HZTNrX/ahW/OpHa+SyMDMopm0 ee0lkS+SAKSqOj5eKwQdAey45KTh+6CGabSZwE6hQxGGOTsVkgF2O+IGlqWnKp6bpH8R 2urw== X-Gm-Message-State: AOAM531kF6IT8ldJUvPXmS5rMxJUFw3Vh6b8FzeUGIJrZSpG7CS9/y0s s9zpjVmWRxG2FMv4BmCidR3PBBNd8L1b2v4WdhOKO1WLMQK7oAJg/G+r4RoZNiWkbsbFyEm0151 aUvTTe6u31k+XbDj1xCLj+D5aQVkmZYXU5ZAgfCln5edBqHnQFLx9Rfj1jB0l7BME0gNOR2PTIq YKpH0nUBaasDCCRhL0wadrVX2IM8zwUSoRd+7T1VyxImdNFQOTuUtuVqKhK1sX X-Google-Smtp-Source: ABdhPJypUOUKl+En/6u/PC3lnEDZ5tDkxji37cflTMQj2g+rQwyvRR8A1zbgZUxVrEdvbAO6LWnSsw== X-Received: by 2002:a05:6402:3514:: with SMTP id b20mr2400232edd.65.1644592339160; Fri, 11 Feb 2022 07:12:19 -0800 (PST) Received: from [10.137.0.18] (static-84-42-175-93.net.upcbroadband.cz. [84.42.175.93]) by smtp.gmail.com with ESMTPSA id o3sm6223571edt.67.2022.02.11.07.12.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 11 Feb 2022 07:12:18 -0800 (PST) Message-ID: <901c13d7-b37f-3a2d-062a-3696d58d030c@enterprisedb.com> Date: Fri, 11 Feb 2022 16:12:16 +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 V. Lepikhov" , PostgreSQL Hackers Cc: d.belyalov@postgrespro.ru 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> <90e400a2-9afa-15c6-8c3c-bac9f68cb9f3@postgrespro.ru> From: Tomas Vondra In-Reply-To: <90e400a2-9afa-15c6-8c3c-bac9f68cb9f3@postgrespro.ru> Content-Type: text/plain; charset=UTF-8; format=flowed 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/11/22 05:29, Andrey V. Lepikhov wrote: > 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). > I'm not sure I understand what you mean by multiplexing. The term usually means "sending multiple signals at once" but I'm not sure how that applies to this issue. Can you elaborate? I assume you mean something like collecting a sample for a partition once, and then keeping and reusing the sample for future ANALYZE runs, until invalidated in some sense. Yeah, I agree that'd be useful - and not just for partitions, actually. I've been pondering something like that for regular tables, because the sample might be used for estimation of clauses directly. But it requires storing the sample somewhere, and I haven't found a good and simple way to do that. We could serialize that into bytea, or we could create a new fork, or something, but what should that do with oversized attributes (how would TOAST work for a fork) and/or large samples (which might not fit into 1GB bytea)? > 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. I think storing samples in pg_statistic is problematic, because values[] is subject to 1GB limit etc. Not an issue for small MCV list of a single attribute, certainly an issue for larger samples. Even if the data fit, the size of pg_statistic would explode. > 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. > I think ndistinct is problem only when merging final estimates. But if we're able to calculate and store some intermediate results, we can easily use HLL and merge that. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company