Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uNE5Y-00EczH-1h for pgsql-performance@arkaria.postgresql.org; Thu, 05 Jun 2025 17:09:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uNE5W-00C5Z8-29 for pgsql-performance@arkaria.postgresql.org; Thu, 05 Jun 2025 17:09:10 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uNE5V-00C5Yz-O5 for pgsql-performance@lists.postgresql.org; Thu, 05 Jun 2025 17:09:10 +0000 Received: from mail1.dalibo.net ([51.159.93.128] helo=mail.dalibo.com) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uNE5U-000OaV-2Y for pgsql-performance@lists.postgresql.org; Thu, 05 Jun 2025 17:09:10 +0000 Received: from [192.168.0.7] (5-49-10-71.hfc.dyn.abo.bbox.fr [5.49.10.71]) by mail.dalibo.com (Postfix) with ESMTPSA id 9BAD927F35; Thu, 5 Jun 2025 19:09:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dalibo.com; s=a; t=1749143346; bh=ZyFQlsKTGJCCY/Y2O5za3yHgEGsam1QBCOxlrxHKcGY=; h=Date:Subject:To:References:From:In-Reply-To:From; b=FYfnwM8wGGC3QqSJDYlO9vsbQ0o8yaJLg+nA+gDESJQZhPIGcVxwRGpruj1Wi15/v cKdd+eWFRXTkMm4JFfrU3jyEA3ZbPtED4lzRQTmJyUv1KKhWSYjSFXSPMCZ+b5wxoM UPSuE3JkCCW0UXLHjikcZ1PY2wZ9b7EzqQVDYAAs= Message-ID: <3e539c8b-c95a-4ba9-8462-04045b2da2b0@dalibo.com> Date: Thu, 5 Jun 2025 19:09:06 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Poor row estimates from planner, stat `most_common_elems` sometimes missing for a text[] column To: Mark Frost , "pgsql-performance@lists.postgresql.org" References: From: =?UTF-8?Q?Fr=C3=A9d=C3=A9ric_Yhuel?= Content-Language: fr, en-US Autocrypt: addr=frederic.yhuel@dalibo.com; keydata= xjMEXn3bgxYJKwYBBAHaRw8BAQdA6tX5FT/n5ztMWIoBdl6k5avvu65fv6ryfVzIx/aH3V3N JEYuIFlodWVsIDxmcmVkZXJpYy55aHVlbEBkYWxpYm8uY29tPsKWBBMWCAA+FiEEi7OTyf6H ePS+C6n11XGWhN8zGNUFAmZDVJ8CGwMFCQtfi90FCwkIBwIGFQoJCAsCBBYCAwECHgECF4AA CgkQ1XGWhN8zGNV65gEA6o+UrebFjn2CIAOYwP3CiiJugiM5TMH9yJyehQua5ZoA/2ChxiVn 8OUaAw/ErxJmQi1mSN0tNZBL/KhkUPBDUDQNzjgEXn3bgxIKKwYBBAGXVQEFAQEHQCuh5cLQ AtEBXHa2Fmtp0kduBu7msM7qO/gaEcdjFUdiAwEIB8J+BBgWCAAmAhsMFiEEi7OTyf6HePS+ C6n11XGWhN8zGNUFAmZDVJ8FCQtfi90ACgkQ1XGWhN8zGNWOOAEArSqePBqfd4Kx4ulACaWO 6fM+XSDfUlBAQXx9rU6DR4MBALwozl9g91tRysim6lKxggvBfp/PvbpTZNrxYLWB2fYP In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 6/5/25 17:42, Mark Frost wrote: > Is there any good explanation for this behaviour? Preferably we’d like > some way for proper `most_common_elems` statistics to be collected in > our production database, in the hope that influences a good query plan > to always be selected. most_common_elems has a limited size, and if all the elements have the same freq, there's nothing we can do. You could do: alter table test alter column tags set statistics X; However, X is capped at 10000, which means that the size of most_common_elems will be less than 100k, and it would probably be stupid to go beyond that anyway. It seems that postgres lacks some kind of "n_distinct_elems" for that kind of case, but let's wait and see what the statistics gurus think.