Hi,
First off, here is how I generally write my stored procedures (sprocs)
I create a view, add and join all the tables and do as much configuration as is possible in a view.
Then copy/paste to Query Analyser and format it nicely, drop all the junk and write the complex stuff.
What I always do is re-arrange the FROM clause into something readable.
And I always check what the Estimated Execution Plan is before/after I re-write the FROM clause. And it ALWAYS seems to change astronomically...
Today, a query went from having a few hashes and a few nested loops to having lots of team hash joins (??) and lots of stuff about parallel execution (well, it sounds good, but ??? again).
All because I re-arranged the FROM clause!!
I always re-arrange my FROMs to..
See the three stars? That's where Enteprise manager seems to like to put the other joins, in the middle of other joins. Which I find makes the query almost un-readable.
I time both queries, I've never seen any appreciable speed difference. The example for today took 49 seconds regardless, even though the estimated subtree cost was
40 before rearrange
58 after rearrange
Not that numbers mean anything except a ~50% difference to me.
Does anybody know where I can find a good reference guide to what's going on here?
I'd really like to know if any of this can really benefit performence. All my report queries take 1-3 mins on a dual PIII 1.2 Ghz Dell with 512Mb of RAM. I have no idea whether this is good/bad/awfull. Our only comparison is the access system it replaced and we kinda beat it's "go and have several cups of tea, we're not joking this will take until the morning" performance.
Cheers,
Jim.
First off, here is how I generally write my stored procedures (sprocs)
I create a view, add and join all the tables and do as much configuration as is possible in a view.
Then copy/paste to Query Analyser and format it nicely, drop all the junk and write the complex stuff.
What I always do is re-arrange the FROM clause into something readable.
And I always check what the Estimated Execution Plan is before/after I re-write the FROM clause. And it ALWAYS seems to change astronomically...
Today, a query went from having a few hashes and a few nested loops to having lots of team hash joins (??) and lots of stuff about parallel execution (well, it sounds good, but ??? again).
All because I re-arranged the FROM clause!!
I always re-arrange my FROMs to..
Code:
FROM <table1>
INNER/OUTER JOIN <table2> *** ON <Join Criteria>
<More and More Joins>
See the three stars? That's where Enteprise manager seems to like to put the other joins, in the middle of other joins. Which I find makes the query almost un-readable.
I time both queries, I've never seen any appreciable speed difference. The example for today took 49 seconds regardless, even though the estimated subtree cost was
40 before rearrange
58 after rearrange
Not that numbers mean anything except a ~50% difference to me.
Does anybody know where I can find a good reference guide to what's going on here?
I'd really like to know if any of this can really benefit performence. All my report queries take 1-3 mins on a dual PIII 1.2 Ghz Dell with 512Mb of RAM. I have no idea whether this is good/bad/awfull. Our only comparison is the access system it replaced and we kinda beat it's "go and have several cups of tea, we're not joking this will take until the morning" performance.
Cheers,
Jim.