开发者

Mysql Where Query Performance?

will there be any performance differences between these 2 queries?

SELECT * FROM cats WHERE cats_id = '开发者_Python百科1'
SELECT * FROM cats WHERE cats_name = 'cats_name'

regards


That depends on whether there is an index on the fields.

If the cats_id field is a primary key field, and cats_name is a varchar field with no index on it, the first query will definitely be faster.

If you need to improve performance on the cats_name field, consider creating an index on it.


It all depends on whether the table column is indexed or not (explanation on selectivity).


It really depends on:

a) the relative sizes (number of entries) of those two columns

b) whether the columns are indexed

If they're both indexed and of ~ the same size the query speed will be approx the same. If one is indexed and the other isn't, the indexed one will be (much) faster. If neither is indexed, it will depend on where in the table the searched-for entry is: which one occurs first will be quickest.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜