Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bAWs3-0001aT-Gm for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Jun 2016 06:21:43 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bAWs3-00008A-3g for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Jun 2016 06:21:43 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bAWqh-00073a-Bc for pgsql-hackers@postgresql.org; Wed, 08 Jun 2016 06:20:19 +0000 Received: from szalupa.batory.org.pl ([81.18.204.35]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bAWqe-0002AZ-GZ for pgsql-hackers@postgresql.org; Wed, 08 Jun 2016 06:20:18 +0000 Received: from [192.168.0.11] (095160153008.dynamic-ww-10.vectranet.pl [95.160.153.8]) (authenticated bits=0) by szalupa.batory.org.pl (8.14.4/8.14.4) with ESMTP id u586Jv9R018096 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Wed, 8 Jun 2016 08:19:57 +0200 Subject: Re: [BUGS] Routine analyze of single column prevents standard autoanalyze from running at all To: Tom Lane , Jim Nasby References: <28700.1465238280@sss.pgh.pa.us> <5755DBC2.9040007@agliodbs.com> <3d9303dc-f99c-b63c-73be-aa2214bebe73@BlueTreble.com> <26771.1465355045@sss.pgh.pa.us> Cc: Josh berkus , pgsql-hackers@postgresql.org From: Tomasz Ostrowski Message-ID: <3eebdfc2-95dc-9ede-7467-47a3c26b8892@ato.waw.pl> Date: Wed, 8 Jun 2016 08:19:58 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 MIME-Version: 1.0 In-Reply-To: <26771.1465355045@sss.pgh.pa.us> Content-Type: text/plain; charset=iso-8859-2; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 81.18.204.35 X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org W dniu 2016-06-08 o 05:04, Tom Lane pisze: > Jim Nasby writes: >> Is there any significant advantage to not analyzing all columns? Only >> case I can think of is if you have a fair number of columns that have >> been toasted; otherwise I'd think IO would completely swamp any other >> considerations. > > Yeah, my guess is that the OP's example where analyzing just one column > was significantly cheaper boiled down to some of the other columns being > mostly toasted data. Otherwise it's hard to see how there's much more > expense in analyzing them all. Actually no - this volatile column has smaller "statistics" than most of the table, so analyzing it is much faster when it's data is not in RAM. Here is a small exaggerated example showing a difference: $ psql tometzky=> create table test (id serial, data text); tometzky=> insert into test(data) select 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ' ||generate_series(0,10000000)::text; tometzky=> alter table test alter column id set statistics 10; tometzky=> alter table test alter column data set statistics 1000; tometzky=> \q # Drop OS page cache and restart postgres # so the table data won't be in RAM anymore: $ sudo sh -c 'echo 1 >/proc/sys/vm/drop_caches' $ sudo systemctl restart postgresql; # Test single column analyze: $ psql tometzky=> \timing Timing is on. tometzky=> analyze verbose test(id); INFO: analyzing "public.test" INFO: "test": scanned 3000 of 123457 pages, containing 243000 live rows and 0 dead rows; 3000 rows in sample, 2712238 estimated total rows ANALYZE Time: 422,521 ms tometzky=> \q # Drop OS page cache and restart postgres again $ sudo sh -c 'echo 1 >/proc/sys/vm/drop_caches' $ sudo systemctl restart postgresql; $ psql tometzky=> \timing Timing is on. tometzky=> analyze verbose test; INFO: analyzing "public.test" INFO: "test": scanned 123457 of 123457 pages, containing 10000001 live rows and 0 dead rows; 300000 rows in sample, 10000001 estimated total rows ANALYZE Time: 9447,519 ms -- Tomasz "Tometzky" Ostrowski -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers