<div dir='auto'><div>Hi,<div dir="auto"><br></div><div dir="auto">The ST_union costs and like this you don't take advantage of any spatial index. You may want to create a temporary table made of the merged states with a gist index in order to use it for updating your table. </div><div dir="auto"><br></div><div dir="auto">HTH,</div><div dir="auto">Hug</div><br><div class="gmail_extra"><br><div class="gmail_quote">Le 13 déc. 2020 09:59, liglio.pessoal@nexxa.com.br a écrit :<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><p>Hi,</p><p> </p><p>I am trying to update a flag indicating if a point is inside a country. I have a table with 27 states (tb_state) and a partitioned table with points (tb_heat), child tables per year, from tb_heat_2000 to tb_heat_2025.</p><p>The update longs forever, and I have to cancel. I don’t’t know if is a postgresql tune problem, or a SQL problem.</p><p> </p><p>tb_state has index for column state_area</p><p>tb_heat and childs have index for columns din_heat, point_heat</p><p> </p><p>tb_state - 27 rows</p><p>tb_heat  - From ‘2020-12-09 00:00:00’ to ‘2020-12-10 00:00:00’ (1day) – 4002 rows</p><p style="background:white"><span style="font-family:'times new roman' , serif;color:black"><br></span><b><span style="font-family:'courier new';color:blue">UPDATE </span></b><span style="font-family:'courier new';color:black">tb_heat </span><b><span style="font-family:'courier new';color:blue">SET </span></b><span style="font-family:'courier new';color:black">flg_insidecountry = ST_CONTAINS(foo.country, tb_heat.point_heat) </span><b><span style="font-family:'courier new';color:blue">FROM </span></b><span style="font-family:'courier new';color:black">(</span><b><span style="font-family:'courier new';color:blue">SELECT </span></b><span style="font-family:'courier new';color:black">ST_UNION(tb_state.area_state) </span><b><span style="font-family:'courier new';color:blue">as </span></b><span style="font-family:'courier new';color:black">country </span><b><span style="font-family:'courier new';color:blue">FROM </span></b><span style="font-family:'courier new';color:black">tb_state) </span><b><span style="font-family:'courier new';color:blue">AS </span></b><span style="font-family:'courier new';color:black">foo <br></span><b><span style="font-family:'courier new';color:blue">WHERE </span></b><span style="font-family:'courier new';color:black">tb_heat.din_heat >= </span><span style="font-family:'courier new';color:red">'2020-12-09 00:00:00' </span><b><span style="font-family:'courier new';color:blue">and </span></b><span style="font-family:'courier new';color:black">tb_heat.din_heat < </span><span style="font-family:'courier new';color:red">'2020-12-10 00:00:00'<br><br></span></p><p> </p><p>Regards,</p><p> </p><p>Liglio</p><p> </p></div></div></blockquote></div><br></div></div></div>