M
M
MilezNoles2021-07-16 14:54:38
MySQL
MilezNoles, 2021-07-16 14:54:38

How can I speed up an UPDATE query in MySQL?

There is a database for 357751 lines, you need to update all lines (UPDATE position SET allow = 'N' WHERE is_client IN ( 'Y', 'N' )). Initially, it took ~6.4 seconds, after removing the allow index, the update took 5.2 seconds. Is there any other way to speed up this query? The table is MyISAM, there are already 10 other indexes, but they do not concern the fields that are in the update (allow, I erased).

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Page-Audit.ru, 2021-07-16
@PageAuditRU

As an experiment
UPDATE position SET allow = 'N' WHERE allow <> 'N' AND is_client IN ( 'Y', 'N' )
+ add paired index (allow, is_client)

S
Spartak (Web-StyleStudio), 2021-07-16
@Spartak-2205

1. Create index for is_client
2. Replace query with

UPDATE `position` SET `allow`='N' WHERE `is_client`='Y'
, if there are no other values ​​in the is_client field except Y and N
P/S: check for duplicate indexes , check for unused indexes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question