This is an automated email from the ASF dual-hosted git repository.

SbloodyS pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new 3752346650 [Improvement-18439][API]Add composite index 
idx_project_start_time for workflow instance query (#18440)
3752346650 is described below

commit 375234665081ccf9e56819580957842e0e3e84e9
Author: suyc <[email protected]>
AuthorDate: Sun Jul 26 18:07:02 2026 +0800

    [Improvement-18439][API]Add composite index idx_project_start_time for 
workflow instance query (#18440)
---
 .../src/main/resources/sql/dolphinscheduler_h2.sql                 | 7 ++++---
 .../src/main/resources/sql/dolphinscheduler_mysql.sql              | 5 +++--
 .../src/main/resources/sql/dolphinscheduler_postgresql.sql         | 3 ++-
 .../sql/upgrade/3.5.0_schema/mysql/dolphinscheduler_ddl.sql        | 1 +
 .../sql/upgrade/3.5.0_schema/postgresql/dolphinscheduler_ddl.sql   | 1 +
 5 files changed, 11 insertions(+), 6 deletions(-)

diff --git 
a/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql 
b/dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_h2.sql
index bbc7c2fa82..1725b5c2df 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 ASC, start_time DESC)
 );
 
 -- ----------------------------
@@ -936,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 cd5c9c936e..f6dfa61fc1 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` ASC, `start_time` DESC) USING 
BTREE
 ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE = utf8_bin;
 
 -- ----------------------------
@@ -938,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 e265aa7412..698b35768d 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 
ASC, start_time DESC);
 
 --
 -- Table structure for table t_ds_project
@@ -859,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
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 d68a4463cf..3f7d317597 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 6ce9d03a51..61a5ae809a 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);

Reply via email to