Re: Update query takes too long time
"Hey there! The issue seems to stem from how the subquery in your `UPDATE` statement is being executed. When using a correlated subquery like `(SELECT erstelltam FROM vorgang WHERE KEY1 = belegnr)`, MySQL evaluates it for every row being updated, which can be extremely slow, especially with larger tables or when updating multiple rows.
To optimize this, you can try rewriting the query to avoid the correlated subquery. For example, use a JOIN instead:
```sql
UPDATE belegkopf
JOIN vorgang ON vorgang.KEY1 = belegkopf.belegnr
SET belegkopf.lieferdatumist = vorgang.erstelltam
WHERE ISNULL(belegkopf.i4)
LIMIT 5;
```
This approach allows MySQL to process the rows more efficiently by leveraging the JOIN, which is typically faster than repeatedly running a subquery. Also, ensure you have proper indexing in place, particularly on `belegkopf.belegnr` and `vorgang.KEY1`, as it can make a big difference in performance.
Let me know if this helps or if you’re still experiencing issues—I’d be happy to dig deeper!"
Subject
Written By
Posted
Re: Update query takes too long time
January 19, 2025 03:40PM
Sorry, only registered users may post in this forum.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.