Skip to content

Commit a31ac50

Browse files
committed
[Improvement-17755][Dao]optimize pagination query performance by adding indexes
1 parent 4505d4b commit a31ac50

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_mysql.sql

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,9 @@ CREATE TABLE `t_ds_workflow_instance` (
646646
`restart_time` datetime DEFAULT NULL COMMENT 'workflow instance restart time',
647647
PRIMARY KEY (`id`),
648648
KEY `workflow_instance_index` (`workflow_definition_code`,`id`) USING BTREE,
649-
KEY `start_time_index` (`start_time`,`end_time`) USING BTREE
649+
KEY `start_time_index` (`start_time`,`end_time`) USING BTREE,
650+
KEY `idx_project_code_start_time` (`project_code`, `start_time` DESC, `id` DESC) USING BTREE,
651+
KEY `idx_workflow_definition_code_start_time` (`workflow_definition_code`, `start_time` DESC) USING BTREE
650652
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE = utf8_bin;
651653

652654
-- ----------------------------
@@ -937,7 +939,9 @@ CREATE TABLE `t_ds_task_instance` (
937939
`memory_max` int(11) DEFAULT '-1' NOT NULL COMMENT 'MemoryMax(MB): -1:Infinity',
938940
PRIMARY KEY (`id`),
939941
KEY `workflow_instance_id` (`workflow_instance_id`) USING BTREE,
940-
KEY `idx_code_version` (`task_code`, `task_definition_version`) USING BTREE
942+
KEY `idx_code_version` (`task_code`, `task_definition_version`) USING BTREE,
943+
KEY `idx_project_code_submit_time` (`project_code`, `submit_time` DESC) USING BTREE,
944+
KEY `idx_project_code_start_time` (`project_code`, `start_time` DESC) USING BTREE
941945
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE = utf8_bin;
942946

943947
-- ----------------------------

dolphinscheduler-dao/src/main/resources/sql/dolphinscheduler_postgresql.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,8 @@ CREATE TABLE t_ds_workflow_instance (
589589

590590
create index workflow_instance_index on t_ds_workflow_instance (workflow_definition_code,id);
591591
create index start_time_index on t_ds_workflow_instance (start_time,end_time);
592+
create index idx_project_code_start_time on t_ds_workflow_instance (project_code, start_time DESC, id DESC);
593+
create index idx_workflow_definition_code_start_time on t_ds_workflow_instance (workflow_definition_code, start_time DESC);
592594

593595
--
594596
-- Table structure for table t_ds_project
@@ -859,6 +861,9 @@ CREATE TABLE t_ds_task_instance (
859861
) ;
860862

861863
create index idx_task_instance_code_version on t_ds_task_instance (task_code, task_definition_version);
864+
create index idx_project_code_submit_time on t_ds_task_instance (project_code, submit_time DESC);
865+
create index idx_workflow_instance_id on t_ds_task_instance (workflow_instance_id);
866+
create index idx_project_code_start_time on t_ds_task_instance (project_code, start_time DESC);
862867

863868
--
864869
-- Table structure for t_ds_task_instance_context

dolphinscheduler-dao/src/main/resources/sql/upgrade/3.4.0_schema/mysql/dolphinscheduler_ddl.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@ CREATE TABLE IF NOT EXISTS `t_ds_serial_command` (
3636
KEY `idx_workflow_instance_id` (`workflow_instance_id`)
3737
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE = utf8_bin;
3838

39+
-- Add indexes for workflow instance and task instance
40+
ALTER TABLE `t_ds_workflow_instance` ADD INDEX `idx_project_code_start_time` (`project_code`, `start_time` DESC, `id` DESC) USING BTREE;
41+
ALTER TABLE `t_ds_workflow_instance` ADD INDEX `idx_workflow_definition_code_start_time` (`workflow_definition_code`, `start_time` DESC) USING BTREE;
42+
ALTER TABLE `t_ds_task_instance` ADD INDEX `idx_project_code_submit_time` (`project_code`, `submit_time` DESC) USING BTREE;
43+
ALTER TABLE `t_ds_task_instance` ADD INDEX `idx_project_code_start_time` (`project_code`, `start_time` DESC) USING BTREE;

dolphinscheduler-dao/src/main/resources/sql/upgrade/3.4.0_schema/postgresql/dolphinscheduler_ddl.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,9 @@ COMMENT ON COLUMN "t_ds_serial_command"."state" IS 'state of the serial queue: 0
4343
COMMENT ON COLUMN "t_ds_serial_command"."command" IS 'command json';
4444
COMMENT ON COLUMN "t_ds_serial_command"."create_time" IS 'create time';
4545
COMMENT ON COLUMN "t_ds_serial_command"."update_time" IS 'update time';
46+
47+
-- Add indexes for workflow instance and task instance
48+
CREATE INDEX idx_project_code_start_time ON t_ds_workflow_instance (project_code, start_time DESC, id DESC);
49+
CREATE INDEX idx_workflow_definition_code_start_time ON t_ds_workflow_instance (workflow_definition_code, start_time DESC);
50+
CREATE INDEX idx_project_code_submit_time ON t_ds_task_instance (project_code, submit_time DESC);
51+
CREATE INDEX idx_project_code_start_time ON t_ds_task_instance (project_code, start_time DESC);

0 commit comments

Comments
 (0)