A dumbveloper at my work (years ago) moved the body column from our comments table to a secondary comment_extensions table as some sort of sketchy guesswork optimization. It seems ill-advised to do a join every time we want to display a comment, so I’m going to try moving that column back into our comments table and run some benchmarks.
My problem is that this update crawls. I let it run for an hour before shutting it off, fearing that it would take all night.
UPDATE comments SET body = comment_extensions.body
FROM comment_extensions
WHERE comments.id = comment_extensions.comment_id;
It’s a PostgreSQL 8.1 database, and comment_extensions.comment_id is indexed.
Any suggestions for making this run faster?
How about this?
http://www.postgresql.org/docs/8.1/interactive/sql-createtableas.html
That would create a new joined_comments table. That could be almost enough (you’d need to still recreate indexes and so on) but I remember Postgres 8.1 has a bug about the way serial columns get created (sorry can’t find a link).
So my suggestion would be that after you have this new joined table, then you COPY TO a BINARY file from that joined_comments table, create a new comments table stating that id is a SERIAL right from the start, then COPY FROM that BINARY file to the new comments table. Then, recreate indexes.