drop table if exists document; drop table if exists document_file ; create table document (document_type_id int, id int primary key); create table document_file (document_type_id int, document_id int primary key, filler char(600)); insert into document_file select x,x,'z' from generate_series(1,4000000) x; insert into document select x,x from generate_series(1,4000000) x; analyze document_file; analyze document; set enable_mergejoin = false; explain analyze UPDATE ONLY document_file AS df SET document_type_id = d.document_type_id FROM document AS d WHERE d.id = document_id;