それはおそらく本当に簡単な質問ですが、私はそれに対する答えを自分で見つけることができませんでした:
更新したい行をカーソルで指している場合、UPDATEステートメントを発行するよりも速い方法はありますか?
DECLARE current_id, current_product_id, current_price, current_position INT DEFAULT 0;
DECLARE new_position INT DEFAULT 0;
DECLARE cursor_offers CURSOR FOR
SELECT id, product_id, price, position FROM offers
ORDER BY product_id, price ASC;
OPEN cursor_offers;
offers_loop: LOOP
FETCH cursor_offers INTO current_id, current_product_id, current_price, current_position;
# Loop control omitted
# Conditional statements omitted, that calculate new_position
UPDATE offers SET position = new_position WHERE id = current_id; # <--- This line
END LOOP offers_loop;
MySQLにはすでにカーソルを介してその行へのポインターがあるため、UPDATEステートメントでそれを再度見つけるのは非効率的であると思います。