SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Table Access Order


Table Access Order

Author
Message
Andre Guerreiro
Andre Guerreiro
SSCrazy
SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)

Group: General Forum Members
Points: 2209 Visits: 1515
SQL Kiwi (9/23/2011)Adam (Machanic) would no doubt want me to encourage you to share a link to SQLblog instead (traffic = advertising = pays the hosting bills) but I understand that is not always possible.


I'm currently starting a new SQL blog(it's very basic now and in Portugues) and I'll be adding links to your blog, Paul Randall's, Kimberly Tripp's, GilaMonster's and others if that's ok.

It's sad that some people will copy an article reinventing the wheel and stealing the credit instead of sending the reader to the right place and giving credits to those who are due.

I'm just a learner. BigGrin

Best regards,

Best regards,

Andre Guerreiro Neto

Database Analyst
http://www.softplan.com.br
MCITPx1/MCTSx2/MCSE/MCSA
Paul White
Paul White
SSC-Dedicated
SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)

Group: General Forum Members
Points: 34238 Visits: 11359
codebyo (9/24/2011)
I'm currently starting a new SQL blog(it's very basic now and in Portugues)...

Looks good! I am also a fan of Fabiano Amorim by the way.



Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
Gianluca Sartori
Gianluca Sartori
SSC-Insane
SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)

Group: General Forum Members
Points: 23043 Visits: 13362
Great question, Paul!
I got it wrong, as usual. :-)
I was highly tempted to pick the correct answer based on how the hash operator works, but I suspected there was a "trick" somewhere and I didn't listen to my brain.

Anyway, I have a doubt and I'm sure you can clear things up.

Here's a small test I ran:


SET STATISTICS IO ON

-- Changed to temp tables in order to recognize the table names
-- in STATISTICS IO output
CREATE TABLE #A (a INT NOT NULL)
CREATE TABLE #B (b INT NOT NULL)

SELECT COUNT_BIG(*)
FROM #A
LEFT HASH JOIN #B ON [#B].b = [#A].a

SELECT COUNT_BIG(*)
FROM #A
RIGHT HASH JOIN #B ON [#B].b = [#A].a



Output:


Warning: The join order has been enforced because a local join hint is used.

--------------------
0

(1 row(s) affected)

Table 'Worktable'. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table '#A__000000024106'. Scan count 1, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Warning: The join order has been enforced because a local join hint is used.

--------------------
0

(1 row(s) affected)

Table 'Worktable'. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table '#B__000000024107'. Scan count 1, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
Table '#A__000000024106'. Scan count 1, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.


As you can see, in this case STATISTICS IO returns objects in reverse order. Is this sensible and/or guaranteed/documented?
I couldn't find anything on the subject.

--Gianluca Sartori

How to post T-SQL questions
spaghettidba.com
@spaghettidba
Paul White
Paul White
SSC-Dedicated
SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)SSC-Dedicated (34K reputation)

Group: General Forum Members
Points: 34238 Visits: 11359
Gianluca Sartori (9/30/2011)
As you can see, in this case STATISTICS IO returns objects in reverse order. Is this sensible and/or guaranteed/documented? I couldn't find anything on the subject.

I don't know the answer to that; however I'm pretty sure it isn't documented or guaranteed.



Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
Gianluca Sartori
Gianluca Sartori
SSC-Insane
SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)

Group: General Forum Members
Points: 23043 Visits: 13362
SQL Kiwi (9/30/2011)
Gianluca Sartori (9/30/2011)
As you can see, in this case STATISTICS IO returns objects in reverse order. Is this sensible and/or guaranteed/documented? I couldn't find anything on the subject.

I don't know the answer to that; however I'm pretty sure it isn't documented or guaranteed.


Thank you, Paul.
I did a couple of tests and turns out that it was just a coincidence. Well, not entirely: the order of the tables in the STATISTICS IO output is often very similar to the execution order in the query plan, but it starts diverging when tables are accessed more than once, or parallelism kicks in, or... many other things.

--Gianluca Sartori

How to post T-SQL questions
spaghettidba.com
@spaghettidba
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search