|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Thursday, February 14, 2013 3:07 PM
Points: 27,
Visits: 24
|
|
Execution plan showed me merge join without sort.

Join was FULL JOIN with no equality in ON clause.
I can't understand this.
SQL Version is "Microsoft SQL Server 2008 (RTM) - 10.0.1600.22"
Recall script is as below.
CREATE TABLE tblA ( aa INT ) ; INSERT INTO tblA( aa ) SELECT TOP 10 ROW_NUMBER() OVER ( ORDER BY object_id, column_id ) FROM sys.all_columns ; CREATE TABLE tblB ( aa INT, bb INT ) ; DECLARE @ii INT = 1; BEGIN TRAN WHILE @ii <= 50 BEGIN INSERT INTO tblB( aa, bb ) SELECT TOP 2000 @ii, ROW_NUMBER() OVER ( ORDER BY object_id, column_id ) FROM sys.all_columns ; SET @ii = @ii + 1; END COMMIT TRAN
SELECT tblA.aa, tblb.bb FROM tblA FULL JOIN tblB ON tblA.aa < tblB.aa ;
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Today @ 9:37 AM
Points: 13,381,
Visits: 25,168
|
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 10:47 AM
Points: 37,729,
Visits: 29,990
|
|
It's an Ordered False operation. The thing is, that's actually a cross join. There's no join predicate at all. All rows qualify for that predicate so there's no ordering necessary, every row joins to every row.
Gail Shaw Microsoft Certified Master: SQL Server 2008, MVP SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter We stand on the bridge and no one may pass
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Thursday, February 14, 2013 3:07 PM
Points: 27,
Visits: 24
|
|
First of all, thank you Fritchey.
I recheck execution plan but I can't find any kind of sorting operations.
As you can see, table scan is used because there is no clustered index and sorting operator isn't be shown.
Isn't it weird?
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 10:47 AM
Points: 37,729,
Visits: 29,990
|
|
Not weird at all. There's no need to sort as all rows match all rows with that join you've specified. Look at the join columns in the merge join () = ()
This is essentially what your query boils down to:
SELECT tblA.aa, tblb.bb FROM tblA FULL OUTER JOIN tblB ON 1=1 For a merge join, the two inputs need to be sorted on the join column, except there is no join column, so any order whatsoever will do.
Gail Shaw Microsoft Certified Master: SQL Server 2008, MVP SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter We stand on the bridge and no one may pass
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Thursday, February 14, 2013 3:07 PM
Points: 27,
Visits: 24
|
|
Thank you GilaMonster
You makes me clear.
|
|
|
|