473,503 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

a and (b or c) better than (a and b) or (a and c) ?

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
Jun 27 '08 #1
3 1407
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" <le**@neland.dkwrote in message
news:48***********************@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
Jun 27 '08 #2
>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.

Jun 27 '08 #3
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.
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
18803
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
3
2021
by: Muhd | last post by:
<usualDisclaimer>Please forgive me if this is in the wrong group, and if so, what is the right group.</usualDisclaimer> Let me start off by first saying im a newb. Ok, with that out of the way I...
24
3405
by: Faith Dorell | last post by:
I really don´t like C.You can write better programs in BASIC than in C, if you don´t like this language. I don´t understand how C became so popular, although much better programming languages...
43
3357
by: Rob R. Ainscough | last post by:
I realize I'm learning web development and there is a STEEP learning curve, but so far I've had to learn: HTML XML JavaScript ASP.NET using VB.NET ..NET Framework ADO.NET SSL
33
2523
by: Protoman | last post by:
Which is better for general-purpose programming, C or C++? My friend says C++, but I'm not sure. Please enlighten me. Thanks!!!!!
22
2684
by: JoeC | last post by:
I am working on another game project and it is comming along. It is an improvment over a previous version I wrote. I am trying to write better programs and often wonder how to get better at...
19
1849
by: Alexandre Badez | last post by:
I'm just wondering, if I could write a in a "better" way this code lMandatory = lOptional = for arg in cls.dArguments: if arg is True: lMandatory.append(arg) else: lOptional.append(arg)...
23
2329
by: mike3 | last post by:
Hi. (posted to both newsgroups since I was not sure of which would be appropriate for this question or how specific to the given language it is. If one of them is inappropriate, just don't send...
20
3043
by: mike3 | last post by:
Hi. (Xposted to both comp.lang.c++ and comp.programming since I've got questions related to both C++ language and general programming) I've got the following C++ code. The first routine runs in...
3
3563
by: Ryan Liu | last post by:
Hi, Is Async I/O (e.g. NetworkStream.Begin/End Read/Write) always better than synchronous I/O? At least as good? When I don't concern about easy or difficult to write code, should I always...
0
7087
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7334
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6993
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5579
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3156
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1514
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
383
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.