When entering the page, the following code is triggered.

$post = $pdo->prepare('SELECT * FROM app WHERE id = ? AND url = ?'); $post->execute(array($id,$url)); $game = $post->fetch(PDO::FETCH_LAZY); $views = $pdo->prepare('UPDATE app SET views=views+1 WHERE id = ?'); $views->execute(array($id)); 
  1. If several users simultaneously log into the page, will the views field be correct? That is, 10 people opened the page at the same time. Then the views field will refresh 10 times in the order of the queue?
  2. On account of the first request. If I set the index to the url field, will the selection be faster?
  • 1. Yes, 2. Yes: D - Invision
  • one
    1. Yes, correctly. 2. And on one id you have many records? if yes, then a composite index id, url is needed. Two indexes cannot be used simultaneously by mysql, only one will be selected. so it makes sense in this one index and include both fields - Mike
  • @Mike ~ 500, sampled by url made for guarantees, all of a sudden some wrong id will choose - emtecif
  • one
    @emtecif Ie id is less unique. then you don't need an index on the url, only adding records will slow down, but will not be used for actual search - Mike
  • @Mike how to understand more or less unique?) Id because in any case unique, 1,2,3, etc, it will not be repeated. - emtecif

1 answer 1

Reply from comments from Mike

  1. Yes, right.
  2. And on one id you have a lot of records? If so, then a composite index id , url is needed. Two indexes cannot be used simultaneously by mysql, only one will be selected. Therefore, it makes sense to this one index and include both fields.