Mysql count vs mysql SELECT, which one is faster?

后端 未结 5 972
粉色の甜心
粉色の甜心 2020-12-17 16:41

If I want to do a check a name, I want to see how many rows/name exists in the \"username\" column under users table. Lets say thousands ... hundred of thousands, should I u

5条回答
  •  时光取名叫无心
    2020-12-17 16:59

    Try all three and use whichever preforms the best. If they all preform around the same this is an and example of premature optimization and you should probably just use whichever one you feel most comfortable with and tweak it later if necessary. If you superstitious you could also consider using count(1) which I have been told could performance advantages as well.

    I would say you should use a select top 1, but your checking a username which is probably an indexed unique column so theoretically count should preform just as well considering there can only be one.

提交回复
热议问题