-
Optimization: Subqueries and backreferences?
I wonder if somebody could give me advice on SQL Server7-specific handling of subqueries and backreferences...
What is a) more efficient, and b) faster:
1. IF (DATEDIFF(minute, (
SELECT tLastHitTime
FROM (
SELECT *
FROM tblSession
WHERE tSessionID = 'abcd1234'
) as sess), getDate()) < 30)
SELECT *
FROM sess
or:
2. IF (DATEDIFF(minute, (
SELECT tLastHitTime
FROM tblSession
WHERE tSessionID = 'abcd1234'
) as sess), getDate()) < 30)
SELECT *
FROM tblSession
WHERE tSessionID = 'abcd1234'
In the first example, 2 SELECT statements (line 2 & line 8) refer to derived table by its alias 'sess'. In the 2nd example, both queries are independant, yet identical...
I wonder if SQLServer is "smart" enough to execute identical queries only once, and then reuse the resulset (e.g. derived table), or it requires explicit references (such as alias) in order to do so...
TIA,
Alex
-
Optimization: Subqueries and backreferences? (reply)
Why don't you testit and see!
------------
Alex at 5/17/00 5:36:49 PM
I wonder if somebody could give me advice on SQL Server7-specific handling of subqueries and backreferences...
What is a) more efficient, and b) faster:
1. IF (DATEDIFF(minute, (
SELECT tLastHitTime
FROM (
SELECT *
FROM tblSession
WHERE tSessionID = 'abcd1234'
) as sess), getDate()) < 30)
SELECT *
FROM sess
or:
2. IF (DATEDIFF(minute, (
SELECT tLastHitTime
FROM tblSession
WHERE tSessionID = 'abcd1234'
) as sess), getDate()) < 30)
SELECT *
FROM tblSession
WHERE tSessionID = 'abcd1234'
In the first example, 2 SELECT statements (line 2 & line 8) refer to derived table by its alias 'sess'. In the 2nd example, both queries are independant, yet identical...
I wonder if SQLServer is "smart" enough to execute identical queries only once, and then reuse the resulset (e.g. derived table), or it requires explicit references (such as alias) in order to do so...
TIA,
Alex
-
Optimization: Subqueries and backreferences? (reply)
------------
Testit at 5/18/00 9:00:46 AM
Why don't you testit and see!
------------
Because the machine where SQL server is running on is wickedly fast - the execution time for both queries is 0 ticks. I was wondering if anybody with extensive SQL Server7 knowledge/experience could answer this theoretical question...
TIA,
Alex
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|