473,387 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Selecting MAX (Date) - Performance Question

I have the following function(s) that each joins an active record with
it's most recent record in an audit trail table, to show differences.
I've perused the execution plans for 2 versions of this function in QA
and it seems to me that the two versions execute identically - that is,
the addressing the sub-query of the WHERE clause with either IN or =
results in the same execution plan.

Does this seem plausible or did I misinterpret something in QA?

---

ALTER FUNCTION Function9()
RETURNS TABLE
AS RETURN
(
SELECT ID, Numb, Name, Q.Diff_ID, Q.Diff_Numb, Q.Diff_Name,
FROM tblQuestion INNER JOIN
(
SELECT ID AS Diff_ID, Numb AS Diff_Numb, Name as Diff_Name

FROM tblQuestion_Audit
WHERE AuditDate IN (SELECT MAX(AuditDate) FROM tblQuestion_Audit)
) AS Q
ON dbo.tblItem.ID = Q.Diff_ID

)

ALTER FUNCTION Function10()
RETURNS TABLE
AS RETURN
(
SELECT ID, Numb, Name, Q.Diff_ID, Q.Diff_Numb, Q.Diff_Name,
FROM tblQuestion INNER JOIN
(
SELECT ID AS Diff_ID, Numb AS Diff_Numb, Name as Diff_Name

FROM tblQuestion_Audit
WHERE AuditDate = (SELECT MAX(AuditDate) FROM tblQuestion_Audit)
) AS Q
ON dbo.tblItem.ID = Q.Diff_ID

)

May 3 '06 #1
3 1889
Beowulf (be*****************@hotmail.com) writes:
I have the following function(s) that each joins an active record with
it's most recent record in an audit trail table, to show differences.
I've perused the execution plans for 2 versions of this function in QA
and it seems to me that the two versions execute identically - that is,
the addressing the sub-query of the WHERE clause with either IN or =
results in the same execution plan.

Does this seem plausible or did I misinterpret something in QA?


It seems very plausible.

I nevertheless prefer the version with =. But that is merely because
it's easier to read and understand.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
May 3 '06 #2
Erland Sommarskog wrote:
Beowulf (be*****************@hotmail.com) writes:
I have the following function(s) that each joins an active record with
it's most recent record in an audit trail table, to show differences.
I've perused the execution plans for 2 versions of this function in QA
and it seems to me that the two versions execute identically - that is,
the addressing the sub-query of the WHERE clause with either IN or =
results in the same execution plan.

Does this seem plausible or did I misinterpret something in QA?
It seems very plausible.


So, the SQL Server query optimizer is smart enough to figure out that
the sub-query in the WHERE clause will return only a single value and is
able to figure out that WHERE x IN (a) is the same as WHERE x = a.
That's pretty cool.
I nevertheless prefer the version with =. But that is merely because
it's easier to read and understand.


Thanks for the input. I certainly agree.
May 5 '06 #3
Beowulf (be*****************@hotmail.com) writes:
So, the SQL Server query optimizer is smart enough to figure out that
the sub-query in the WHERE clause will return only a single value and is
able to figure out that WHERE x IN (a) is the same as WHERE x = a.
That's pretty cool.


That's a fairly trivial exercise for the optimizer, I'd say. :-)

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
May 5 '06 #4

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

Similar topics

18
by: Robin Lawrie | last post by:
Hi again, another problem! I've moved from an Access database to SQL server and am now having trouble inserting dates and times into seperate fields. I'm using ASP and the code below to get the...
4
by: remote89 | last post by:
Hi experts, I have been trying to limit the table rows in the following situation, any suggestions will be appreciated. we have table called tempTb has columns id, c_id, c_name, rating, date...
3
by: larry mckay | last post by:
anyone have the code to select and listview item or row (subitems) after a doubleclick event from a listview. *** Sent via Developersdex http://www.developersdex.com *** Don't just participate...
42
by: Dooglo | last post by:
I'm new VB and programming all together, but I'm getting he hang of it. My question is; I'm writting a program to figure square feet and yards when the user inputs "Length in feet and inch (...
28
by: romy | last post by:
What's the easiest way to verify the user had entered a valid date ?
1
by: vunderusaf | last post by:
I have a listbox on a form that is selecting using named FinalQuery: SELECT ., ., . FROM FinalQuery; Now I have a text field with a date on this form and I'd like to use that date as the...
11
by: shsandeep | last post by:
I used the following query to retrieve the date in dd-mon-yyyy format. db2 => SELECT RTRIM(CHAR(DAY(COVG_TYP_STRT_DT))) || '-' || RTRIM(MONTHNAME(COVG_TYP_STRT_DT)) || '-' ||...
1
by: archcool | last post by:
I want to display new empty text fields within the same form after selecting an option from a combobox. here is the form Filter by:todays date,from date ---- in a combobox when from date is...
2
by: sdanda | last post by:
Hi , Do you have any idea how to improve my java class performance while selecting and inserting data into DB using JDBC Connectivity ......... This has to work for more than 8,00,000...
11
by: Chris | last post by:
Hi, I'm kind of new to the more involved workings of javascript, and am having a few problems. My problem is this: I am working with a CMS which is including various javascrip files in the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.