UPDATE FROM with JOIN (Great table performance) Postgresql?

I am trying to execute the following query to execute with reasonable performance:

UPDATE order_item_imprint SET item_new_id = oi.item_new_id
      FROM order_item oi
      INNER JOIN order_item_imprint oii ON oi.item_number = oii.item_id          

Currently, it does not complete within 8 days, so we killed him. The request explanation is as follows:

Query Graphical Explaination

Merge Join  (cost=59038021.60..33137238641.84 rows=1432184234121 width=1392)
Merge Cond: ((oi.item_number)::text = (oii.item_id)::text)
  ->  Nested Loop  (cost=0.00..10995925524.15 rows=309949417305 width=1398)
        ->  Index Scan using unique_order_item_item_number on order_item oi  (cost=0.00..608773.05 rows=258995 width=14)
        ->  Seq Scan on order_item_imprint  (cost=0.00..30486.39 rows=1196739 width=1384)
  ->  Materialize  (cost=184026.24..198985.48 rows=1196739 width=6)
        ->  Sort  (cost=184026.24..187018.09 rows=1196739 width=6)
              Sort Key: oii.item_id
              ->  Seq Scan on order_item_imprint oii  (cost=0.00..30486.39 rows=1196739 width=6)

I have indexes for both tables, and I ensured that the comparison fields have the same type and size. Now I'm trying to change the configuration of the postgresql server, I hope it helps, but I'm not sure what it will be.

The order_item_imprint table has a size of about 1.1 million with a disk space of 145 MB, and the order_item table is approximately the third size.

The main goal - I need to be able to run this along with several other requests within a few hours of the maintenance window.

.

+3
2

, pgsql

, , , order_item_inprint.

, :

= 1432184234121

1,4 , . order_item_inprint , .

+6

, pgsql :

UPDATE order_item_imprint SET item_new_id = oi.item_new_id 
FROM order_item oi where oi.item_number = order_item_imprint.item_id

, , :

Hash Join  (cost=1.38..5.73 rows=48 width=1407)
  Hash Cond: ((order_item_imprint.item_id)::text = (oi.item_number)::text)
  ->  Seq Scan on order_item_imprint  (cost=0.00..3.63 rows=63 width=1399)
  ->  Hash  (cost=1.17..1.17 rows=17 width=23)
        ->  Seq Scan on order_item oi  (cost=0.00..1.17 rows=17 width=23)
+4

Source: https://habr.com/ru/post/1753894/


All Articles