Changeset 12768 for branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/SQL Scripts
- Timestamp:
- 07/16/15 15:09:12 (9 years ago)
- Location:
- branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/SQL Scripts
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/SQL Scripts/Initialize Hive Database.sql
r12584 r12768 131 131 [DateEnqueued] DateTime NOT NULL, 132 132 CONSTRAINT [PK_UserPriority] PRIMARY KEY ([UserId]) 133 )134 CREATE TABLE [DeletedJobStatistics](135 [UserId] UniqueIdentifier NOT NULL,136 [ExecutionTimeS] float NOT NULL,137 [ExecutionTimeSFinishedJobs] float NOT NULL,138 [StartToEndTimeS] float NOT NULL,139 [DeletedJobStatisticsId] UniqueIdentifier NOT NULL,140 CONSTRAINT [PK_DeletedJobStatistics] PRIMARY KEY ([DeletedJobStatisticsId])141 )142 CREATE TABLE [UserStatistics](143 [StatisticsId] UniqueIdentifier NOT NULL,144 [UserId] UniqueIdentifier NOT NULL,145 [ExecutionTimeMs] float NOT NULL,146 [UsedCores] Int NOT NULL,147 [ExecutionTimeMsFinishedJobs] float NOT NULL,148 [StartToEndTimeMs] float NOT NULL,149 CONSTRAINT [PK_UserStatistics] PRIMARY KEY ([StatisticsId], [UserId])150 )151 CREATE TABLE [SlaveStatistics](152 [StatisticsId] UniqueIdentifier NOT NULL,153 [SlaveId] UniqueIdentifier NOT NULL,154 [Cores] Int NOT NULL,155 [FreeCores] Int NOT NULL,156 [CpuUtilization] float NOT NULL,157 [Memory] Int NOT NULL,158 [FreeMemory] Int NOT NULL,159 CONSTRAINT [PK_SlaveStatistics] PRIMARY KEY ([StatisticsId], [SlaveId])160 )161 CREATE TABLE [Statistics](162 [StatisticsId] UniqueIdentifier NOT NULL,163 [Timestamp] DateTime NOT NULL,164 CONSTRAINT [PK_Statistics] PRIMARY KEY ([StatisticsId])165 133 ) 166 134 ALTER TABLE [dbo].[AssignedResources] … … 192 160 ALTER TABLE [dbo].[JobPermission] 193 161 ADD CONSTRAINT [Job_JobPermission] FOREIGN KEY ([JobId]) REFERENCES [dbo].[Job]([JobId]) 194 ALTER TABLE [UserStatistics]195 ADD CONSTRAINT [Statistics_UserStatistics] FOREIGN KEY ([StatisticsId]) REFERENCES [Statistics]([StatisticsId])196 ALTER TABLE [SlaveStatistics]197 ADD CONSTRAINT [Statistics_SlaveStatistics] FOREIGN KEY ([StatisticsId]) REFERENCES [Statistics]([StatisticsId])198 162 199 163 GO -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/SQL Scripts/Prepare Hive Database.sql
r12761 r12768 93 93 GO 94 94 95 ALTER TABLE [dbo].[Statistics] ALTER COLUMN StatisticsId ADD ROWGUIDCOL;96 ALTER TABLE [dbo].[Statistics] WITH NOCHECK ADD CONSTRAINT [DF_Statistics_StatisticsId] DEFAULT (NEWSEQUENTIALID()) FOR StatisticsId;97 GO98 99 ALTER TABLE [dbo].[DeletedJobStatistics] ALTER COLUMN DeletedJobStatisticsId ADD ROWGUIDCOL;100 ALTER TABLE [dbo].[DeletedJobStatistics] WITH NOCHECK ADD CONSTRAINT [DF_DeletedJobStatistics_DeletedJobStatisticsId] DEFAULT (NEWSEQUENTIALID()) FOR DeletedJobStatisticsId;101 GO102 103 ALTER TABLE [dbo].[SlaveStatistics] DROP CONSTRAINT [Statistics_SlaveStatistics]104 ALTER TABLE [dbo].[SlaveStatistics] WITH CHECK ADD CONSTRAINT [Statistics_SlaveStatistics] FOREIGN KEY([StatisticsId])105 REFERENCES [dbo].[Statistics] ([StatisticsId])106 ON UPDATE CASCADE107 ON DELETE CASCADE108 GO109 110 ALTER TABLE [dbo].[UserStatistics] DROP CONSTRAINT [Statistics_UserStatistics]111 ALTER TABLE [dbo].[UserStatistics] WITH CHECK ADD CONSTRAINT [Statistics_UserStatistics] FOREIGN KEY([StatisticsId])112 REFERENCES [dbo].[Statistics] ([StatisticsId])113 ON UPDATE CASCADE114 ON DELETE CASCADE115 GO116 117 95 /* create indices */ 118 96 CREATE INDEX Index_RequiredPlugins_TaskId ON RequiredPlugins(TaskId); … … 147 125 GO 148 126 149 -- =============================================150 -- Author: cneumuel151 -- Description: returns aggregates statistic information for every minute152 -- =============================================153 CREATE VIEW [dbo].[view_Statistics]154 AS155 SELECT CONVERT(VARCHAR(19), MIN(s.Timestamp), 120) AS DateTime, SUM(ss.Cores) AS Cores, SUM(ss.FreeCores) AS FreeCores,156 AVG(ss.CpuUtilization) AS CpuUtilization, SUM(ss.Memory) AS Memory, SUM(ss.FreeMemory) AS FreeMemory, x.exSum AS ExecutionTimeHours,157 x.exFinishedSum AS ExecutionTimeFinished, x.exStartToEndSum AS StartToEndTimeFinished158 FROM dbo.SlaveStatistics AS ss INNER JOIN159 dbo.[Statistics] AS s ON ss.StatisticsId = s.StatisticsId INNER JOIN160 dbo.Resource AS r ON ss.SlaveId = r.ResourceId INNER JOIN161 (SELECT StatisticsId, SUM(ExecutionTimeMs) / 1000 / 60 / 60 AS exSum, SUM(ExecutionTimeMsFinishedJobs) / 1000 / 60 / 60 AS exFinishedSum,162 SUM(StartToEndTimeMs) / 1000 / 60 / 60 AS exStartToEndSum163 FROM dbo.UserStatistics AS us164 GROUP BY StatisticsId) AS x ON s.StatisticsId = x.StatisticsId165 GROUP BY s.StatisticsId, x.exSum, x.exFinishedSum, x.exStartToEndSum166 167 /* triggers */168 GO169 127 /****** Object: Trigger [dbo].[tr_JobDeleteCascade] Script Date: 04/19/2011 16:31:53 ******/ 170 128 SET ANSI_NULLS ON … … 191 149 -- Create date: 11.11.2010 192 150 -- Description: Recursively deletes all child-jobs of a job when it is deleted. (Source: http://devio.wordpress.com/2008/05/23/recursive-delete-in-sql-server/) 193 -- ============================================= 151 -- =============================================DeletedJobStatistics 194 152 CREATE TRIGGER [dbo].[tr_TaskDeleteCascade] ON [dbo].[Task] INSTEAD OF DELETE AS 195 153 BEGIN 196 -- add statistics197 INSERT INTO dbo.DeletedJobStatistics (UserId, ExecutionTimeS, ExecutionTimeSFinishedJobs, StartToEndTimeS)198 154 SELECT 199 155 he.OwnerUserId AS UserId, … … 238 194 GO 239 195 240 241 CREATE TRIGGER [dbo].[tr_StatisticsDeleteCascade] ON [dbo].[Statistics] INSTEAD OF DELETE AS242 BEGIN243 DELETE SlaveStatistics FROM deleted, SlaveStatistics WHERE deleted.StatisticsId = SlaveStatistics.StatisticsId244 -- should also remove UserStatistics here245 DELETE [Statistics] FROM deleted, [Statistics] WHERE deleted.StatisticsId = [Statistics].StatisticsId246 END247 GO248 249 250 196 -- ============================================================ 251 197 -- Description: Create indices to speed up execution of queries
Note: See TracChangeset
for help on using the changeset viewer.