Let’s say i have a mysql database table ‘article’ with the following fields: id, title, url, views
I have the field title marked with a FULLTEXT index and the field url marked with a UNIQUE index.
My question is, if i do an ordinary update something like:
UPDATE 'article' SET views = views + 1 WHERE id = {id}
…will this result in a update of the mysql table indexes?
Is it safe (from speed point of view) to keep the field views in the table article or maybe i should create a separate table, let’s say, article_stats with the following fields: article_id, views ?
Yes,
UPDATEstatements update indexes. MySQL manages indexes automatically – you never need to worry about updating them manually or triggering an update. If you are asking whether that particularUPDATEwill change your indexes which don’t include theviewscolumn – no, it wont. Only related indexes get updated.Keeping a
viewscolumn is fine, unless you need to track extra information about each view (when it occurred, user who made the view, etc)Your SQL does contain a syntax error, however. You can’t quote table names like
'article'. If you need to quote a table name (e.g. if it contains a SQL reserved word), then use backticks like this: