An application I am working with contains this sequence of queries at the end of constructing a large temp table; I believe it is an attempt to improve performance by pruning dead tuples –
create temp table tmp_foo_new as select * from tmp_foo;
drop table tmp_foo;
alter table tmp_foo_new rename to tmp_foo;
Some rudimentary benchmarks do indicate this sequence does improve performance substantially, so it is worthwhile. It feels somewhat hacky to me though. Is there a more canonical way to do this?
Best Answer
If the table has an index, you may want to consider the
cluster
command instead of re-creating it or usingvacuum full
. This will:order by
clause when re-creating)