dimanche 28 février 2016

In SQLite/WebSQL, will BEGIN go through entire table again to find the updated row even though the TRIGGER knows where it is?

Below I have a users table and I want it so that every time a row's avatar changes to a different value, the same row's downloadavatar is set to 1.

CREATE TABLE users (
   id UNIQUE TEXT,
   avatar TEXT,
   downloadavatar INTEGER
)

CREATE TRIGGER update_users_downloadavatar AFTER UPDATE OF avatar ON users WHEN old.avatar!=new.avatar
BEGIN
    UPDATE users SET downloadavatar=1 WHERE id=old.id;
END

The SQL above does just that. My question is will it result in searching the entire users table for the row that meets the WHERE condition despite the TRIGGER already knowing where it is? If yes, how can I rectify this inefficiency?

Aucun commentaire:

Enregistrer un commentaire