I'm trying to find where is the problem with this select query on Azure SQL. It runs for about 700ms.
DECLARE @LanguageIds1 INT = 11;
DECLARE @LanguageIds2 INT = 14;
SELECT
[G].[Id],
[G].[Name],
COUNT(*) AS [AudiobookCount]
FROM [Genre] AS [G]
INNER JOIN [Audiobook2Genre] AS [A2G] ON [A2G].[GenreId] = [G].[Id]
INNER JOIN [Audiobook] AS [A] ON [A].[Id] = [A2G].[AudiobookId]
WHERE [A].[LanguageId] IN (@LanguageIds1,@LanguageIds2)
GROUP BY [G].[Id], [G].[Name]
ORDER BY [G].[Name]
When I changed it to this (remove parameters and directly put values).
SELECT
[G].[Id],
[G].[Name],
COUNT(*) AS [AudiobookCount]
FROM [Genre] AS [G]
INNER JOIN [Audiobook2Genre] AS [A2G] ON [A2G].[GenreId] = [G].[Id]
INNER JOIN [Audiobook] AS [A] ON [A].[Id] = [A2G].[AudiobookId]
WHERE [A].[LanguageId] IN (11,14)
GROUP BY [G].[Id], [G].[Name]
ORDER BY [G].[Name]
It runs only for about 80ms. So difference in running time is about 620ms and I don't understand why.
I tried copy database from Azure to local MSSQL 2017 Developer Edition via bacpac and run same queries. Running times was approximately the same.