Changeset 6267 for branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/Tools/prepareHiveDatabase.sql
- Timestamp:
- 05/24/11 16:55:48 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.4/Tools/prepareHiveDatabase.sql
r6229 r6267 1 USE [HeuristicLab.Hive-3.4] 1 2 /* this script is supposed to be executed after the plain DB is generated by the linq-to-sql schema */ 2 3 … … 108 109 GO 109 110 111 ALTER TABLE [dbo].[DeletedJobStatistics] ALTER COLUMN DeletedJobStatisticsId ADD ROWGUIDCOL; 112 ALTER TABLE [dbo].[DeletedJobStatistics] WITH NOCHECK ADD CONSTRAINT [DF_DeletedJobStatistics_DeletedJobStatisticsId] DEFAULT (newid()) FOR DeletedJobStatisticsId; 113 GO 114 110 115 ALTER TABLE [dbo].[SlaveStatistics] DROP CONSTRAINT [Statistics_SlaveStatistics] 111 116 ALTER TABLE [dbo].[SlaveStatistics] WITH CHECK ADD CONSTRAINT [Statistics_SlaveStatistics] FOREIGN KEY([StatisticsId]) … … 124 129 /* create indices */ 125 130 CREATE INDEX Index_RequiredPlugins_JobId ON RequiredPlugins(JobId); 131 GO 132 133 /* views */ 134 -- ============================================= 135 -- Author: cneumuel 136 -- Description: Returns the first StateLog entry for each job 137 -- ============================================= 138 CREATE VIEW [dbo].[view_FirstState] 139 AS 140 SELECT sl.JobId, sl.DateTime, sl.State 141 FROM dbo.StateLog AS sl INNER JOIN 142 (SELECT JobId, MIN(DateTime) AS DateTime 143 FROM dbo.StateLog 144 GROUP BY JobId) AS minDate ON sl.DateTime = minDate.DateTime AND sl.JobId = minDate.JobId 145 146 GO 147 148 -- ============================================= 149 -- Author: cneumuel 150 -- Description: Returns the last StateLog entry for each job 151 -- ============================================= 152 CREATE VIEW [dbo].[view_LastState] 153 AS 154 SELECT sl.JobId, sl.DateTime, sl.State 155 FROM dbo.StateLog AS sl INNER JOIN 156 (SELECT JobId, MAX(DateTime) AS DateTime 157 FROM dbo.StateLog 158 GROUP BY JobId) AS minDate ON sl.DateTime = minDate.DateTime AND sl.JobId = minDate.JobId 159 160 GO 126 161 127 162 /* triggers */ 128 USE [HeuristicLab.Hive-3.4]129 163 GO 130 164 /****** Object: Trigger [dbo].[tr_HiveExperimentDeleteCascade] Script Date: 04/19/2011 16:31:53 ******/ … … 136 170 -- Author: cneumuel 137 171 -- Create date: 19.04.2011 138 -- Description: Deletes all associated jobs. This cannot be done with cascading delete, 172 -- Description: (1) Writes the execution times of deleted jobs into DeletedJobStats to ensure correct statistics 173 -- (2) Deletes all associated jobs. This cannot be done with cascading delete, 139 174 -- because the job table defines a INSTEAD OF DELETE trigger itself, which 140 175 -- is not compatible with cascading deletes. … … 154 189 CREATE TRIGGER [dbo].[tr_JobDeleteCascade] ON [dbo].[Job] INSTEAD OF DELETE AS 155 190 BEGIN 191 -- add statistics 192 INSERT INTO dbo.DeletedJobStatistics (UserId, ExecutionTimeMs, ExecutionTimeMsFinishedJobs, StartToEndTimeMs) 193 SELECT 194 he.OwnerUserId AS UserId, 195 SUM(j.ExecutionTimeMs) AS ExecutionTimeMs, 196 SUM(CASE ls.State WHEN 'Finished' THEN j.ExecutionTimeMs END) AS ExecutionTimeMsFinishedJobs, 197 SUM(CASE ls.State WHEN 'Finished' THEN DATEDIFF(MS,fs.DateTime,ls.DateTime) ELSE 0 END) AS StartToEndMs 198 FROM 199 deleted j, 200 HiveExperiment he, 201 view_FirstState fs, 202 view_LastState ls 203 WHERE 204 he.HiveExperimentId = j.HiveExperimentId AND 205 fs.JobId = j.JobId AND 206 ls.JobId = j.JobId 207 GROUP BY he.OwnerUserId 208 209 -- recursively delete jobs 156 210 CREATE TABLE #Table( 157 211 JobId uniqueidentifier … … 186 240 --CREATE TRIGGER [dbo].[tr_DeletedJobStats] ON [dbo].[Job] AFTER DELETE AS 187 241 --BEGIN 188 -- INSERT INTO DeletedJobStats SELECT JobId, ExecutionTime FROM deleted 242 243 189 244 --END 245 --GO
Note: See TracChangeset
for help on using the changeset viewer.