[Solved] MS SQL cross join performance evaluation

EverSQL Database Performance Knowledge Base

MS SQL cross join performance evaluation

I am not a DBA and am new to MS SQL...

I would like to know if an sql statement is performing poorly or not, more specifically, I would like to know whether a cross join select is performing poorly or not. Not in comparison to another select statement which may be more efficient if it is a reformulation of the original, but in comparison to itself (I understand this is a bit vague...).

For example I have the following table:

table columns

where my table has > 100K entries.

I run the following select:

select * from dbo.pcopy as p1, dbo.pcopy as p2;

It takes upwards of a day to complete. This, perhaps, is fine, but how can I ascertain this???

I have been shown the following select but cannot understand how to derive poor perforamce metrics from it:

select * from sys.dm_exec_query_Stats

How to optimize this SQL query?

The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:

  1. Description of the steps you can take to speed up the query.
  2. The optimal indexes for this query, which you can copy and create in your database.
  3. An automatically re-written query you can copy and execute in your database.
The optimization process and recommendations:
  1. Avoid Selecting Unnecessary Columns (query line: 2): Avoid selecting all columns with the '*' wildcard, unless you intend to use them all. Selecting redundant columns may result in unnecessary performance degradation.
The optimized query:
SELECT
        * 
    FROM
        dbo.pcopy AS p1,
        dbo.pcopy AS p2

Related Articles



* original question posted on StackOverflow here.