pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomasz Ostrowski <tometzky+pg@ato.waw.pl>
To: Tom Lane <tgl@sss.pgh.pa.us>
To: Jim Nasby <Jim.Nasby@BlueTreble.com>
Cc: Josh berkus <josh@agliodbs.com>
Cc: pgsql-hackers@postgresql.org
Subject: Re: [BUGS] Routine analyze of single column prevents standard autoanalyze from running at all
Date: Wed, 8 Jun 2016 08:19:58 +0200
Message-ID: <3eebdfc2-95dc-9ede-7467-47a3c26b8892@ato.waw.pl> (raw)
In-Reply-To: <26771.1465355045@sss.pgh.pa.us>
References: <ef99c1bd-ff60-5f32-2733-c7b504eb960c@ato.waw.pl>
	<28700.1465238280@sss.pgh.pa.us>
	<WM!3b713ccc015c0c47227d1456caf75c57fb15350b789ac43e940c60b7507990cad27fa6afdc0df2c3e2d3afaa80b692c8!@mailstronghold-2.zmailcloud.com>
	<5755DBC2.9040007@agliodbs.com>
	<3d9303dc-f99c-b63c-73be-aa2214bebe73@BlueTreble.com>
	<26771.1465355045@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

W dniu 2016-06-08 o 05:04, Tom Lane pisze:
> Jim Nasby <Jim.Nasby@BlueTreble.com> 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



view thread (8+ messages)  latest in thread

Message-ID: <3eebdfc2-95dc-9ede-7467-47a3c26b8892@ato.waw.pl>
Permalink:  ../3eebdfc2-95dc-9ede-7467-47a3c26b8892@ato.waw.pl/
Also on:    postgresql.org/message-id/3eebdfc2-95dc-9ede-7467-47a3c26b8892@ato.waw.pl

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tometzky+pg@ato.waw.pl, tgl@sss.pgh.pa.us, Jim.Nasby@BlueTreble.com, josh@agliodbs.com, pgsql-hackers@postgresql.org
  Subject: Re: [BUGS] Routine analyze of single column prevents standard autoanalyze from running at all
  In-Reply-To: <3eebdfc2-95dc-9ede-7467-47a3c26b8892@ato.waw.pl>
  References: <ef99c1bd-ff60-5f32-2733-c7b504eb960c@ato.waw.pl> <28700.1465238280@sss.pgh.pa.us> <WM!3b713ccc015c0c47227d1456caf75c57fb15350b789ac43e940c60b7507990cad27fa6afdc0df2c3e2d3afaa80b692c8!@mailstronghold-2.zmailcloud.com> <5755DBC2.9040007@agliodbs.com> <3d9303dc-f99c-b63c-73be-aa2214bebe73@BlueTreble.com> <26771.1465355045@sss.pgh.pa.us> <3eebdfc2-95dc-9ede-7467-47a3c26b8892@ato.waw.pl>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox