I have to execute ~6k update queries on a table through sql (No Hibernate/JDBC). Query is something like
UPDATE A
SET
some_id = 'value1'
WHERE
id = 'value2';
It takes too long to execute all these queries. Is there a way to improve the performance?
Create a temp table (containing just the value1 and value2 values) and populate it in bulk (ie, you can potentially do this with a single insert statement). Then do an update using a join between your existing table and the temp table.
Something like
INSERT INTO SomeTempTable(id, some_id)
VALUES (1,2), (3,4), (5,6), .......
UPDATE A
INNER JOIN
SomeTempTable ON A.id = SomeTempTable.id
SET
A.some_id = SomeTempTable.some_id;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With