Sql-server – Tool to view intermediate query results

sql servertools

I am using SQL Server 2008 Express edition and I've worked two days on a problem where seems to be a cross join in running a query.

I would want to know the set returned per join operation visually.

Is there any tool that can give you intermediate query results? I couldn't find one on Google.

EDIT

I solved this problem with the oldest trick in the book, manually running the query before joining to see where exactly the problem of cross join was happening. And found out that there was a mapping DB that sent 3 results for a join instead of just one (because it needed two conditions for a proper inner join, instead of one).

Best Answer

There are none that I know of that will show you the exact results - maintaining hooks so such tools could spy on what is going on would probably be inefficient in production (no doubt MS can do it in their development builds). While intermediate results aer sometimes dumped to temporary tables for further processing, they are often never materialised as a whole unit instead being streamed between parts of the query engine as they are produced.

If you run the query in SQL Server Management Studio, you can request that the query plan used is output. While that will not give you the entire intermediate results it will show you what comparisons are being performed and approximately how many rows are effectively output at each step - if you have a Cartesian product between a pair of large tables this should hopefully make it clear where in the process this happens.

For more specific help you'll need to add more detail to your question (please add it to the question, not as comments here, then there is better visibility of the new information for people who visit this page later):

  • What makes you think there is a cross join happening? Are you getting many more rows than you expect then whittling them down with a DISTINCT? If it is just that the query is running very slowly and spinning the CPU then it may instead be a index use problem or a correlated subquery that is resulting in a scan per output row (a situation that can actually be worse than a cross join performance wise)
  • Could you provide a copy of the query and relevant table structures?
  • What size of data are we talking about?