Hi guys. Assuming SQL Server can choose the appropriate execution plan for a Query/SP — How can I see how many execution plans are exists for a specific Query/SP ?
@JackDouglas Yes that's what I meant. Does a simple select with a few joins can have large amount of possible plans ? ( I thought there're a few plans , not large amount of plans....)
optimizers invariably have a strategy for narrowing down the list of plans they will cost because the cost of costing all possible plans is otherwise going to be higher than the cost of executing them, if you see what I mean
what's your reason for wanting to see the plans other than the chosen one?
The purpose is just for learning. I've learned that if SP do @declare @v=something and later I do in the SP : select where myIndexedColumn=@v then , the index will be used as scan and not via seek so it must chose a different execution plan. I just wanted to see what other possibilities it has to chose from.
@RoyiNamir No that's not true. It impacts cardinality estimates, which affects the decision to seek or scan, but it doesn't prevent use of the index.
I don't think a 'seek' is impossible, it's just that cardinality estimates may be 'wrong' enough that it chooses a scan when a seek would really be faster