This commit is contained in:
2024-12-27 15:07:59 +01:00
parent 594d20080d
commit c55d583e42
2 changed files with 79 additions and 65 deletions

View File

@@ -27,8 +27,8 @@ WITH [cteFilteredSize] AS (
) )
SELECT [f].[Server Name] AS [instance], SELECT [f].[Server Name] AS [instance],
cast([f].[filteredInstanceMBUsed] AS NUMERIC(25, 2)) AS [Filtered tables size in MB], CAST([f].[filteredInstanceMBUsed] AS NUMERIC(25, 2)) AS [Filtered tables size in MB],
cast([uf].[unfilteredInstanceMBUsed] AS NUMERIC(25, 2)) AS [Unfiltered tables size in MB], CAST([uf].[unfilteredInstanceMBUsed] AS NUMERIC(25, 2)) AS [Unfiltered tables size in MB],
CAST([c].[currentMbUsed] AS NUMERIC(25, 2)) AS [Current db size in MB], CAST([c].[currentMbUsed] AS NUMERIC(25, 2)) AS [Current db size in MB],
CAST([d].[filteredInstanceMBCompressionEstimate] AS NUMERIC(25, 2)) AS [Estimated compressed db size in MB] CAST([d].[filteredInstanceMBCompressionEstimate] AS NUMERIC(25, 2)) AS [Estimated compressed db size in MB]
FROM [cteFilteredSize] [f] FROM [cteFilteredSize] [f]
@@ -77,10 +77,10 @@ WITH [cteFilteredSize] AS (
SELECT [f].[Server Name], SELECT [f].[Server Name],
[f].[dbName] AS [db], [f].[dbName] AS [db],
REPLACE(REPLACE(CONVERT(VARCHAR(100), CONVERT(MONEY, CAST([f].[filteredInstanceMBUsed] AS NUMERIC(25, 2))), 1), ',', ''''), '.00', '') AS [Filtered tables size in MB], CAST([f].[filteredInstanceMBUsed] AS NUMERIC(25, 2)) AS [Filtered tables size in MB],
REPLACE(REPLACE(CONVERT(VARCHAR(100), CONVERT(MONEY, CAST([uf].[unfilteredInstanceMBUsed] AS NUMERIC(25, 2))), 1), ',', ''''), '.00', '') AS [Unfiltered tables size in MB], CAST([uf].[unfilteredInstanceMBUsed] AS NUMERIC(25, 2)) AS [Unfiltered tables size in MB],
REPLACE(REPLACE(CONVERT(VARCHAR(100), CONVERT(MONEY, CAST([c].[currentMbUsed] AS NUMERIC(25, 2))), 1), ',', ''''), '.00', '') AS [Current db size in MB], CAST([c].[currentMbUsed] AS NUMERIC(25, 2)) AS [Current db size in MB],
REPLACE(REPLACE(CONVERT(VARCHAR(100), CONVERT(MONEY, CAST([d].[filteredInstanceMBCompressionEstimate] AS NUMERIC(25, 2))), 1), ',', ''''), '.00', '') AS [Estimated compressed db size in MB] CAST([d].[filteredInstanceMBCompressionEstimate] AS NUMERIC(25, 2)) AS [Estimated compressed db size in MB]
FROM [cteFilteredSize] [f] FROM [cteFilteredSize] [f]
INNER JOIN [cteUnfilteredSize] [uf] ON [uf].[Server Name] = [f].[Server Name] AND [uf].[dbName] = [f].[dbName] INNER JOIN [cteUnfilteredSize] [uf] ON [uf].[Server Name] = [f].[Server Name] AND [uf].[dbName] = [f].[dbName]
INNER JOIN [cteCurrentSize] [c] ON [c].[Server Name] = [f].[Server Name] AND [c].[dbname] = [f].[dbName] INNER JOIN [cteCurrentSize] [c] ON [c].[Server Name] = [f].[Server Name] AND [c].[dbname] = [f].[dbName]
@@ -88,6 +88,7 @@ FROM [cteFilteredSize] [f]
ORDER BY [f].[Server Name], ORDER BY [f].[Server Name],
[f].[dbName] [f].[dbName]
; ;
--per customer --per customer
WITH [cteFilteredSize] AS ( WITH [cteFilteredSize] AS (
SELECT [d].[Server Name], SELECT [d].[Server Name],
@@ -129,14 +130,15 @@ SELECT CASE
WHEN [d].[Server Name] LIKE 'sun%' OR [d].[Server Name] LIKE 'swsu%' THEN 'sun' WHEN [d].[Server Name] LIKE 'sun%' OR [d].[Server Name] LIKE 'swsu%' THEN 'sun'
ELSE 'central' ELSE 'central'
END AS [customer], END AS [customer],
COUNT(DISTINCT [f].[Server Name]) AS [cnt],
CAST(SUM([f].[filteredInstanceMBUsed]) AS NUMERIC(25, 2)) AS [Filtered tables size in MB], CAST(SUM([f].[filteredInstanceMBUsed]) AS NUMERIC(25, 2)) AS [Filtered tables size in MB],
CAST(SUM([uf].[unfilteredInstanceMBUsed]) AS NUMERIC(25, 2)) AS [Unfiltered tables size in MB], CAST(SUM([uf].[unfilteredInstanceMBUsed]) AS NUMERIC(25, 2)) AS [Unfiltered tables size in MB],
CAST(SUM([c].[currentMbUsed]) AS NUMERIC(25, 2)) AS [Current db size in MB], CAST(SUM([c].[currentMbUsed]) AS NUMERIC(25, 2)) AS [Current db size in MB],
CAST(SUM([d].[filteredInstanceMBCompressionEstimate]) AS NUMERIC(25, 2)) AS [Estimated compressed db size in MB] CAST(SUM([d].[filteredInstanceMBCompressionEstimate]) AS NUMERIC(25, 2)) AS [Estimated compressed db size in MB]
FROM [cteFilteredSize] [f] FROM [cteFilteredSize] [f]
INNER JOIN [cteUnfilteredSize] [uf] ON [uf].[Server Name] = [f].[Server Name] AND uf.[dbName] = f.[dbName] INNER JOIN [cteUnfilteredSize] [uf] ON [uf].[Server Name] = [f].[Server Name] AND [uf].[dbName] = [f].[dbName]
INNER JOIN [cteCurrentSize] [c] ON [c].[Server Name] = [f].[Server Name] AND c.[dbName] = f.[dbName] INNER JOIN [cteCurrentSize] [c] ON [c].[Server Name] = [f].[Server Name] AND [c].[dbName] = [f].[dbName]
INNER JOIN [cteCompressedSize] [d] ON [d].[Server Name] = [f].[Server Name] AND d.[dbName] = f.[dbName] INNER JOIN [cteCompressedSize] [d] ON [d].[Server Name] = [f].[Server Name] AND [d].[dbName] = [f].[dbName]
GROUP BY CASE GROUP BY CASE
WHEN [d].[Server Name] LIKE 'ama%' OR [d].[Server Name] LIKE 'swam%' THEN 'ama' WHEN [d].[Server Name] LIKE 'ama%' OR [d].[Server Name] LIKE 'swam%' THEN 'ama'
WHEN [d].[Server Name] LIKE 'cvi%' OR [d].[Server Name] LIKE 'swcv%' THEN 'cvi' WHEN [d].[Server Name] LIKE 'cvi%' OR [d].[Server Name] LIKE 'swcv%' THEN 'cvi'

View File

@@ -3,24 +3,26 @@ IF OBJECT_ID('tempdb..#toUpdate') IS NOT NULL
DROP TABLE [#toUpdate]; DROP TABLE [#toUpdate];
END END
if not exists( IF NOT EXISTS(
select * SELECT *
from [INFORMATION_SCHEMA].[COLUMNS] c FROM [INFORMATION_SCHEMA].[COLUMNS] [c]
WHERE c.table_name='octpdba-931-detail' WHERE [c].[table_name] = 'octpdba-931-detail'
and c.table_schema='dbo' AND [c].[table_schema] = 'dbo'
and c.column_name='toIgnore' AND [c].[column_name] = 'toIgnore'
) )
BEGIN BEGIN
EXEC ('alter table dbo.[octpdba-931-detail] add toIgnore bit CONSTRAINT df_toIgnore DEFAULT 0'); EXEC ('alter table dbo.[octpdba-931-detail] add toIgnore bit CONSTRAINT df_toIgnore DEFAULT 0');
print 'Added filter bit column'; PRINT 'Added filter bit column';
END END
/*Reset flag toIgnore*/ /*Reset flag toIgnore*/
UPDATE [dbo].[octpdba-931-detail] UPDATE [dbo].[octpdba-931-detail]
SET [octpdba-931-detail].[toIgnore]=0; SET [octpdba-931-detail].[toIgnore]=0
;
/*Search for the group that has the smallest number of pharmacies*/ /*Search for the group that has the smallest number of pharmacies*/
DECLARE @cntLimit INT; DECLARE @cntLimit INT
;
WITH [cteInstances] AS ( WITH [cteInstances] AS (
SELECT [g].[Server Name], SELECT [g].[Server Name],
CASE CASE
@@ -31,12 +33,14 @@ WITH [cteInstances] AS (
WHEN [g].[Server Name] LIKE 'sun%' THEN 'sun' WHEN [g].[Server Name] LIKE 'sun%' THEN 'sun'
WHEN [g].[Server Name] LIKE 'swsun%' THEN 'sun' WHEN [g].[Server Name] LIKE 'swsun%' THEN 'sun'
WHEN [g].[Server Name] LIKE 'swprd%' THEN 'central' WHEN [g].[Server Name] LIKE 'swprd%' THEN 'central'
ELSE 'unknown' END AS [customer] ELSE 'unknown'
END AS [customer]
FROM [dbo].[octpdba-931-global] [g] FROM [dbo].[octpdba-931-global] [g]
GROUP BY [g].[Server Name] GROUP BY [g].[Server Name]
), ),
[cteCnt] AS ( [cteCnt] AS (
SELECT [cteInstances].[customer], COUNT(1) AS [cnt] SELECT [cteInstances].[customer],
COUNT(1) AS [cnt]
FROM [cteInstances] FROM [cteInstances]
GROUP BY [cteInstances].[customer] GROUP BY [cteInstances].[customer]
) )
@@ -44,6 +48,12 @@ SELECT @cntLimit = MIN([cnt])
FROM [cteCnt] FROM [cteCnt]
WHERE [cteCnt].[customer] IN ('sun', 'cvi', 'ama') WHERE [cteCnt].[customer] IN ('sun', 'cvi', 'ama')
UPDATE [d]
SET [d].[toIgnore] = 1
FROM [dbo].[octpdba-931-detail] [d]
WHERE [d].[schemaName] NOT IN ('del')
AND [d].[dbName] LIKE 'arizona%'
AND [d].[TableName] LIKE '%[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]%'
/*Every table that is present in less than 90 pharmacies is deemed as to be ignored (phcy count: ama=215, sun=91, cvi=92)*/ /*Every table that is present in less than 90 pharmacies is deemed as to be ignored (phcy count: ama=215, sun=91, cvi=92)*/
SELECT [d].[schemaName], SELECT [d].[schemaName],
@@ -67,14 +77,16 @@ SET [d].[toIgnore] = 0
FROM [dbo].[octpdba-931-detail] [d] FROM [dbo].[octpdba-931-detail] [d]
INNER JOIN [#toUpdate] [t] ON [t].[TableName] = [d].[TableName] AND [t].[schemaName] = [d].[schemaName] AND [t].[dbName] = [d].[dbName] INNER JOIN [#toUpdate] [t] ON [t].[TableName] = [d].[TableName] AND [t].[schemaName] = [d].[schemaName] AND [t].[dbName] = [d].[dbName]
WHERE [d].[dbName] NOT LIKE 'activepos%' WHERE [d].[dbName] NOT LIKE 'activepos%'
AND [d].[toIgnore] = 1; AND [d].[toIgnore] = 1
;
/*All tables in the DEL schema are ignored*/ /*All tables in the DEL schema are ignored*/
UPDATE [d] UPDATE [d]
SET [d].[toIgnore] = 1 SET [d].[toIgnore] = 1
FROM [dbo].[octpdba-931-detail] [d] FROM [dbo].[octpdba-931-detail] [d]
WHERE [d].[schemaName] = 'del' WHERE [d].[schemaName] = 'del'
AND [d].[toIgnore] = 0; AND [d].[toIgnore] = 0
;
SELECT [d].[schemaName], SELECT [d].[schemaName],
[d].[TableName], [d].[TableName],