mercredi 3 mars 2021

Which is faster in MYSQL UPDATE, IF statement or CASE statement

I'm testing query's speed in mysql 5.7.

1.

UPDATE tablefortest SET testbit = CASE WHEN TEST_YN = 'Y' THEN '1' ELSE '0' END;
    UPDATE tablefortest SET testbit = IF(TEST_YN LIKE 'Y', '1', '0');
    

    Both query take a time 0.8sec ~ 1.1sec. Sometimes IF statement is faster and the other times CASE statement is faster. I wonder the difference between two queries's running principle. And how can I make query speed faster???

    Thanks.

    Aucun commentaire:

    Enregistrer un commentaire