diff --git a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql index ea80068e49d4..5d5b0ca6ae63 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql @@ -646,7 +646,9 @@ CREATE TABLE `t_ds_workflow_instance` ( `restart_time` datetime DEFAULT NULL COMMENT 'workflow instance restart time', PRIMARY KEY (`id`), KEY `workflow_instance_index` (`workflow_definition_code`,`id`) USING BTREE, - KEY `start_time_index` (`start_time`,`end_time`) USING BTREE + KEY `start_time_index` (`start_time`,`end_time`) USING BTREE, + KEY `idx_project_code_start_time` (`project_code`, `start_time` DESC, `id` DESC) USING BTREE, + KEY `idx_workflow_definition_code_start_time` (`workflow_definition_code`, `start_time` DESC) USING BTREE ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE = utf8_bin; -- ---------------------------- @@ -937,7 +939,9 @@ CREATE TABLE `t_ds_task_instance` ( `memory_max` int(11) DEFAULT '-1' NOT NULL COMMENT 'MemoryMax(MB): -1:Infinity', PRIMARY KEY (`id`), KEY `workflow_instance_id` (`workflow_instance_id`) USING BTREE, - KEY `idx_code_version` (`task_code`, `task_definition_version`) USING BTREE + KEY `idx_code_version` (`task_code`, `task_definition_version`) USING BTREE, + KEY `idx_project_code_submit_time` (`project_code`, `submit_time` DESC) USING BTREE, + KEY `idx_project_code_start_time` (`project_code`, `start_time` DESC) USING BTREE ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE = utf8_bin; -- ---------------------------- diff --git a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql index afe1b957cde9..c5b0a27cd1c9 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql @@ -589,6 +589,8 @@ CREATE TABLE t_ds_workflow_instance ( create index workflow_instance_index on t_ds_workflow_instance (workflow_definition_code,id); create index start_time_index on t_ds_workflow_instance (start_time,end_time); +create index idx_project_code_start_time on t_ds_workflow_instance (project_code, start_time DESC, id DESC); +create index idx_workflow_definition_code_start_time on t_ds_workflow_instance (workflow_definition_code, start_time DESC); -- -- Table structure for table t_ds_project @@ -859,6 +861,9 @@ CREATE TABLE t_ds_task_instance ( ) ; create index idx_task_instance_code_version on t_ds_task_instance (task_code, task_definition_version); +create index idx_project_code_submit_time on t_ds_task_instance (project_code, submit_time DESC); +create index idx_workflow_instance_id on t_ds_task_instance (workflow_instance_id); +create index idx_project_code_start_time on t_ds_task_instance (project_code, start_time DESC); -- -- Table structure for t_ds_task_instance_context diff --git a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.4.0_schema/mysql/dolphinscheduler_ddl.sql b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.4.0_schema/mysql/dolphinscheduler_ddl.sql index 3a9fff25efe2..7df6c1209790 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.4.0_schema/mysql/dolphinscheduler_ddl.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.4.0_schema/mysql/dolphinscheduler_ddl.sql @@ -36,3 +36,8 @@ CREATE TABLE IF NOT EXISTS `t_ds_serial_command` ( KEY `idx_workflow_instance_id` (`workflow_instance_id`) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE = utf8_bin; +-- Add indexes for workflow instance and task instance +ALTER TABLE `t_ds_workflow_instance` ADD INDEX `idx_project_code_start_time` (`project_code`, `start_time` DESC, `id` DESC) USING BTREE; +ALTER TABLE `t_ds_workflow_instance` ADD INDEX `idx_workflow_definition_code_start_time` (`workflow_definition_code`, `start_time` DESC) USING BTREE; +ALTER TABLE `t_ds_task_instance` ADD INDEX `idx_project_code_submit_time` (`project_code`, `submit_time` DESC) USING BTREE; +ALTER TABLE `t_ds_task_instance` ADD INDEX `idx_project_code_start_time` (`project_code`, `start_time` DESC) USING BTREE; diff --git a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.4.0_schema/postgresql/dolphinscheduler_ddl.sql b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.4.0_schema/postgresql/dolphinscheduler_ddl.sql index 5d2beea9a028..7b2e2fec4237 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.4.0_schema/postgresql/dolphinscheduler_ddl.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.4.0_schema/postgresql/dolphinscheduler_ddl.sql @@ -43,3 +43,9 @@ COMMENT ON COLUMN "t_ds_serial_command"."state" IS 'state of the serial queue: 0 COMMENT ON COLUMN "t_ds_serial_command"."command" IS 'command json'; COMMENT ON COLUMN "t_ds_serial_command"."create_time" IS 'create time'; COMMENT ON COLUMN "t_ds_serial_command"."update_time" IS 'update time'; + +-- Add indexes for workflow instance and task instance +CREATE INDEX idx_project_code_start_time ON t_ds_workflow_instance (project_code, start_time DESC, id DESC); +CREATE INDEX idx_workflow_definition_code_start_time ON t_ds_workflow_instance (workflow_definition_code, start_time DESC); +CREATE INDEX idx_project_code_submit_time ON t_ds_task_instance (project_code, submit_time DESC); +CREATE INDEX idx_project_code_start_time ON t_ds_task_instance (project_code, start_time DESC);