What is the excution order in Query like:
SELECT * FROM [users] WHERE [userid] = 50001 AND [username] = 'new user'
My question is what will be matched for first - [userid] or [username].
and so will affect the execution time.
Any suggesetion to improve this query will be appriciated.
The answer depends on the indexes that you make available to the SQL engine. If userid
is indexed but username
is not, the engine is likely to start with userid
; if username
is indexed but userid
is not, then the engine would probably start with the name; if both fields are indexed, the engine will search that index, and look up the rows by internal ids. Note that all of this is highly dependent on the RDBMS that you are using. Some engines would forego index searches altogether in favor of full table scans when the number of rows is low.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With