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 1ogJxW-0005MB-7C for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Oct 2022 06:02:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ogJxU-00024y-UQ for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Oct 2022 06:02:12 +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 1ogJxU-00024p-GQ for pgsql-hackers@lists.postgresql.org; Thu, 06 Oct 2022 06:02:12 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ogJxR-0000k9-5H for pgsql-hackers@postgresql.org; Thu, 06 Oct 2022 06:02:12 +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 A8BEB21C4996; Thu, 6 Oct 2022 09:02:07 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1665036127; bh=Vt6+IZAJW6pRGlPMLsAPyNRShQ2Sng4zf++BJI8lM34=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=p/N0siuCgKQKAzPwaUPSDE4OMYpU8fYy3m21YoDnHjiRHLSABwDteW4BPF8FCNtcI BSP1FEbtjwIlxnbbjYhCnCnE7nMKIhY6rW1FUjxWab7IDW3qvoP+69qc/uK4EVroHL e1vorB8ECDyWv0fDcCOmSsxeJJeCvt7gRCoK6GXU= Message-ID: <3df5c68b-13aa-53d0-c0ec-ed98e6972e2e@postgrespro.ru> Date: Thu, 6 Oct 2022 11:02:07 +0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.1 Subject: Re: document the need to analyze partitioned tables To: Laurenz Albe , Tomas Vondra , Justin Pryzby , Robert Haas Cc: =?UTF-8?Q?=c3=81lvaro_Herrera?= , yuzuko , pgsql-hackers@postgresql.org References: <20210913035409.GA10647@telsasoft.com> <20211008125822.GJ27491@telsasoft.com> <681e76ad-3a7b-ea3c-b6b0-55946239c49b@enterprisedb.com> <20220121180200.GM23027@telsasoft.com> <19c248d9-3687-9e0f-0b1a-2adad1de6fbe@enterprisedb.com> <20220315230011.GZ28503@telsasoft.com> <88903179-5ce2-3d4d-af43-7830372bdcb6@enterprisedb.com> <1fd81ddc7710a154834030133c6fea41e55c8efb.camel@cybertec.at> Content-Language: en-US From: Andrey Lepikhov Organization: Postgres Professional In-Reply-To: <1fd81ddc7710a154834030133c6fea41e55c8efb.camel@cybertec.at> 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 10/5/22 13:37, Laurenz Albe wrote: > On Mon, 2022-03-28 at 15:05 +0200, Tomas Vondra wrote: >> I've pushed the last version, and backpatched it to 10 (not sure I'd >> call it a bugfix, but I certainly agree with Justin it's worth >> mentioning in the docs, even on older branches). > > I'd like to suggest an improvement to this. The current wording could > be read to mean that dead tuples won't get cleaned up in partitioned tables. > > > By the way, where are the statistics of a partitioned tables used? The actual > tables scanned are always the partitions, and in the execution plans that > I have seen, the optimizer always used the statistics of the partitions. For example, it is used to estimate selectivity of join clause: CREATE TABLE test (id integer, val integer) PARTITION BY hash (id); CREATE TABLE test_0 PARTITION OF test FOR VALUES WITH (modulus 2, remainder 0); CREATE TABLE test_1 PARTITION OF test FOR VALUES WITH (modulus 2, remainder 1); INSERT INTO test (SELECT q, q FROM generate_series(1,10) AS q); VACUUM ANALYZE test; INSERT INTO test (SELECT q, q%2 FROM generate_series(11,200) AS q); VACUUM ANALYZE test_0,test_1; EXPLAIN (ANALYZE, TIMING OFF, SUMMARY OFF) SELECT * FROM test t1, test t2 WHERE t1.id = t2.val; VACUUM ANALYZE test; EXPLAIN (ANALYZE, TIMING OFF, SUMMARY OFF) SELECT * FROM test t1, test t2 WHERE t1.id = t2.val; Here without actual statistics on parent table we make wrong prediction. -- Regards Andrey Lepikhov Postgres Professional