[Bug] [dolphinscheduler-api] The pages of project management, workflow instance and task instance are accessed slowly #7061 (#7139)

1、I found that the SQL behind this interface is very slow. The main table is large, but there is no index to use. By add the index, the all mode in the query plan can be changed into a more efficient ref mode. If this optimization still fails to meet the requirements, please contact me and I will continue to optimize。
2、modify index start_time_index in init script and upgrade scripts.
This commit is contained in:
GaoTianDuo 2021-12-04 13:13:30 +08:00 committed by GitHub
parent ba2b2a67c2
commit ed9fca6c97
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 3 deletions

View File

@ -600,7 +600,7 @@ CREATE TABLE `t_ds_process_instance` (
`next_process_instance_id` int(11) DEFAULT '0' COMMENT 'serial queue next processInstanceId',
PRIMARY KEY (`id`),
KEY `process_instance_index` (`process_definition_code`,`id`) USING BTREE,
KEY `start_time_index` (`start_time`) USING BTREE
KEY `start_time_index` (`start_time`,`end_time`) USING BTREE,
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
-- ----------------------------

View File

@ -507,7 +507,7 @@ CREATE TABLE t_ds_process_instance (
) ;
create index process_instance_index on t_ds_process_instance (process_definition_code,id);
create index start_time_index on t_ds_process_instance (start_time);
create index start_time_index on t_ds_process_instance (start_time,end_time);
--
-- Table structure for table t_ds_project

View File

@ -387,6 +387,8 @@ alter table t_ds_process_instance add var_pool longtext COMMENT 'var_pool' AFTER
alter table t_ds_process_instance add dry_run tinyint(4) DEFAULT '0' COMMENT 'dry run flag0 normal, 1 dry run' AFTER var_pool;
alter table t_ds_process_instance drop KEY `process_instance_index`;
alter table t_ds_process_instance add KEY `process_instance_index` (`process_definition_code`,`id`) USING BTREE;
alter table t_ds_process_instance drop KEY `start_time_index`;
alter table t_ds_process_instance add KEY `start_time_index` (`start_time`,`end_time`) USING BTREE;
alter table t_ds_process_instance drop process_instance_json;
alter table t_ds_process_instance drop locations;
alter table t_ds_process_instance drop connects;

View File

@ -98,11 +98,12 @@ BEGIN
--- drop index
EXECUTE 'DROP INDEX IF EXISTS "process_instance_index"';
EXECUTE 'DROP INDEX IF EXISTS "task_instance_index"';
EXECUTE 'DROP INDEX IF EXISTS "start_time_index"';
--- create index
EXECUTE 'CREATE INDEX IF NOT EXISTS priority_id_index ON ' || quote_ident(v_schema) ||'.t_ds_command USING Btree("process_instance_priority","id")';
EXECUTE 'CREATE INDEX IF NOT EXISTS process_instance_index ON ' || quote_ident(v_schema) ||'.t_ds_process_instance USING Btree("process_definition_code","id")';
EXECUTE 'CREATE INDEX IF NOT EXISTS start_time_index ON ' || quote_ident(v_schema) ||'.t_ds_process_instance USING Btree("start_time","end_time")';
---add comment
EXECUTE 'comment on column ' || quote_ident(v_schema) ||'.t_ds_user.state is ''state 0:disable 1:enable''';