Skip to content
Advertisement

How to optimize an increment query in Laravel?

in a Laravel project I am incrementing views based on session I am using it like this:

JavaScript

Is there any way to optimize this? I have activated the slow queries log and I am getting results like this one:

JavaScript

How to optimize this? Any suggestions?

Edit: Adding a manual EXPLAIN update statement:

JavaScript

Result: 1 row in set (0.01 sec)

id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 UPDATE posts NULL range PRIMARY PRIMARY 4 const 1 100.00 Using where

Advertisement

Answer

  • Don’t use ENGINE=MyISAM; switch to InnoDB.

  • Beware of other queries (in other connections) that are touching this table for a long time.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement