ANALYZE after CREATE TABLE AS SELECT...

Started by Semyon Reyfmanabout 11 years ago4 messagesgeneral
Jump to latest
#1Semyon Reyfman
reyfmans@gmail.com

Hi,

When I create a table with "CREATE TABLE name AS SELECT." statement and
immediately afterward use this new table in a query does it make sense to
run ANALYZE on the table in between? It appears that postgres should be
able to collect very detailed statistics while emitting the table but I am
not sure if this is done.

Thanks

Simon

#2Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Semyon Reyfman (#1)
Re: ANALYZE after CREATE TABLE AS SELECT...

Semyon Reyfman wrote:

When I create a table with "CREATE TABLE name AS SELECT." statement and
immediately afterward use this new table in a query does it make sense to
run ANALYZE on the table in between? It appears that postgres should be
able to collect very detailed statistics while emitting the table but I am
not sure if this is done.

It isn't. It also doesn't create any indexes, which you might want to
do before analyze.

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#3David Steele
david@pgmasters.net
In reply to: Alvaro Herrera (#2)
Re: ANALYZE after CREATE TABLE AS SELECT...

On 2/26/15 5:23 PM, Alvaro Herrera wrote:

Semyon Reyfman wrote:

When I create a table with "CREATE TABLE name AS SELECT." statement and
immediately afterward use this new table in a query does it make sense to
run ANALYZE on the table in between? It appears that postgres should be
able to collect very detailed statistics while emitting the table but I am
not sure if this is done.

It isn't. It also doesn't create any indexes, which you might want to
do before analyze.

Is it necessary to create indexes before analyzing?

I usually do, just to be safe, but I thought statistics were based
solely on sampling of the heap.

--
- David Steele
david@pgmasters.net

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: David Steele (#3)
Re: ANALYZE after CREATE TABLE AS SELECT...

David Steele <david@pgmasters.net> writes:

On 2/26/15 5:23 PM, Alvaro Herrera wrote:

It isn't. It also doesn't create any indexes, which you might want to
do before analyze.

Is it necessary to create indexes before analyzing?

I usually do, just to be safe, but I thought statistics were based
solely on sampling of the heap.

ANALYZE pays no attention to plain indexes. If you have any expression
indexes, it will collect stats for those expressions.

regards, tom lane

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general