I have table1 which contains around 1mln line of records and table2 around 3mln line of data.
I have received the below-mentioned code from my previous post (link) which is updating the table as expected, but is taking more than an hour to update just 100 lines of records.
do $$
declare
rec record;
current_joins text;
current_result int;
begin
for rec in select joins from table1 loop
select rec.joins into current_joins;
execute format('select count(*)
from (
select 1
from table2
group by %1$s
having count(*)>=1
) as some_alias;',
current_joins)
into current_result;
update table1 set result=current_result where joins=current_joins;
end loop;
end $$;
Appreciate if somebody could provide me any alternative code to handle the above requirements.
The feature of the table can be seen from the following link (https://dbfiddle.uk/pP_9mKy3) and the previous post can be seen from the following link