From 8e193dfc62341455edaa88cf8b0991e9af23734d Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Sat, 15 Apr 2017 10:52:38 -0400 Subject: [PATCH] join optimizations --- .../dbo/Stored Procedures/CipherDetails_ReadByUserId.sql | 2 +- .../CipherFullDetails_ReadByIdUserId.sql | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Sql/dbo/Stored Procedures/CipherDetails_ReadByUserId.sql b/src/Sql/dbo/Stored Procedures/CipherDetails_ReadByUserId.sql index 3d9664b4e..7d20f5974 100644 --- a/src/Sql/dbo/Stored Procedures/CipherDetails_ReadByUserId.sql +++ b/src/Sql/dbo/Stored Procedures/CipherDetails_ReadByUserId.sql @@ -9,7 +9,7 @@ BEGIN FROM [dbo].[CipherDetails](@UserId) C LEFT JOIN - [dbo].[SubvaultCipher] SC ON SC.[CipherId] = C.[Id] + [dbo].[SubvaultCipher] SC ON C.[UserId] IS NULL AND SC.[CipherId] = C.[Id] LEFT JOIN [dbo].[SubvaultUser] SU ON SU.[SubvaultId] = SC.[SubvaultId] LEFT JOIN diff --git a/src/Sql/dbo/Stored Procedures/CipherFullDetails_ReadByIdUserId.sql b/src/Sql/dbo/Stored Procedures/CipherFullDetails_ReadByIdUserId.sql index a52dd8349..99a6aad4e 100644 --- a/src/Sql/dbo/Stored Procedures/CipherFullDetails_ReadByIdUserId.sql +++ b/src/Sql/dbo/Stored Procedures/CipherFullDetails_ReadByIdUserId.sql @@ -24,7 +24,12 @@ BEGIN WHERE C.Id = @Id AND ( - (C.[UserId] IS NOT NULL AND C.[UserId] = @UserId) - OR (OU.[UserId] = @UserId AND OU.[Status] = 2 AND O.[Enabled] = 1) -- 2 = Confirmed + C.[UserId] = @UserId + OR ( + C.[UserId] IS NULL + AND OU.[UserId] = @UserId + AND OU.[Status] = 2 -- 2 = Confirmed + AND O.[Enabled] = 1 + ) ) END \ No newline at end of file