mirror of
https://github.com/Microsoft/sql-server-samples.git
synced 2025-12-08 14:58:54 +00:00
improved perf for coldroomtemperature
Improved process, such that all data for a given day is generated as a single native proc execution, which accumulates the data in a non-durable table. this data is then bulk-moved to the archive table, before adding the most recent data to the current table.
This commit is contained in:
@@ -53,3 +53,4 @@ samples/features/in-memory/iot-smart-grid/ConsoleClient/bin/Release/ConsoleClien
|
||||
samples/features/in-memory/ticket-reservations/TicketReservations/bin/Release/TicketReservations.publish.sql
|
||||
samples/applications/iot-smart-grid/ConsoleClient/bin/Release/ConsoleClient.exe.config
|
||||
samples/applications/iot-smart-grid/Db/Db.dbmdl
|
||||
samples/databases/wide-world-importers/workload-drivers/order-insert/MultithreadedOrderInsert/obj/Release/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
|
||||
|
||||
-2770
File diff suppressed because it is too large
Load Diff
-29
@@ -1,29 +0,0 @@
|
||||
|
||||
CREATE PROCEDURE DataLoadSimulation.Configuration_RemoveDataLoadSimulationProcedures
|
||||
WITH EXECUTE AS OWNER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
DROP PROCEDURE IF EXISTS DataLoadSimulation.ActivateWebsiteLogons;
|
||||
DROP PROCEDURE IF EXISTS DataLoadSimulation.AddCustomers;
|
||||
DROP PROCEDURE IF EXISTS DataLoadSimulation.AddSpecialDeals;
|
||||
DROP PROCEDURE IF EXISTS DataLoadSimulation.AddStockItems;
|
||||
DROP PROCEDURE IF EXISTS DataLoadSimulation.ChangePasswords;
|
||||
DROP PROCEDURE IF EXISTS DataLoadSimulation.CreateCustomerOrders;
|
||||
DROP PROCEDURE IF EXISTS DataLoadSimulation.DailyProcessToCreateHistory;
|
||||
DROP PROCEDURE IF EXISTS DataLoadSimulation.InvoicePickedOrders;
|
||||
DROP PROCEDURE IF EXISTS DataLoadSimulation.MakeTemporalChanges;
|
||||
DROP PROCEDURE IF EXISTS DataLoadSimulation.PaySuppliers;
|
||||
DROP PROCEDURE IF EXISTS DataLoadSimulation.PerformStocktake;
|
||||
DROP PROCEDURE IF EXISTS DataLoadSimulation.PickStockForCustomerOrders;
|
||||
DROP PROCEDURE IF EXISTS DataLoadSimulation.PlaceSupplierOrders;
|
||||
DROP PROCEDURE IF EXISTS DataLoadSimulation.ProcessCustomerPayments;
|
||||
DROP PROCEDURE IF EXISTS DataLoadSimulation.ReceivePurchaseOrders;
|
||||
DROP PROCEDURE IF EXISTS DataLoadSimulation.RecordColdRoomTemperatures;
|
||||
DROP PROCEDURE IF EXISTS DataLoadSimulation.RecordDeliveryVanTemperatures;
|
||||
DROP PROCEDURE IF EXISTS DataLoadSimulation.RecordInvoiceDeliveries;
|
||||
DROP PROCEDURE IF EXISTS DataLoadSimulation.UpdateCustomFields;
|
||||
DROP FUNCTION IF EXISTS DataLoadSimulation.GetAreaCode;
|
||||
END;
|
||||
+255
-229
@@ -11,6 +11,7 @@ CREATE PROCEDURE DataLoadSimulation.DailyProcessToCreateHistory
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
DECLARE @CurrentDateTime datetime2(7) = @StartDate;
|
||||
DECLARE @EndOfTime datetime2(7) = '99991231 23:59:59.9999999';
|
||||
@@ -28,264 +29,289 @@ BEGIN
|
||||
|
||||
EXEC DataLoadSimulation.DeactivateTemporalTablesBeforeDataLoad;
|
||||
|
||||
WHILE @CurrentDateTime <= @EndDate
|
||||
BEGIN
|
||||
SET @DateMessage = N'Processing '
|
||||
+ SUBSTRING(DATENAME(weekday, @CurrentDateTime), 1,3)
|
||||
+ N' '
|
||||
+ CONVERT(nvarchar(20), @CurrentDateTime, 107)
|
||||
+ N' '
|
||||
+ CAST(DATEDIFF(DAY, @CurrentDateTime, @EndDate) AS NVARCHAR)
|
||||
+ N' Days Remaining '
|
||||
;
|
||||
BEGIN TRY
|
||||
|
||||
WHILE @CurrentDateTime <= @EndDate
|
||||
BEGIN
|
||||
-- one transaction per day
|
||||
BEGIN TRAN
|
||||
SET @DateMessage = N'Processing '
|
||||
+ SUBSTRING(DATENAME(weekday, @CurrentDateTime), 1,3)
|
||||
+ N' '
|
||||
+ CONVERT(nvarchar(20), @CurrentDateTime, 107)
|
||||
+ N' '
|
||||
+ CAST(DATEDIFF(DAY, @CurrentDateTime, @EndDate) AS NVARCHAR)
|
||||
+ N' Days Remaining '
|
||||
;
|
||||
|
||||
|
||||
|
||||
IF @AreDatesPrinted <> 0 OR @IsSilentMode = 0
|
||||
BEGIN
|
||||
--PRINT SUBSTRING(DATENAME(weekday, @CurrentDateTime), 1,3) + N' ' + CONVERT(nvarchar(20), @CurrentDateTime, 107);
|
||||
--PRINT N' ';
|
||||
PRINT @DateMessage
|
||||
END;
|
||||
IF @AreDatesPrinted <> 0 OR @IsSilentMode = 0
|
||||
BEGIN
|
||||
--PRINT SUBSTRING(DATENAME(weekday, @CurrentDateTime), 1,3) + N' ' + CONVERT(nvarchar(20), @CurrentDateTime, 107);
|
||||
--PRINT N' ';
|
||||
PRINT @DateMessage
|
||||
END;
|
||||
|
||||
-- Calculate the days of the week - different processing happens on each day
|
||||
SET @Weekday = DATEPART(weekday, @CurrentDateTime);
|
||||
SET @IsSaturday = 0;
|
||||
SET @IsSunday = 0;
|
||||
SET @IsMonday = 0;
|
||||
SET @IsWeekday = 1;
|
||||
-- Calculate the days of the week - different processing happens on each day
|
||||
SET @Weekday = DATEPART(weekday, @CurrentDateTime);
|
||||
SET @IsSaturday = 0;
|
||||
SET @IsSunday = 0;
|
||||
SET @IsMonday = 0;
|
||||
SET @IsWeekday = 1;
|
||||
|
||||
IF @Weekday = 7
|
||||
BEGIN
|
||||
SET @IsSaturday = 1;
|
||||
SET @IsWeekday = 0;
|
||||
END;
|
||||
IF @Weekday = 1
|
||||
BEGIN
|
||||
SET @IsSunday = 1;
|
||||
SET @IsWeekday = 0;
|
||||
END;
|
||||
IF @Weekday = 2 SET @IsMonday = 1;
|
||||
IF @Weekday = 7
|
||||
BEGIN
|
||||
SET @IsSaturday = 1;
|
||||
SET @IsWeekday = 0;
|
||||
END;
|
||||
IF @Weekday = 1
|
||||
BEGIN
|
||||
SET @IsSunday = 1;
|
||||
SET @IsWeekday = 0;
|
||||
END;
|
||||
IF @Weekday = 2 SET @IsMonday = 1;
|
||||
|
||||
-- Purchase orders
|
||||
IF @IsWeekday <> 0
|
||||
BEGIN
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Receiving Purchase Orders'
|
||||
END;
|
||||
-- Purchase orders
|
||||
IF @IsWeekday <> 0
|
||||
BEGIN
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Receiving Purchase Orders'
|
||||
END;
|
||||
|
||||
-- Start receiving purchase orders at 7AM on weekdays
|
||||
SET @StartingWhen = DATEADD(hour, 7, @CurrentDateTime);
|
||||
EXEC DataLoadSimulation.ReceivePurchaseOrders @CurrentDateTime, @StartingWhen, @EndOfTime, @IsSilentMode;
|
||||
END;
|
||||
-- Start receiving purchase orders at 7AM on weekdays
|
||||
SET @StartingWhen = DATEADD(hour, 7, @CurrentDateTime);
|
||||
EXEC DataLoadSimulation.ReceivePurchaseOrders @CurrentDateTime, @StartingWhen, @EndOfTime, @IsSilentMode;
|
||||
END;
|
||||
|
||||
-- Password changes
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Receiving Changing Passwords'
|
||||
END;
|
||||
SET @StartingWhen = DATEADD(hour, 8, @CurrentDateTime);
|
||||
EXEC DataLoadSimulation.ChangePasswords @CurrentDateTime, @StartingWhen, @EndOfTime, @IsSilentMode;
|
||||
-- Password changes
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Receiving Changing Passwords'
|
||||
END;
|
||||
SET @StartingWhen = DATEADD(hour, 8, @CurrentDateTime);
|
||||
EXEC DataLoadSimulation.ChangePasswords @CurrentDateTime, @StartingWhen, @EndOfTime, @IsSilentMode;
|
||||
|
||||
-- Activate new website users
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Activating Website Logins'
|
||||
END;
|
||||
SET @StartingWhen = DATEADD(minute, 10, DATEADD(hour, 8, @CurrentDateTime));
|
||||
EXEC DataLoadSimulation.ActivateWebsiteLogons @CurrentDateTime, @StartingWhen, @EndOfTime, @IsSilentMode;
|
||||
-- Activate new website users
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Activating Website Logins'
|
||||
END;
|
||||
SET @StartingWhen = DATEADD(minute, 10, DATEADD(hour, 8, @CurrentDateTime));
|
||||
EXEC DataLoadSimulation.ActivateWebsiteLogons @CurrentDateTime, @StartingWhen, @EndOfTime, @IsSilentMode;
|
||||
|
||||
-- Payments to suppliers
|
||||
IF DATEPART(weekday, @CurrentDateTime) = 2
|
||||
BEGIN
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Paying Suppliers'
|
||||
END;
|
||||
SET @StartingWhen = DATEADD(hour, 9, @CurrentDateTime); -- Suppliers are paid on Monday mornings
|
||||
EXEC DataLoadSimulation.PaySuppliers @CurrentDateTime, @StartingWhen, @EndOfTime, @IsSilentMode;
|
||||
END;
|
||||
-- Payments to suppliers
|
||||
IF DATEPART(weekday, @CurrentDateTime) = 2
|
||||
BEGIN
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Paying Suppliers'
|
||||
END;
|
||||
SET @StartingWhen = DATEADD(hour, 9, @CurrentDateTime); -- Suppliers are paid on Monday mornings
|
||||
EXEC DataLoadSimulation.PaySuppliers @CurrentDateTime, @StartingWhen, @EndOfTime, @IsSilentMode;
|
||||
END;
|
||||
|
||||
-- Customer orders received
|
||||
SET @StartingWhen = DATEADD(hour, 10, @CurrentDateTime);
|
||||
SET @NumberOfCustomerOrders = @AverageNumberOfCustomerOrdersPerDay / 2
|
||||
+ CEILING(RAND() * @AverageNumberOfCustomerOrdersPerDay);
|
||||
SET @NumberOfCustomerOrders = CASE DATEPART(weekday, @CurrentDateTime)
|
||||
WHEN 7
|
||||
THEN FLOOR(@NumberOfCustomerOrders * @SaturdayPercentageOfNormalWorkDay / 100)
|
||||
WHEN 1
|
||||
THEN FLOOR(@NumberOfCustomerOrders * @SundayPercentageOfNormalWorkDay / 100)
|
||||
ELSE @NumberOfCustomerOrders
|
||||
END;
|
||||
SET @NumberOfCustomerOrders = FLOOR(@NumberOfCustomerOrders * CASE WHEN YEAR(@StartingWhen) = 2013 THEN 1.0
|
||||
WHEN YEAR(@StartingWhen) = 2014 THEN 1.12
|
||||
WHEN YEAR(@StartingWhen) = 2015 THEN 1.21
|
||||
WHEN YEAR(@StartingWhen) = 2016 THEN 1.23
|
||||
ELSE 1.26
|
||||
END
|
||||
);
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Creating Customer Orders'
|
||||
END;
|
||||
EXEC DataLoadSimulation.CreateCustomerOrders @CurrentDateTime, @StartingWhen, @EndOfTime, @NumberOfCustomerOrders, @IsSilentMode;
|
||||
-- Customer orders received
|
||||
SET @StartingWhen = DATEADD(hour, 10, @CurrentDateTime);
|
||||
SET @NumberOfCustomerOrders = @AverageNumberOfCustomerOrdersPerDay / 2
|
||||
+ CEILING(RAND() * @AverageNumberOfCustomerOrdersPerDay);
|
||||
SET @NumberOfCustomerOrders = CASE DATEPART(weekday, @CurrentDateTime)
|
||||
WHEN 7
|
||||
THEN FLOOR(@NumberOfCustomerOrders * @SaturdayPercentageOfNormalWorkDay / 100)
|
||||
WHEN 1
|
||||
THEN FLOOR(@NumberOfCustomerOrders * @SundayPercentageOfNormalWorkDay / 100)
|
||||
ELSE @NumberOfCustomerOrders
|
||||
END;
|
||||
SET @NumberOfCustomerOrders = FLOOR(@NumberOfCustomerOrders * CASE WHEN YEAR(@StartingWhen) = 2013 THEN 1.0
|
||||
WHEN YEAR(@StartingWhen) = 2014 THEN 1.12
|
||||
WHEN YEAR(@StartingWhen) = 2015 THEN 1.21
|
||||
WHEN YEAR(@StartingWhen) = 2016 THEN 1.23
|
||||
ELSE 1.26
|
||||
END
|
||||
);
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Creating Customer Orders'
|
||||
END;
|
||||
EXEC DataLoadSimulation.CreateCustomerOrders @CurrentDateTime, @StartingWhen, @EndOfTime, @NumberOfCustomerOrders, @IsSilentMode;
|
||||
|
||||
-- Pick any customer orders that can be picked
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Picking Stock for Customer Orders'
|
||||
END;
|
||||
SET @StartingWhen = DATEADD(hour, 11, @CurrentDateTime);
|
||||
EXEC DataLoadSimulation.PickStockForCustomerOrders @CurrentDateTime, @StartingWhen, @EndOfTime, @IsSilentMode;
|
||||
-- Pick any customer orders that can be picked
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Picking Stock for Customer Orders'
|
||||
END;
|
||||
SET @StartingWhen = DATEADD(hour, 11, @CurrentDateTime);
|
||||
EXEC DataLoadSimulation.PickStockForCustomerOrders @CurrentDateTime, @StartingWhen, @EndOfTime, @IsSilentMode;
|
||||
|
||||
-- Process any payments from customers
|
||||
IF @Weekday <> 0
|
||||
BEGIN
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Process Customer Payments'
|
||||
END;
|
||||
SET @StartingWhen = DATEADD(minute, 30, DATEADD(hour, 11, @CurrentDateTime));
|
||||
EXEC DataLoadSimulation.ProcessCustomerPayments @CurrentDateTime, @StartingWhen, @EndOfTime, @IsSilentMode;
|
||||
END;
|
||||
-- Process any payments from customers
|
||||
IF @Weekday <> 0
|
||||
BEGIN
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Process Customer Payments'
|
||||
END;
|
||||
SET @StartingWhen = DATEADD(minute, 30, DATEADD(hour, 11, @CurrentDateTime));
|
||||
EXEC DataLoadSimulation.ProcessCustomerPayments @CurrentDateTime, @StartingWhen, @EndOfTime, @IsSilentMode;
|
||||
END;
|
||||
|
||||
-- Invoice orders that have been fully picked
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Invoice Picked Orders'
|
||||
END;
|
||||
SET @StartingWhen = DATEADD(hour, 12, @CurrentDateTime);
|
||||
EXEC DataLoadSimulation.InvoicePickedOrders @CurrentDateTime, @StartingWhen, @EndOfTime, @IsSilentMode;
|
||||
-- Invoice orders that have been fully picked
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Invoice Picked Orders'
|
||||
END;
|
||||
SET @StartingWhen = DATEADD(hour, 12, @CurrentDateTime);
|
||||
EXEC DataLoadSimulation.InvoicePickedOrders @CurrentDateTime, @StartingWhen, @EndOfTime, @IsSilentMode;
|
||||
|
||||
-- Place supplier orders
|
||||
IF @Weekday <> 0
|
||||
BEGIN
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Placing Supplier Orders'
|
||||
END;
|
||||
SET @StartingWhen = DATEADD(hour, 13, @CurrentDateTime);
|
||||
EXEC DataLoadSimulation.PlaceSupplierOrders @CurrentDateTime, @StartingWhen, @EndOfTime, @IsSilentMode;
|
||||
END;
|
||||
-- Place supplier orders
|
||||
IF @Weekday <> 0
|
||||
BEGIN
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Placing Supplier Orders'
|
||||
END;
|
||||
SET @StartingWhen = DATEADD(hour, 13, @CurrentDateTime);
|
||||
EXEC DataLoadSimulation.PlaceSupplierOrders @CurrentDateTime, @StartingWhen, @EndOfTime, @IsSilentMode;
|
||||
END;
|
||||
|
||||
-- End of quarter stock take
|
||||
IF (MONTH(@CurrentDateTime) = 1 AND DAY(@CurrentDateTime) = 31)
|
||||
OR (MONTH(@CurrentDateTime) = 4 AND DAY(@CurrentDateTime) = 30)
|
||||
OR (MONTH(@CurrentDateTime) = 7 AND DAY(@CurrentDateTime) = 31)
|
||||
OR (MONTH(@CurrentDateTime) = 10 AND DAY(@CurrentDateTime) = 31)
|
||||
BEGIN
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Performing Stock Take'
|
||||
END;
|
||||
SET @StartingWhen = DATEADD(hour, 14, @CurrentDateTime);
|
||||
EXEC DataLoadSimulation.PerformStocktake @CurrentDateTime, @StartingWhen, @EndOfTime, @IsSilentMode;
|
||||
END;
|
||||
-- End of quarter stock take
|
||||
IF (MONTH(@CurrentDateTime) = 1 AND DAY(@CurrentDateTime) = 31)
|
||||
OR (MONTH(@CurrentDateTime) = 4 AND DAY(@CurrentDateTime) = 30)
|
||||
OR (MONTH(@CurrentDateTime) = 7 AND DAY(@CurrentDateTime) = 31)
|
||||
OR (MONTH(@CurrentDateTime) = 10 AND DAY(@CurrentDateTime) = 31)
|
||||
BEGIN
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Performing Stock Take'
|
||||
END;
|
||||
SET @StartingWhen = DATEADD(hour, 14, @CurrentDateTime);
|
||||
EXEC DataLoadSimulation.PerformStocktake @CurrentDateTime, @StartingWhen, @EndOfTime, @IsSilentMode;
|
||||
END;
|
||||
|
||||
-- Record invoice deliveries
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Recording Invoice Deliveries'
|
||||
END;
|
||||
SET @StartingWhen = DATEADD(hour, 7, @CurrentDateTime);
|
||||
EXEC DataLoadSimulation.RecordInvoiceDeliveries @CurrentDateTime, @StartingWhen, @EndOfTime, @IsSilentMode;
|
||||
-- Record invoice deliveries
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Recording Invoice Deliveries'
|
||||
END;
|
||||
SET @StartingWhen = DATEADD(hour, 7, @CurrentDateTime);
|
||||
EXEC DataLoadSimulation.RecordInvoiceDeliveries @CurrentDateTime, @StartingWhen, @EndOfTime, @IsSilentMode;
|
||||
|
||||
-- Add customers
|
||||
IF @Weekday <> 0
|
||||
BEGIN
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Adding Customers'
|
||||
END;
|
||||
SET @StartingWhen = DATEADD(hour, 15, @CurrentDateTime);
|
||||
EXEC DataLoadSimulation.AddCustomers @CurrentDateTime, @StartingWhen, @EndOfTime, @IsSilentMode;
|
||||
END;
|
||||
-- Add customers
|
||||
IF @Weekday <> 0
|
||||
BEGIN
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Adding Customers'
|
||||
END;
|
||||
SET @StartingWhen = DATEADD(hour, 15, @CurrentDateTime);
|
||||
EXEC DataLoadSimulation.AddCustomers @CurrentDateTime, @StartingWhen, @EndOfTime, @IsSilentMode;
|
||||
END;
|
||||
|
||||
-- Add stock items
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Adding Stock Items'
|
||||
END;
|
||||
SET @StartingWhen = DATEADD(hour, 16, @CurrentDateTime);
|
||||
EXEC DataLoadSimulation.AddStockItems @CurrentDateTime, @StartingWhen, @EndOfTime, @IsSilentMode;
|
||||
-- Add stock items
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Adding Stock Items'
|
||||
END;
|
||||
SET @StartingWhen = DATEADD(hour, 16, @CurrentDateTime);
|
||||
EXEC DataLoadSimulation.AddStockItems @CurrentDateTime, @StartingWhen, @EndOfTime, @IsSilentMode;
|
||||
|
||||
-- Add special deals
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Adding Special Deals'
|
||||
END;
|
||||
SET @StartingWhen = DATEADD(hour, 16, @CurrentDateTime);
|
||||
EXEC DataLoadSimulation.AddSpecialDeals @CurrentDateTime, @StartingWhen, @EndOfTime, @IsSilentMode;
|
||||
-- Add special deals
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Adding Special Deals'
|
||||
END;
|
||||
SET @StartingWhen = DATEADD(hour, 16, @CurrentDateTime);
|
||||
EXEC DataLoadSimulation.AddSpecialDeals @CurrentDateTime, @StartingWhen, @EndOfTime, @IsSilentMode;
|
||||
|
||||
-- Temporal changes
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Making Temporal Changes'
|
||||
END;
|
||||
SET @StartingWhen = DATEADD(hour, 16, @CurrentDateTime);
|
||||
EXEC DataLoadSimulation.MakeTemporalChanges @CurrentDateTime, @StartingWhen, @EndOfTime, @IsSilentMode;
|
||||
-- Temporal changes
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Making Temporal Changes'
|
||||
END;
|
||||
SET @StartingWhen = DATEADD(hour, 16, @CurrentDateTime);
|
||||
EXEC DataLoadSimulation.MakeTemporalChanges @CurrentDateTime, @StartingWhen, @EndOfTime, @IsSilentMode;
|
||||
|
||||
-- Record delivery van temperatures
|
||||
IF @CurrentDateTime >= '20160101'
|
||||
BEGIN
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Recording Delivery Van Temperatures'
|
||||
END;
|
||||
SET @StartingWhen = DATEADD(hour, 7, @CurrentDateTime);
|
||||
EXEC DataLoadSimulation.RecordDeliveryVanTemperatures 300, 2, @CurrentDateTime, @StartingWhen, @IsSilentMode;
|
||||
END;
|
||||
-- Record delivery van temperatures
|
||||
IF @CurrentDateTime >= '20160101'
|
||||
BEGIN
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Recording Delivery Van Temperatures'
|
||||
END;
|
||||
SET @StartingWhen = DATEADD(hour, 7, @CurrentDateTime);
|
||||
EXEC DataLoadSimulation.RecordDeliveryVanTemperatures 300, 2, @CurrentDateTime, @StartingWhen, @IsSilentMode;
|
||||
END;
|
||||
|
||||
-- Record cold room temperatures
|
||||
IF @CurrentDateTime >= '20151220'
|
||||
BEGIN
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Recording Cold Room Temperatures'
|
||||
END;
|
||||
EXEC DataLoadSimulation.RecordColdRoomTemperatures 30, 4, @CurrentDateTime, @EndOfTime, @IsSilentMode;
|
||||
END;
|
||||
-- Record cold room temperatures
|
||||
--IF @CurrentDateTime >= '20151220'
|
||||
--BEGIN
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT @DateMessage + N'- Recording Cold Room Temperatures'
|
||||
END;
|
||||
EXEC DataLoadSimulation.RecordColdRoomTemperatures 3600, 40, @CurrentDateTime, @EndOfTime, @IsSilentMode;
|
||||
--END;
|
||||
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT N' ';
|
||||
END;
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT N' ';
|
||||
END;
|
||||
|
||||
SET @CurrentDateTime = DATEADD(day, 1, @CurrentDateTime);
|
||||
END; -- of processing each day
|
||||
SET @CurrentDateTime = DATEADD(day, 1, @CurrentDateTime);
|
||||
COMMIT
|
||||
END; -- of processing each day
|
||||
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT N'Updating Custom Fields';
|
||||
END;
|
||||
IF @UpdateCustomFields <> 0
|
||||
BEGIN
|
||||
EXEC DataLoadSimulation.UpdateCustomFields @EndDate;
|
||||
END;
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT N'Updating Custom Fields';
|
||||
END;
|
||||
IF @UpdateCustomFields <> 0
|
||||
BEGIN
|
||||
EXEC DataLoadSimulation.UpdateCustomFields @EndDate;
|
||||
END;
|
||||
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT N'Reactivating Temporal Tables After Data Load ';
|
||||
END;
|
||||
EXEC DataLoadSimulation.ReactivateTemporalTablesAfterDataLoad;
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT N'Reactivating Temporal Tables After Data Load ';
|
||||
END;
|
||||
EXEC DataLoadSimulation.ReactivateTemporalTablesAfterDataLoad;
|
||||
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT N'Reseeding All Sequences';
|
||||
END;
|
||||
EXEC Sequences.ReseedAllSequences;
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT N'Reseeding All Sequences';
|
||||
END;
|
||||
EXEC Sequences.ReseedAllSequences;
|
||||
|
||||
-- Ensure RLS is applied
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT N'Applying Row Level Security';
|
||||
END;
|
||||
EXEC [Application].Configuration_ApplyRowLevelSecurity
|
||||
-- Ensure RLS is applied
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT N'Applying Row Level Security';
|
||||
END;
|
||||
EXEC [Application].Configuration_ApplyRowLevelSecurity
|
||||
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT N'Done Creating Wide World Importers Data History';
|
||||
END;
|
||||
IF @IsSilentMode = 0
|
||||
BEGIN
|
||||
PRINT N'Done Creating Wide World Importers Data History';
|
||||
END;
|
||||
END TRY
|
||||
BEGIN CATCH
|
||||
IF XACT_STATE() <> 0
|
||||
BEGIN
|
||||
ROLLBACK
|
||||
END
|
||||
|
||||
PRINT N'Error Detected. Error ' + CAST(ERROR_NUMBER() AS nvarchar) + N': ' + ERROR_MESSAGE();
|
||||
PRINT N'Attempting cleanup before throwing.';
|
||||
|
||||
PRINT N'Reactivating Temporal Tables After Data Load ';
|
||||
EXEC DataLoadSimulation.ReactivateTemporalTablesAfterDataLoad;
|
||||
|
||||
PRINT N'Reseeding All Sequences';
|
||||
EXEC Sequences.ReseedAllSequences;
|
||||
|
||||
PRINT N'Applying Row Level Security';
|
||||
EXEC [Application].Configuration_ApplyRowLevelSecurity;
|
||||
THROW;
|
||||
END CATCH
|
||||
|
||||
END;
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
CREATE PROCEDURE [DataLoadSimulation].[PopulateColdRoomTemperatures_temp]
|
||||
@AverageSecondsBetweenReadings int,
|
||||
@NumberOfSensors int,
|
||||
@TimeCounter datetime2(7),
|
||||
@EndTime datetime2(7)
|
||||
WITH NATIVE_COMPILATION, SCHEMABINDING, EXECUTE AS OWNER
|
||||
AS
|
||||
BEGIN ATOMIC WITH
|
||||
(TRANSACTION ISOLATION LEVEL=SNAPSHOT, LANGUAGE=N'English')
|
||||
|
||||
DECLARE @ValidTo datetime2(7)
|
||||
DECLARE @DelayInSeconds int
|
||||
DECLARE @SensorCounter int
|
||||
DECLARE @Temperature decimal(10,2);
|
||||
DECLARE @ColdRoomTemperatureID bigint
|
||||
|
||||
SELECT @ColdRoomTemperatureID = ISNULL(MAX(ColdRoomTemperatureID), 0) + 1
|
||||
FROM DataLoadSimulation.[ColdRoomTemperatures_temp]
|
||||
|
||||
WHILE @TimeCounter < @EndTime
|
||||
BEGIN
|
||||
SET @SensorCounter = 0;
|
||||
SET @DelayInSeconds = CEILING(RAND() * @AverageSecondsBetweenReadings);
|
||||
SET @ValidTo = DATEADD(second, @DelayInSeconds, @TimeCounter);
|
||||
|
||||
WHILE @SensorCounter < @NumberOfSensors
|
||||
BEGIN
|
||||
SET @Temperature = 3 + RAND() * 2;
|
||||
|
||||
INSERT DataLoadSimulation.[ColdRoomTemperatures_temp]
|
||||
(ColdRoomTemperatureID, ColdRoomSensorNumber, RecordedWhen, Temperature, ValidFrom, ValidTo)
|
||||
VALUES
|
||||
(@ColdRoomTemperatureID, @SensorCounter + 1, @TimeCounter, @Temperature, @TimeCounter, @ValidTo);
|
||||
|
||||
SET @SensorCounter += 1;
|
||||
SET @ColdRoomTemperatureID += 1;
|
||||
END;
|
||||
SET @TimeCounter = @ValidTo
|
||||
END;
|
||||
END;
|
||||
-3
@@ -9,8 +9,6 @@ AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
|
||||
EXEC DataLoadSimulation.Configuration_ApplyDataLoadSimulationProcedures;
|
||||
|
||||
DECLARE @CurrentMaximumDate date = COALESCE((SELECT MAX(OrderDate) FROM Sales.Orders), '20121231');
|
||||
DECLARE @StartingDate date = DATEADD(day, 1, @CurrentMaximumDate);
|
||||
DECLARE @EndingDate date = CAST(DATEADD(day, -1, SYSDATETIME()) AS date);
|
||||
@@ -25,5 +23,4 @@ BEGIN
|
||||
@IsSilentMode = @IsSilentMode,
|
||||
@AreDatesPrinted = @AreDatesPrinted;
|
||||
|
||||
EXEC DataLoadSimulation.Configuration_RemoveDataLoadSimulationProcedures;
|
||||
END;
|
||||
|
||||
+49
-30
@@ -20,11 +20,7 @@ BEGIN
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
-- Pushed Notifications to calling proc
|
||||
--IF @IsSilentMode = 0
|
||||
--BEGIN
|
||||
-- PRINT N'Recording cold room temperatures for ' + LEFT(CAST(@CurrentDateTime AS NVARCHAR), 10);
|
||||
--END;
|
||||
BEGIN TRAN
|
||||
|
||||
DECLARE @TimeCounter datetime2(7) = CAST(@CurrentDateTime AS date);
|
||||
DECLARE @SensorCounter int;
|
||||
@@ -32,32 +28,55 @@ BEGIN
|
||||
DECLARE @TimeToFinishForTheDay datetime2(7) = DATEADD(second, -30, DATEADD(day, 1, @TimeCounter));
|
||||
DECLARE @Temperature decimal(10,2);
|
||||
|
||||
WHILE @TimeCounter < @TimeToFinishForTheDay
|
||||
BEGIN
|
||||
SET @SensorCounter = 0;
|
||||
WHILE @SensorCounter < @NumberOfSensors
|
||||
BEGIN
|
||||
SET @Temperature = 3 + RAND() * 2;
|
||||
-- clean up any artifacts from earlier runs
|
||||
DELETE FROM DataLoadSimulation.[ColdRoomTemperatures_temp]
|
||||
|
||||
DELETE Warehouse.ColdRoomTemperatures
|
||||
OUTPUT deleted.ColdRoomTemperatureID,
|
||||
deleted.ColdRoomSensorNumber,
|
||||
deleted.RecordedWhen,
|
||||
deleted.Temperature,
|
||||
deleted.ValidFrom,
|
||||
@TimeCounter
|
||||
INTO Warehouse.ColdRoomTemperatures_Archive
|
||||
WHERE ColdRoomSensorNumber = @SensorCounter + 1;
|
||||
IF @TimeCounter < @TimeToFinishForTheDay
|
||||
BEGIN
|
||||
-- seed temporary table with current status of sensors
|
||||
DELETE Warehouse.ColdRoomTemperatures
|
||||
OUTPUT deleted.ColdRoomTemperatureID,
|
||||
deleted.ColdRoomSensorNumber,
|
||||
deleted.RecordedWhen,
|
||||
deleted.Temperature,
|
||||
deleted.ValidFrom,
|
||||
@TimeCounter
|
||||
INTO DataLoadSimulation.[ColdRoomTemperatures_temp]
|
||||
(ColdRoomTemperatureID,
|
||||
ColdRoomSensorNumber,
|
||||
RecordedWhen,
|
||||
Temperature,
|
||||
ValidFrom,
|
||||
ValidTo)
|
||||
|
||||
INSERT Warehouse.ColdRoomTemperatures
|
||||
(ColdRoomSensorNumber, RecordedWhen, Temperature, ValidFrom, ValidTo)
|
||||
VALUES
|
||||
(@SensorCounter + 1, @TimeCounter, @Temperature, @TimeCounter, @EndOfTime);
|
||||
-- populate data for the day in temp table
|
||||
DECLARE @ArchiveEndTime datetime2(7) = DATEADD(second, (0 - @AverageSecondsBetweenReadings), @TimeToFinishForTheDay)
|
||||
EXEC DataLoadSimulation.PopulateColdRoomTemperatures_temp @AverageSecondsBetweenReadings, @NumberOfSensors, @TimeCounter, @ArchiveEndTime
|
||||
|
||||
SET @SensorCounter += 1;
|
||||
END;
|
||||
SET @DelayInSeconds = CEILING(RAND() * @AverageSecondsBetweenReadings);
|
||||
SET @TimeCounter = DATEADD(second, @DelayInSeconds, @TimeCounter);
|
||||
END;
|
||||
-- move daily data into archive table
|
||||
DELETE DataLoadSimulation.ColdRoomTemperatures_temp
|
||||
OUTPUT deleted.ColdRoomTemperatureID,
|
||||
deleted.ColdRoomSensorNumber,
|
||||
deleted.RecordedWhen,
|
||||
deleted.Temperature,
|
||||
deleted.ValidFrom,
|
||||
deleted.ValidTo
|
||||
INTO Warehouse.ColdRoomTemperatures_Archive
|
||||
|
||||
-- add last daily reading to current table
|
||||
SET @SensorCounter = 0;
|
||||
WHILE @SensorCounter < @NumberOfSensors
|
||||
BEGIN
|
||||
SET @Temperature = 3 + RAND() * 2;
|
||||
|
||||
INSERT Warehouse.ColdRoomTemperatures
|
||||
(ColdRoomSensorNumber, RecordedWhen, Temperature, ValidFrom, ValidTo)
|
||||
VALUES
|
||||
(@SensorCounter + 1, @ArchiveEndTime, @Temperature, @ArchiveEndTime, @EndOfTime);
|
||||
|
||||
SET @SensorCounter += 1;
|
||||
END;
|
||||
|
||||
END;
|
||||
COMMIT
|
||||
END;
|
||||
GO
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
CREATE TABLE DataLoadSimulation.[ColdRoomTemperatures_temp] (
|
||||
[ColdRoomTemperatureID] BIGINT NOT NULL,
|
||||
[ColdRoomSensorNumber] INT NOT NULL,
|
||||
[RecordedWhen] DATETIME2 (7) NOT NULL,
|
||||
[Temperature] DECIMAL (10, 2) NOT NULL,
|
||||
[ValidFrom] DATETIME2 (7) NOT NULL,
|
||||
[ValidTo] DATETIME2 (7) NOT NULL,
|
||||
INDEX [IX_DataSimulation_ColdRoomTemperatures_ColdRoomSensorNumber]
|
||||
NONCLUSTERED HASH ([ColdRoomSensorNumber]) WITH (BUCKET_COUNT=100000)
|
||||
)
|
||||
WITH (MEMORY_OPTIMIZED = ON, DURABILITY=SCHEMA_ONLY);
|
||||
|
||||
@@ -420,14 +420,6 @@
|
||||
<AnsiNulls>On</AnsiNulls>
|
||||
<QuotedIdentifier>On</QuotedIdentifier>
|
||||
</Build>
|
||||
<Build Include="DataLoadSimulation\Stored Procedures\Configuration_ApplyDataLoadSimulationProcedures.sql">
|
||||
<AnsiNulls>On</AnsiNulls>
|
||||
<QuotedIdentifier>On</QuotedIdentifier>
|
||||
</Build>
|
||||
<Build Include="DataLoadSimulation\Stored Procedures\Configuration_RemoveDataLoadSimulationProcedures.sql">
|
||||
<AnsiNulls>On</AnsiNulls>
|
||||
<QuotedIdentifier>On</QuotedIdentifier>
|
||||
</Build>
|
||||
<Build Include="Website\Stored Procedures\InvoiceCustomerOrders.sql">
|
||||
<AnsiNulls>On</AnsiNulls>
|
||||
<QuotedIdentifier>On</QuotedIdentifier>
|
||||
@@ -700,6 +692,8 @@
|
||||
<Build Include="Application\Stored Procedures\Configuration_DisableInMemory.sql" />
|
||||
<Build Include="Application\Stored Procedures\Configuration_PrepareForAzure.sql" />
|
||||
<Build Include="SampleVersion.sql" />
|
||||
<Build Include="DataLoadSimulation\Tables\ColdRoomTemperatures_temp.sql" />
|
||||
<Build Include="DataLoadSimulation\Stored Procedures\PopulateColdRoomTemperatures_temp.sql" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PostDeploy Include="PostDeploymentScripts\Script.PostDeployment1.sql" />
|
||||
|
||||
Reference in New Issue
Block a user