Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 how to calculate query cost using index query?

Author  Topic 

askmydear
Starting Member

1 Post

Posted - 2009-04-02 : 08:22:43
Hi friends,

i'am beginner in SQL server 2005. i wrote query using index to link three tables.

here is code:

select a.name,b.title from actors as a with(index=actors_actorid_NC),movies as b with (index=movies_movieid_NC) ,movies2actors as c with (index=movies2actors_actorid_NC) where (c.actorid>5000 and c.actorid<6000) and (c.actorid=a.actorid) and (c.movieid=b.movieid)


i want to calculate query cost for above query.

please any one help me?

Thanks in advance.

theboyholty
Posting Yak Master

226 Posts

Posted - 2009-04-02 : 09:10:53
On your top menu, click Query > Include Actual Execution Plan and then run your query.

That gives you all kinds of metrics regarding your query. Understanding it? Well that's another matter but if you hover over the first item on your execution plan, the 'Estimated Subtree Cost' is probably going to be your key stat. Trick is getting it as low as possible.

Go to Top of Page

darkdusky
Aged Yak Warrior

591 Posts

Posted - 2009-04-02 : 09:22:33
Compare the execution plan for your query with the execution plan for the query without the index hints, i.e after removing with(index=actors_actorid_NC) and with (index=movies2actors_actorid_NC). You may find it uses the indexes anyway. Not using the hint leaves the optimiser free to choose a faster method if it is available.

http://blog.sqlauthority.com/2009/02/07/sql-server-introduction-to-force-index-query-hints-index-hint/
Go to Top of Page
   

- Advertisement -