Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Why table scan?
Message
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Why table scan?
Versions des environnements
SQL Server:
SQL Server 2000
Divers
Thread ID:
01293823
Message ID:
01293823
Vues:
66
I don't get it.
Maybe I missing something very obvious or I didn't read this part of BOL, but almost same queries give me different results in execution plan.
In one table I have PK clustered, in other I have regular index. When I execute first query execution plan shows INDEX SEEK when I execute second one execution plan shows TABLE SCAN.
The version of SQL Server is obsolete. I test this on both 2000 and 2005, that is why I think I'm missing something.
CREATE DATABASE Test
GO
USE Test
GO
Create TABLE Test1 (Fld1 int, Fld2 varchar(200)
CONSTRAINT PK_Tets1
    PRIMARY KEY CLUSTERED (Fld1)
)

Create TABLE Test2 (Fld1 int, Fld2 int, Fld3 int, Fld4 varchar(200))
CREATE INDEX IX_Test2 ON Test2 (Fld1, Fld2, Fld3)
GO

--- This gives me INDEX SEEK for Test2
SELECT Test1.*
FROM Test1
LEFT JOIN Test2 ON Test1.Fld1 = Test2.Fld1 AND Test2.Fld2 = 14 AND Fld3 = 1
WHERE Test1.Fld1 > 0

--- This gives me TABLE SCAN for Test2
SELECT * -- Fields from both tables.
FROM Test1
LEFT JOIN Test2 ON Test1.Fld1 = Test2.Fld1 AND Test2.Fld2 = 14 AND Fld3 = 1
WHERE Test1.Fld1 > 0
GO
USE Master
DROP DATABASE Test
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform