Changeset 6721 for branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.3/SQL Scripts
- Timestamp:
- 09/08/11 13:41:25 (13 years ago)
- Location:
- branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.3/SQL Scripts
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.3/SQL Scripts/Initialize Hive Database.sql
r6712 r6721 5 5 CREATE TABLE [dbo].[AssignedResources]( 6 6 [ResourceId] UniqueIdentifier NOT NULL, 7 [ JobId] UniqueIdentifier NOT NULL,8 CONSTRAINT [PK_dbo.ResourceId JobId] PRIMARY KEY ([ResourceId], [JobId])7 [TaskId] UniqueIdentifier NOT NULL, 8 CONSTRAINT [PK_dbo.ResourceIdTaskId] PRIMARY KEY ([ResourceId], [TaskId]) 9 9 ) 10 10 CREATE TABLE [dbo].[Plugin]( … … 19 19 CREATE TABLE [dbo].[RequiredPlugins]( 20 20 [RequiredPluginId] UniqueIdentifier NOT NULL, 21 [ JobId] UniqueIdentifier NOT NULL,21 [TaskId] UniqueIdentifier NOT NULL, 22 22 [PluginId] UniqueIdentifier NOT NULL, 23 23 CONSTRAINT [PK_dbo.RequiredPlugins] PRIMARY KEY ([RequiredPluginId]) … … 42 42 CONSTRAINT [PK_dbo.Resource] PRIMARY KEY ([ResourceId]) 43 43 ) 44 CREATE TABLE [dbo].[ Job](45 [ JobId] UniqueIdentifier NOT NULL,46 [ JobState] VarChar(30),44 CREATE TABLE [dbo].[Task]( 45 [TaskId] UniqueIdentifier NOT NULL, 46 [TaskState] VarChar(30), 47 47 [ExecutionTimeMs] float, 48 48 [LastHeartbeat] DateTime, 49 [Parent JobId] UniqueIdentifier,49 [ParentTaskId] UniqueIdentifier, 50 50 [Priority] Int NOT NULL, 51 51 [CoresNeeded] Int NOT NULL, 52 52 [MemoryNeeded] Int NOT NULL, 53 [IsParent Job] Bit,53 [IsParentTask] Bit, 54 54 [FinishWhenChildJobsFinished] Bit, 55 55 [Command] VarChar(30), 56 56 [HiveExperimentId] UniqueIdentifier NOT NULL, 57 57 [IsPrivileged] Bit, 58 CONSTRAINT [PK_dbo. Job] PRIMARY KEY ([JobId])58 CONSTRAINT [PK_dbo.Task] PRIMARY KEY ([TaskId]) 59 59 ) 60 60 CREATE TABLE [dbo].[Downtime]( … … 79 79 CONSTRAINT [PK_dbo.HiveExperiment] PRIMARY KEY ([HiveExperimentId]) 80 80 ) 81 CREATE TABLE [dbo].[ JobData](82 [ JobId] UniqueIdentifier NOT NULL,81 CREATE TABLE [dbo].[TaskData]( 82 [TaskId] UniqueIdentifier NOT NULL, 83 83 [Data] VarBinary(MAX), 84 84 [LastUpdate] DateTime, 85 CONSTRAINT [PK_dbo. JobData] PRIMARY KEY ([JobId])85 CONSTRAINT [PK_dbo.TaskData] PRIMARY KEY ([TaskId]) 86 86 ) 87 87 CREATE TABLE [dbo].[PluginData]( … … 96 96 [State] VarChar(30) NOT NULL, 97 97 [DateTime] DateTime NOT NULL, 98 [ JobId] UniqueIdentifier NOT NULL,98 [TaskId] UniqueIdentifier NOT NULL, 99 99 [UserId] UniqueIdentifier, 100 100 [SlaveId] UniqueIdentifier, … … 149 149 ADD CONSTRAINT [Resource_AssignedResource] FOREIGN KEY ([ResourceId]) REFERENCES [dbo].[Resource]([ResourceId]) 150 150 ALTER TABLE [dbo].[AssignedResources] 151 ADD CONSTRAINT [ Job_AssignedResource] FOREIGN KEY ([JobId]) REFERENCES [dbo].[Job]([JobId])151 ADD CONSTRAINT [Task_AssignedResource] FOREIGN KEY ([TaskId]) REFERENCES [dbo].[Task]([TaskId]) 152 152 ALTER TABLE [dbo].[RequiredPlugins] 153 153 ADD CONSTRAINT [Plugin_RequiredPlugin] FOREIGN KEY ([PluginId]) REFERENCES [dbo].[Plugin]([PluginId]) 154 154 ALTER TABLE [dbo].[RequiredPlugins] 155 ADD CONSTRAINT [ Job_RequiredPlugin] FOREIGN KEY ([JobId]) REFERENCES [dbo].[Job]([JobId])155 ADD CONSTRAINT [Task_RequiredPlugin] FOREIGN KEY ([TaskId]) REFERENCES [dbo].[Task]([TaskId]) 156 156 ALTER TABLE [dbo].[Resource] 157 157 ADD CONSTRAINT [Resource_Resource] FOREIGN KEY ([ParentResourceId]) REFERENCES [dbo].[Resource]([ResourceId]) 158 ALTER TABLE [dbo].[ Job]159 ADD CONSTRAINT [ Job_Job] FOREIGN KEY ([ParentJobId]) REFERENCES [dbo].[Job]([JobId])160 ALTER TABLE [dbo].[ Job]158 ALTER TABLE [dbo].[Task] 159 ADD CONSTRAINT [Task_Task] FOREIGN KEY ([ParentTaskId]) REFERENCES [dbo].[Task]([TaskId]) 160 ALTER TABLE [dbo].[Task] 161 161 ADD CONSTRAINT [HiveExperiment_Job] FOREIGN KEY ([HiveExperimentId]) REFERENCES [dbo].[HiveExperiment]([HiveExperimentId]) 162 162 ALTER TABLE [dbo].[Downtime] 163 163 ADD CONSTRAINT [Resource_Downtime] FOREIGN KEY ([ResourceId]) REFERENCES [dbo].[Resource]([ResourceId]) 164 ALTER TABLE [dbo].[ JobData]165 ADD CONSTRAINT [ Job_JobData] FOREIGN KEY ([JobId]) REFERENCES [dbo].[Job]([JobId])164 ALTER TABLE [dbo].[TaskData] 165 ADD CONSTRAINT [Task_TaskData] FOREIGN KEY ([TaskId]) REFERENCES [dbo].[Task]([TaskId]) 166 166 ALTER TABLE [dbo].[PluginData] 167 167 ADD CONSTRAINT [Plugin_PluginData] FOREIGN KEY ([PluginId]) REFERENCES [dbo].[Plugin]([PluginId]) 168 168 ALTER TABLE [dbo].[StateLog] 169 ADD CONSTRAINT [ Job_StateLog] FOREIGN KEY ([JobId]) REFERENCES [dbo].[Job]([JobId])169 ADD CONSTRAINT [Task_StateLog] FOREIGN KEY ([TaskId]) REFERENCES [dbo].[Task]([TaskId]) 170 170 ALTER TABLE [dbo].[StateLog] 171 171 ADD CONSTRAINT [Resource_StateLog] FOREIGN KEY ([SlaveId]) REFERENCES [dbo].[Resource]([ResourceId]) -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.3/SQL Scripts/Prepare Hive Database.sql
r6712 r6721 8 8 9 9 10 ALTER TABLE [dbo].[AssignedResources] DROP CONSTRAINT [ Job_AssignedResource]11 ALTER TABLE [dbo].[AssignedResources] WITH CHECK ADD CONSTRAINT [ Job_AssignedResource] FOREIGN KEY([JobId])12 REFERENCES [dbo].[ Job] ([JobId])10 ALTER TABLE [dbo].[AssignedResources] DROP CONSTRAINT [Task_AssignedResource] 11 ALTER TABLE [dbo].[AssignedResources] WITH CHECK ADD CONSTRAINT [Task_AssignedResource] FOREIGN KEY([TaskId]) 12 REFERENCES [dbo].[Task] ([TaskId]) 13 13 ON UPDATE CASCADE 14 14 ON DELETE CASCADE … … 21 21 GO 22 22 23 ALTER TABLE dbo. Job ALTER COLUMN JobId ADD ROWGUIDCOL;24 ALTER TABLE dbo. Job WITH NOCHECK ADD CONSTRAINT [DF_Job_JobId] DEFAULT (NEWSEQUENTIALID()) FOR JobId;25 GO 26 27 ALTER TABLE [dbo].[StateLog] DROP CONSTRAINT [ Job_StateLog]28 ALTER TABLE [dbo].[StateLog] WITH CHECK ADD CONSTRAINT [ Job_StateLog] FOREIGN KEY([JobId])29 REFERENCES [dbo].[ Job] ([JobId])23 ALTER TABLE dbo.Task ALTER COLUMN TaskId ADD ROWGUIDCOL; 24 ALTER TABLE dbo.Task WITH NOCHECK ADD CONSTRAINT [DF_Task_TaskId] DEFAULT (NEWSEQUENTIALID()) FOR TaskId; 25 GO 26 27 ALTER TABLE [dbo].[StateLog] DROP CONSTRAINT [Task_StateLog] 28 ALTER TABLE [dbo].[StateLog] WITH CHECK ADD CONSTRAINT [Task_StateLog] FOREIGN KEY([TaskId]) 29 REFERENCES [dbo].[Task] ([TaskId]) 30 30 ON UPDATE CASCADE 31 31 ON DELETE CASCADE … … 54 54 ALTER TABLE dbo.RequiredPlugins WITH NOCHECK ADD CONSTRAINT [DF_RequiredPlugins_RequiredPluginId] DEFAULT (NEWSEQUENTIALID()) FOR RequiredPluginId; 55 55 56 ALTER TABLE [dbo].[RequiredPlugins] DROP CONSTRAINT [ Job_RequiredPlugin]57 ALTER TABLE [dbo].[RequiredPlugins] WITH CHECK ADD CONSTRAINT [ Job_RequiredPlugin] FOREIGN KEY([JobId])58 REFERENCES [dbo].[ Job] ([JobId])56 ALTER TABLE [dbo].[RequiredPlugins] DROP CONSTRAINT [Task_RequiredPlugin] 57 ALTER TABLE [dbo].[RequiredPlugins] WITH CHECK ADD CONSTRAINT [Task_RequiredPlugin] FOREIGN KEY([TaskId]) 58 REFERENCES [dbo].[Task] ([TaskId]) 59 59 ON UPDATE CASCADE 60 60 ON DELETE CASCADE … … 110 110 111 111 /* create indices */ 112 CREATE INDEX Index_RequiredPlugins_ JobId ON RequiredPlugins(JobId);112 CREATE INDEX Index_RequiredPlugins_TaskId ON RequiredPlugins(TaskId); 113 113 GO 114 114 … … 120 120 CREATE VIEW [dbo].[view_FirstState] 121 121 AS 122 SELECT sl. JobId, sl.DateTime, sl.State122 SELECT sl.TaskId, sl.DateTime, sl.State 123 123 FROM dbo.StateLog AS sl INNER JOIN 124 (SELECT JobId, MIN(DateTime) AS DateTime124 (SELECT TaskId, MIN(DateTime) AS DateTime 125 125 FROM dbo.StateLog 126 GROUP BY JobId) AS minDate ON sl.DateTime = minDate.DateTime AND sl.JobId = minDate.JobId126 GROUP BY TaskId) AS minDate ON sl.DateTime = minDate.DateTime AND sl.TaskId = minDate.TaskId 127 127 128 128 GO … … 134 134 CREATE VIEW [dbo].[view_LastState] 135 135 AS 136 SELECT sl. JobId, sl.DateTime, sl.State136 SELECT sl.TaskId, sl.DateTime, sl.State 137 137 FROM dbo.StateLog AS sl INNER JOIN 138 (SELECT JobId, MAX(DateTime) AS DateTime138 (SELECT TaskId, MAX(DateTime) AS DateTime 139 139 FROM dbo.StateLog 140 GROUP BY JobId) AS minDate ON sl.DateTime = minDate.DateTime AND sl.JobId = minDate.JobId140 GROUP BY TaskId) AS minDate ON sl.DateTime = minDate.DateTime AND sl.TaskId = minDate.TaskId 141 141 GO 142 142 … … 176 176 CREATE TRIGGER [dbo].[tr_HiveExperimentDeleteCascade] ON [dbo].[HiveExperiment] INSTEAD OF DELETE AS 177 177 BEGIN 178 DELETE Job FROM deleted, Job WHERE deleted.HiveExperimentId = Job.HiveExperimentId178 DELETE Task FROM deleted, Task WHERE deleted.HiveExperimentId = Task.HiveExperimentId 179 179 DELETE HiveExperiment FROM deleted, HiveExperiment WHERE deleted.HiveExperimentId = HiveExperiment.HiveExperimentId 180 180 END … … 186 186 -- 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/) 187 187 -- ============================================= 188 CREATE TRIGGER [dbo].[tr_JobDeleteCascade] ON [dbo].[ Job] INSTEAD OF DELETE AS188 CREATE TRIGGER [dbo].[tr_JobDeleteCascade] ON [dbo].[Task] INSTEAD OF DELETE AS 189 189 BEGIN 190 190 -- add statistics … … 202 202 WHERE 203 203 he.HiveExperimentId = j.HiveExperimentId AND 204 fs. JobId = j.JobId AND205 ls. JobId = j.JobId204 fs.TaskId = j.TaskId AND 205 ls.TaskId = j.TaskId 206 206 GROUP BY he.OwnerUserId 207 207 208 208 -- recursively delete jobs 209 209 CREATE TABLE #Table( 210 JobId uniqueidentifier210 TaskId uniqueidentifier 211 211 ) 212 INSERT INTO #Table ( JobId)213 SELECT JobId FROM deleted212 INSERT INTO #Table (TaskId) 213 SELECT TaskId FROM deleted 214 214 215 215 DECLARE @c INT 216 216 SET @c = 0 217 217 218 WHILE @c <> (SELECT COUNT( JobId) FROM #Table) BEGIN219 SELECT @c = COUNT( JobId) FROM #Table218 WHILE @c <> (SELECT COUNT(TaskId) FROM #Table) BEGIN 219 SELECT @c = COUNT(TaskId) FROM #Table 220 220 221 INSERT INTO #Table ( JobId)222 SELECT Job.JobId223 FROM Job224 LEFT OUTER JOIN #Table ON Job.JobId = #Table.JobId225 WHERE Job.ParentJobId IN (SELECT JobId FROM #Table)226 AND #Table. JobId IS NULL221 INSERT INTO #Table (TaskId) 222 SELECT Task.TaskId 223 FROM Task 224 LEFT OUTER JOIN #Table ON Task.TaskId = #Table.TaskId 225 WHERE Task.ParentTaskId IN (SELECT TaskId FROM #Table) 226 AND #Table.TaskId IS NULL 227 227 END 228 228 229 DELETE JobData FROM JobData INNER JOIN #Table ON JobData.JobId = #Table.JobId230 DELETE Job FROM Job INNER JOIN #Table ON Job.JobId = #Table.JobId229 DELETE TaskData FROM TaskData INNER JOIN #Table ON TaskData.TaskId = #Table.TaskId 230 DELETE Task FROM Task INNER JOIN #Table ON Task.TaskId = #Table.TaskId 231 231 END 232 232 GO … … 235 235 -- Author: cneumuel 236 236 -- Create date: 17.05.2011 237 -- Description: Writes the execution times of deleted jobs into DeletedJobStats to ensure correct statistics238 -- ============================================= 239 --CREATE TRIGGER [dbo].[tr_DeletedJobStats] ON [dbo].[ Job] AFTER DELETE AS237 -- Description: Writes the execution times of deleted Tasks into DeletedJobStats to ensure correct statistics 238 -- ============================================= 239 --CREATE TRIGGER [dbo].[tr_DeletedJobStats] ON [dbo].[Task] AFTER DELETE AS 240 240 --BEGIN 241 241 -
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.DataAccess/3.3/SQL Scripts/Query Jobs.sql
r6712 r6721 1 1 /****** Script for SelectTopNRows command from SSMS ******/ 2 SELECT j.[ JobId]3 ,j.[ JobState]2 SELECT j.[TaskId] 3 ,j.[TaskState] 4 4 ,j.[ExecutionTimeMs]/1000/60/60 AS ExecutionTimeHours 5 5 ,DATALENGTH(jd.data)/1024.0/1024.0 AS MB … … 13 13 ,j.[IsPrivileged] 14 14 ,j.[Command] 15 ,j.[IsParent Job]15 ,j.[IsParentTask] 16 16 ,j.[FinishWhenChildJobsFinished] 17 ,j.[Parent JobId]17 ,j.[ParentTaskId] 18 18 , he.HiveExperimentId 19 19 FROM 20 [HeuristicLab.Hive-3.3].[dbo].[ Job] j20 [HeuristicLab.Hive-3.3].[dbo].[Task] j 21 21 ,[HeuristicLab.Hive-3.3].[dbo].[HiveExperiment] he 22 22 ,[HeuristicLab.Authentication].dbo.aspnet_Users u 23 ,[HeuristicLab.Hive-3.3].dbo. JobData jd23 ,[HeuristicLab.Hive-3.3].dbo.TaskData jd 24 24 WHERE 25 25 j.HiveExperimentId = he.HiveExperimentId 26 AND j. JobId = jd.JobId26 AND j.TaskId = jd.TaskId 27 27 AND he.OwnerUserId = u.UserId 28 28 --AND he.DateCreated > '06-03-2011 10:30' 29 29 30 ORDER BY j. JobState, he.DateCreated DESC30 ORDER BY j.TaskState, he.DateCreated DESC
Note: See TracChangeset
for help on using the changeset viewer.