0

will there be any performance differences between these 2 queries?

SELECT * FROM cats WHERE cats_id = '1'
SELECT * FROM cats WHERE cats_name = 'cats_name'

regards

2
  • 1
    why do you want know? what are column types and sizes? are the columns indexed? Commented Aug 16, 2011 at 13:22
  • In addition to the indexing it also depends on the datatypes - _id usually implies a numeric value - but you've got a quoted string which might confuse the optimizer Commented Aug 16, 2011 at 14:22

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

i want to keep some data out of mysql. if there is not much difference i want to go for the second option. 'cats_name' is varchar 100 and got index.
1

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.