Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
WHERE IN approach
Message
De
28/02/2017 17:16:54
 
 
À
28/02/2017 15:38:29
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2014
OS:
Windows 8.1
Network:
Windows Server 2012
Divers
Thread ID:
01648591
Message ID:
01648650
Vues:
34
>It is not a fixed rule.
>In some cases, the engine realizes the indexes and generates a good plan, in practice flowing the two indices and makes a union at the end.
>On next example, the simplicity allows the engine to generate a good plan,
>but if you compare the plans you see that the one with union is simpler.
>
>
>DROP table #TT 
>create table #TT (AA INT PRIMARY KEY, BB INT)
>CREATE INDEX IK ON #TT (BB)
>
>INSERT #TT	SELECT	2*ROW_NUMBER() OVER (ORDER BY (SELECT NULL))
>				,	3*ROW_NUMBER() OVER (ORDER BY (SELECT NULL))
>				FROM sys.objects A,sys.objects B
>
>SELECT * FROM #TT WHERE AA = 4 OR BB = 3000
>
>SELECT * FROM #TT WHERE AA = 4
>	UNION
>	SELECT * FROM #TT WHERE BB = 3000
>
>SELECT * FROM #TT WHERE AA = 4 OR BB = 6
>
>SELECT * FROM #TT WHERE AA = 4
>	UNION
>	SELECT * FROM #TT WHERE BB = 6
>
I tried all that. It is interesting to see the adjustment in the execution when using UNION.

Thanks
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform