sql - How can I optimize this PostgreSQL query that updates every row? -
i wrote query update entire table. how can improve query take less time:
update page_densities set density = round(density - 0.001, 2)
query returned successfully: 628391 rows affected, 1754179 ms (29 minutes) execution time.
edit: setting work memory..
set work_mem = '500mb'; update page_densities set density = round(density - 0.001, 2)
query returned successfully: 628391 rows affected, 731711 ms (12 minutes) execution time.
assuming density not index, may able improve performance different fillfactor. see question/answer or postgresql docs more info:
http://www.postgresql.org/docs/9.4/static/sql-createtable.html
slow simple update query on postgresql database 3 million rows
although cannot modify table's fillfactor, can create new table different fill factor , copy data over. here sample code.
--create new table different fill factor create table page_densities_new ( ...some fields here ) ( fillfactor=70 ); --copy of records new table insert page_densities_new select * page_densities; --rename original/old table alter table page_densities rename page_densities_old; --rename new table alter table page_densities_new rename page_densities;
after have table same name , data original, has different fill factor. set 70, can value 10 100. (100 default)
Comments
Post a Comment