vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| When I use "sql server enterprise manager" gui and write an expression like where a=1 and (b=2 or c=3) it gets transformed into where (a=1 and b=2) or (a=1 and c=3) Is it only because it is easier to display the query in the query-design table? Or is it actually a more efficient method? I.e, when I take the finished query and paste it into my asp-source, should I keep the transformed query, which is larger, or transform it back to the way I originally wrote it? Leif |
| |||
| > Is it only because it is easier to display the query in the query-design > table? Yes, I believe EM changes the query to facilitate GUI display. > Or is it actually a more efficient method? SQL is declarative rather than procedural. The optimizer in the database engine will try to generate the most efficient plan regardless of how the query is expressed. If you compare the execution plans of the 2 queries in Query Analyzer, I would expect both to be identical because they are semantically identical. -- Hope this helps. Dan Guzman SQL Server MVP http://weblogs.sqlteam.com/dang/ "Leif Neland" <leif@neland.dk> wrote in message news:482c078c$0$15887$edfadb0f@dtext01.news.tele.d k... > When I use "sql server enterprise manager" gui and write an expression > like > > where a=1 and (b=2 or c=3) > > it gets transformed into > > where (a=1 and b=2) > or (a=1 and c=3) > > Is it only because it is easier to display the query in the query-design > table? > > Or is it actually a more efficient method? > > I.e, when I take the finished query and paste it into my asp-source, > should I keep the transformed query, which is larger, or transform it back > to the way I originally wrote it? > > Leif |
| |||
| >> WHERE A = 1 AND (B = 2 OR C = 3) it gets transformed into WHERE (A = 1 AND B = 2) OR (A = 1 AND C = 3) << I think that is weird, too. It should not make any difference because the optimizer will figure it out. Hell, procedural languages can optimize simple predicates like that easier these days. For what it is worth, that is the Canonical Disjunctive Form in formal logic and you can probably Google some very boring articles about it. |
| ||||
| > When I use "sql server enterprise manager" gui and write an expression like > > where a=1 and (b=2 or c=3) > > it gets transformed into > > where (a=1 and b=2) > * *or *(a=1 and c=3) > > Is it only because it is easier to display the query in the query-design > table? I believe this to be the case. > Or is it actually a more efficient method? They should be identical. > I.e, when I take the finished query and paste it into my asp-source, > should I keep the transformed query, which is larger, or transform it > back to the way I originally wrote it? I would keep your original logic, if for no other reason than it probably makes more sense to you the way it is written. You should not see any difference in performance, and certainly no difference in results. |
| Thread Tools | |
| Display Modes | |
|
|