Re: Query never returns ... - Mailing list pgsql-sql

From Tom Lane
Subject Re: Query never returns ...
Date
Msg-id 12434.981658257@sss.pgh.pa.us
Whole thread Raw
In response to Re: Query never returns ...  (Brice Ruth <brice@webprojkt.com>)
List pgsql-sql
Brice Ruth <brice@webprojkt.com> writes:
> As for vacuum analyze - prior to running into these problems, I deleted
> all data from the database (using delete from <tblname>) and then ran
> vacuumdb -a, after which I loaded the data into the tables using 'copy
> ... from' - there have been no updates to the database since then -
> merely selects.

That was the wrong order to do things in :-(.  The VACUUM ANALYZE posted
statistics showing all your tables as empty, and the planner is now
faithfully choosing plans that are good for tiny tables --- ie, minimal
startup cost and don't worry about per-tuple cost.

There has been some talk of having stats automatically updated by COPY,
but right now it doesn't happen.  So the correct procedure is to do a
VACUUM ANALYZE on a table *after* you do any sizable data additions.

BTW, people have occasionally stated on the list that you need to redo
VACUUM ANALYZE after adding/dropping indexes, but that's not true, at
least not in the present state of the world.  VACUUM ANALYZE only posts
stats about the data in the table(s).  The planner always looks at the
current set of indices for a table, together with the last-posted data
statistics, to choose a plan.

            regards, tom lane

pgsql-sql by date:

Previous
From: Brice Ruth
Date:
Subject: Re: Re: Query never returns ...
Next
From: Peter Eisentraut
Date:
Subject: Re: [HACKERS] PL/pgsql EXECUTE 'SELECT INTO ...'