From e7cb272626e3dbb9d3458e5e158241303e6652e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E4=B9=89=E8=B6=85?= Date: Fri, 24 Jul 2026 10:03:29 +0800 Subject: [PATCH 1/2] add composite index idx_project_start_time for workflow instance query --- .../src/main/resources/sql/dolphinscheduler_h2.sql | 3 ++- .../src/main/resources/sql/dolphinscheduler_mysql.sql | 3 ++- .../src/main/resources/sql/dolphinscheduler_postgresql.sql | 1 + .../sql/upgrade/3.5.0_schema/mysql/dolphinscheduler_ddl.sql | 1 + .../upgrade/3.5.0_schema/postgresql/dolphinscheduler_ddl.sql | 1 + 5 files changed, 7 insertions(+), 2 deletions(-) diff --git a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql index bbc7c2fa8223..62a6043c73be 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql @@ -636,7 +636,8 @@ CREATE TABLE t_ds_workflow_instance var_pool longtext, dry_run int NULL DEFAULT 0, restart_time datetime DEFAULT NULL, - PRIMARY KEY (id) + PRIMARY KEY (id), + INDEX idx_project_start_time (project_code, start_time) ); -- ---------------------------- diff --git a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql index cd5c9c936e49..1570be5b49e7 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql @@ -646,7 +646,8 @@ 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_start_time` (`project_code`, `start_time`) 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 e265aa741264..751a050bb558 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql @@ -589,6 +589,7 @@ 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_start_time on t_ds_workflow_instance (project_code, start_time); -- -- Table structure for table t_ds_project diff --git a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.5.0_schema/mysql/dolphinscheduler_ddl.sql b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.5.0_schema/mysql/dolphinscheduler_ddl.sql index d68a4463cf1d..3f7d3175979f 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.5.0_schema/mysql/dolphinscheduler_ddl.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.5.0_schema/mysql/dolphinscheduler_ddl.sql @@ -16,4 +16,5 @@ */ ALTER TABLE `t_ds_task_instance` ADD INDEX idx_project_submit_time (project_code ASC, submit_time DESC); +ALTER TABLE `t_ds_workflow_instance` ADD INDEX idx_project_start_time (project_code ASC, start_time DESC); diff --git a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.5.0_schema/postgresql/dolphinscheduler_ddl.sql b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.5.0_schema/postgresql/dolphinscheduler_ddl.sql index 6ce9d03a512a..61a5ae809a13 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.5.0_schema/postgresql/dolphinscheduler_ddl.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/upgrade/3.5.0_schema/postgresql/dolphinscheduler_ddl.sql @@ -16,3 +16,4 @@ */ CREATE INDEX idx_project_submit_time ON t_ds_task_instance (project_code ASC, submit_time DESC); +CREATE INDEX idx_project_start_time ON t_ds_workflow_instance (project_code ASC, start_time DESC); From ca41d03c40838dd4001004a964685eea338dd244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E4=B9=89=E8=B6=85?= Date: Fri, 24 Jul 2026 15:46:36 +0800 Subject: [PATCH 2/2] align index definitions between schema files and upgrade scripts --- .../src/main/resources/sql/dolphinscheduler_h2.sql | 6 +++--- .../src/main/resources/sql/dolphinscheduler_mysql.sql | 4 ++-- .../src/main/resources/sql/dolphinscheduler_postgresql.sql | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql index 62a6043c73be..1725b5c2df36 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql @@ -637,7 +637,7 @@ CREATE TABLE t_ds_workflow_instance dry_run int NULL DEFAULT 0, restart_time datetime DEFAULT NULL, PRIMARY KEY (id), - INDEX idx_project_start_time (project_code, start_time) + INDEX idx_project_start_time (project_code ASC, start_time DESC) ); -- ---------------------------- @@ -937,9 +937,9 @@ CREATE TABLE t_ds_task_instance dry_run int NULL DEFAULT 0, cpu_quota int(11) DEFAULT '-1' NOT NULL, memory_max int(11) DEFAULT '-1' NOT NULL, - PRIMARY KEY (id) + PRIMARY KEY (id), + INDEX idx_project_submit_time (project_code ASC, submit_time DESC) ); -CREATE INDEX idx_project_submit_time ON t_ds_task_instance (project_code, submit_time); -- ---------------------------- -- Records of t_ds_task_instance diff --git a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql index 1570be5b49e7..f6dfa61fc122 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql @@ -647,7 +647,7 @@ CREATE TABLE `t_ds_workflow_instance` ( PRIMARY KEY (`id`), KEY `workflow_instance_index` (`workflow_definition_code`,`id`) USING BTREE, KEY `start_time_index` (`start_time`,`end_time`) USING BTREE, - KEY `idx_project_start_time` (`project_code`, `start_time`) USING BTREE + KEY `idx_project_start_time` (`project_code` ASC, `start_time` DESC) USING BTREE ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE = utf8_bin; -- ---------------------------- @@ -939,7 +939,7 @@ CREATE TABLE `t_ds_task_instance` ( 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_project_submit_time` (`project_code`, `submit_time`) USING BTREE + KEY `idx_project_submit_time` (`project_code` ASC, `submit_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 751a050bb558..698b35768d94 100644 --- a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql +++ b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql @@ -589,7 +589,7 @@ 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_start_time on t_ds_workflow_instance (project_code, start_time); +create index idx_project_start_time on t_ds_workflow_instance (project_code ASC, start_time DESC); -- -- Table structure for table t_ds_project @@ -860,7 +860,7 @@ 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_submit_time on t_ds_task_instance (project_code, submit_time DESC); +create index idx_project_submit_time on t_ds_task_instance (project_code ASC, submit_time DESC); -- -- Table structure for t_ds_task_instance_context