Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 More the specifications in a query more quicker wi

Author  Topic 

rsegecin
Yak Posting Veteran

82 Posts

Posted - 2007-09-01 : 14:06:45
Hello guys, I was wondering if I consult a database specifying the numbers in the query would be quicker than specify a string.
People who used to develop with asp.net noted that if you are using a “select case” statement with a number it will go straight to point and won’t compare every case, but if you are comparing with a string it will compare every single case until find one that matches the string. I think that a query to sql db calculate first the necessary fields giving preference to the numbers, because they would be quicker to match as the same as occurs in asp.net and it could increase the query’s performance. Suppose if in our table “user” had a field called age and my query had a specification of age equal to 18, it would already cut the range of users who has different age straight away, and if my query had another specification beside of it per example “surname = Donald” my query would even look at another Donalds that had different age increasing the performance quite a lot depending on the table’s size and users who had this specifications.

Thank you very much.

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-09-01 : 14:22:28
so what is exactly your question?

in the query you do
where age = someNumber and name = 'someName'

order is irrelevant.


_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

rsegecin
Yak Posting Veteran

82 Posts

Posted - 2007-09-01 : 14:33:04
Thank you for the quick reply spirit1. My question is if I specify in a query a number the response would be quicker than specifying a string.

Ideas are bullet proof.

Vendetta.
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-09-01 : 14:43:23
no not really...
reponse time depends on a lot of other things.
indexes, statistics, query optimizer, ...

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

rsegecin
Yak Posting Veteran

82 Posts

Posted - 2007-09-01 : 14:49:56
Thank you for answer spirit1. And If anyone has more details about it I would appreciate very much. Thanks.

Ideas are bullet proof.

Vendetta.
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-09-01 : 15:10:42
maybe you should tell us your requirement...

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

rsegecin
Yak Posting Veteran

82 Posts

Posted - 2007-09-01 : 15:24:20
I was wondering, as the sql won't cut the range of his source through one the specified value in the query, how he does the evaluation of a query.

Ideas are bullet proof.

Vendetta.
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-09-01 : 15:41:26
well after you run the query for the first time, sql server creates an optimal execution plan (most of the time)
based on the indexes and how up to date they are, referential integrity etc...
during the building of this plan sql tries various combinations of data retreival each having it's own cost.
query optimizer then takes the plan with the least cost and uses it to retreive data.

does that answer your question?

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

rsegecin
Yak Posting Veteran

82 Posts

Posted - 2007-09-01 : 15:49:28
yes it elucidated to me a more how it works, thank you spirit1.

Ideas are bullet proof.

Vendetta.
Go to Top of Page
   

- Advertisement -