У меня есть две таблицы с миллионами строк.
Дело 1 : Where
предложение с 'cvaleur'
SELECT TOP(2000)
[p].[Id_Paie_Param_Constante_Variable] AS [id],
[v].[Date_MAJ] AS [DateMaj],
[v].[Id_Paie_Param_Constante_Variable_Valeur] AS [IdPaieParamConstanteVariableValeur]
FROM
[Paie_Param_Constante_Variable] AS [p]
LEFT JOIN
[Paie_Theme] AS [t] ON [p].[Code_Paie_Theme] = [t].[Code_Paie_Theme]
INNER JOIN
[Paie_Param_Constante_Variable_Valeur] AS [v] ON [p].[Id_Paie_Param_Constante_Variable] = [v].[Id_Paie_Param_Constante_Variable]
WHERE
[p].[Code_Constante_Variable_Type] = N'cvaleur'
ORDER BY
[DateMaj] DESC
Этот запрос возвращает мои строки за 200 мс
Случай 2: предложение Where
с vformule
SELECT TOP(2000)
[p].[Id_Paie_Param_Constante_Variable] AS [id],
[v].[Date_MAJ] AS [DateMaj],
[v].[Id_Paie_Param_Constante_Variable_Valeur] AS [IdPaieParamConstanteVariableValeur]
FROM
[Paie_Param_Constante_Variable] AS [p]
LEFT JOIN
[Paie_Theme] AS [t] ON [p].[Code_Paie_Theme] = [t].[Code_Paie_Theme]
INNER JOIN
[Paie_Param_Constante_Variable_Valeur] AS [v] ON [p].[Id_Paie_Param_Constante_Variable] = [v].[Id_Paie_Param_Constante_Variable]
WHERE
[p].[Code_Constante_Variable_Type] = N'vformule'
ORDER BY
[DateMaj] DESC
Этот запрос возвращает мои строки за 5 секунд! Почему?
У меня есть два индекса:
CREATE NONCLUSTERED INDEX [IX_Relationship9]
ON [dbo].[Paie_Param_Constante_Variable] ([Code_Constante_Variable_Type] ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [DateMAJ]
ON [dbo].[Paie_Param_Constante_Variable_Valeur] ([Date_MAJ] DESC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
Случай 3: предложение Where
с «vformule», но заказ по ASC
SELECT TOP(2000)
[p].[Id_Paie_Param_Constante_Variable] AS [id],
[v].[Date_MAJ] AS [DateMaj],
[v].[Id_Paie_Param_Constante_Variable_Valeur] AS [IdPaieParamConstanteVariableValeur]
FROM
[Paie_Param_Constante_Variable] AS [p]
LEFT JOIN
[Paie_Theme] AS [t] ON [p].[Code_Paie_Theme] = [t].[Code_Paie_Theme]
INNER JOIN
[Paie_Param_Constante_Variable_Valeur] AS [v] ON [p].[Id_Paie_Param_Constante_Variable] = [v].[Id_Paie_Param_Constante_Variable]
WHERE
[p].[Code_Constante_Variable_Type] = N'vformule'
ORDER BY
[DateMaj] ASC
Этот запрос возвращает мои строки за 200 мс!
Мой индекс на DateMAJ - DESC.
Мне нужно заказать SQL по убыванию ...
Любая помощь высоко ценится
Приветствия