diff --git a/CHANGELOG.md b/CHANGELOG.md index ee24d3e50..8d0fbe108 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,12 +9,16 @@ - Add MariaDB support - Add Kotlin example using nFlow with Spring Boot, and integrated nFlow Explorer - Expose wakeup via REST-API +- Update database indices to match workflow instance polling code **Details** - `nflow-engine` - Separate workflow definition scanning from `WorkflowDefinitionService` by introducing `WorkflowDefinitionSpringBeanScanner` and `WorkflowDefinitionClassNameScanner`. This allows breaking the circular dependency when a workflow definition uses `WorkflowInstanceService` (which depends on `WorkflowDefinitionService`, which depended on all workflow definitions). This enabled using constructor injection in all nFlow classes. - Add `disableMariaDbDriver` to default MySQL JDBC URL so that in case there are both MySQL and MariaDB JDBC drivers in the classpath then MariaDB will not steal the MySQL URL. - Add support for `nflow.db.mariadb` profile. + - Update database indices to match current workflow instance polling code. + - Create indices for foreign keys in MS SQL database. + - Fix create database scripts to work with empty database. - Dependency updates: - reactor.netty 0.8.11.RELEASE - jackson 2.9.10 diff --git a/nflow-engine/src/main/resources/scripts/db/db2.create.ddl.sql b/nflow-engine/src/main/resources/scripts/db/db2.create.ddl.sql index 0fed1dc0a..adf2b457b 100644 --- a/nflow-engine/src/main/resources/scripts/db/db2.create.ddl.sql +++ b/nflow-engine/src/main/resources/scripts/db/db2.create.ddl.sql @@ -32,6 +32,8 @@ create or replace trigger nflow_workflow_update_modified drop index nflow_workflow_activation; create index nflow_workflow_activation on nflow_workflow(next_activation, modified); +create index nflow_workflow_polling on nflow_workflow(next_activation, status, executor_id, executor_group); + create table nflow_workflow_action ( id int primary key generated always as identity, workflow_id int not null, diff --git a/nflow-engine/src/main/resources/scripts/db/h2.create.ddl.sql b/nflow-engine/src/main/resources/scripts/db/h2.create.ddl.sql index 38a3202cd..53207845d 100644 --- a/nflow-engine/src/main/resources/scripts/db/h2.create.ddl.sql +++ b/nflow-engine/src/main/resources/scripts/db/h2.create.ddl.sql @@ -26,6 +26,8 @@ create unique index if not exists nflow_workflow_uniq on nflow_workflow (type, e create index if not exists nflow_workflow_next_activation on nflow_workflow(next_activation, modified); +create index if not exists nflow_workflow_polling on nflow_workflow(next_activation, status, executor_id, executor_group); + create table if not exists nflow_workflow_action ( id int not null auto_increment primary key, workflow_id int not null, diff --git a/nflow-engine/src/main/resources/scripts/db/mysql.create.ddl.sql b/nflow-engine/src/main/resources/scripts/db/mysql.create.ddl.sql index d070930dd..1ebb336bc 100644 --- a/nflow-engine/src/main/resources/scripts/db/mysql.create.ddl.sql +++ b/nflow-engine/src/main/resources/scripts/db/mysql.create.ddl.sql @@ -25,6 +25,8 @@ create table if not exists nflow_workflow ( drop index nflow_workflow_activation; create index nflow_workflow_activation on nflow_workflow(next_activation, modified); +create index nflow_workflow_polling on nflow_workflow(next_activation, status, executor_id, executor_group); + create table if not exists nflow_workflow_action ( id int not null auto_increment primary key, workflow_id int not null, diff --git a/nflow-engine/src/main/resources/scripts/db/mysql.legacy.create.ddl.sql b/nflow-engine/src/main/resources/scripts/db/mysql.legacy.create.ddl.sql index 9427681a7..15bc988c0 100644 --- a/nflow-engine/src/main/resources/scripts/db/mysql.legacy.create.ddl.sql +++ b/nflow-engine/src/main/resources/scripts/db/mysql.legacy.create.ddl.sql @@ -25,6 +25,8 @@ create table if not exists nflow_workflow ( drop index nflow_workflow_activation; create index nflow_workflow_activation on nflow_workflow(next_activation, modified); +create index nflow_workflow_polling on nflow_workflow(next_activation, status, executor_id, executor_group); + drop trigger if exists nflow_workflow_insert; create trigger nflow_workflow_insert before insert on `nflow_workflow` diff --git a/nflow-engine/src/main/resources/scripts/db/oracle.create.ddl.sql b/nflow-engine/src/main/resources/scripts/db/oracle.create.ddl.sql index 9215412d0..d0d4833f4 100644 --- a/nflow-engine/src/main/resources/scripts/db/oracle.create.ddl.sql +++ b/nflow-engine/src/main/resources/scripts/db/oracle.create.ddl.sql @@ -26,6 +26,9 @@ create table nflow_workflow ( create index nflow_workflow_activation on nflow_workflow (next_activation) / +create index nflow_workflow_polling on nflow_workflow (next_activation, status, executor_id, executor_group) +/ + create sequence nflow_workflow_id_seq / diff --git a/nflow-engine/src/main/resources/scripts/db/postgresql.create.ddl.sql b/nflow-engine/src/main/resources/scripts/db/postgresql.create.ddl.sql index 563da41e3..797315ba5 100644 --- a/nflow-engine/src/main/resources/scripts/db/postgresql.create.ddl.sql +++ b/nflow-engine/src/main/resources/scripts/db/postgresql.create.ddl.sql @@ -39,6 +39,9 @@ create trigger update_nflow_modified before update on nflow_workflow for each ro drop index if exists nflow_workflow_activation; create index nflow_workflow_activation on nflow_workflow(next_activation, modified); +drop index if exists nflow_workflow_polling; +create index nflow_workflow_polling on nflow_workflow(next_activation, status, executor_id, executor_group); + create type action_type as enum ('stateExecution', 'stateExecutionFailed', 'recovery', 'externalChange'); create table if not exists nflow_workflow_action ( id serial primary key, diff --git a/nflow-engine/src/main/resources/scripts/db/sqlserver.create.ddl.sql b/nflow-engine/src/main/resources/scripts/db/sqlserver.create.ddl.sql index 19b8ac667..7f1e49e80 100644 --- a/nflow-engine/src/main/resources/scripts/db/sqlserver.create.ddl.sql +++ b/nflow-engine/src/main/resources/scripts/db/sqlserver.create.ddl.sql @@ -32,6 +32,8 @@ end; drop index nflow_workflow_activation; create index nflow_workflow_activation on nflow_workflow(next_activation, modified); +create index nflow_workflow_polling on nflow_workflow(next_activation, status, executor_id, executor_group); + create table nflow_workflow_action ( id int not null identity(1,1) primary key, workflow_id int not null, @@ -46,12 +48,18 @@ create table nflow_workflow_action ( constraint nflow_workflow_action_uniq unique (workflow_id, id) ); +create index nflow_workflow_action_workflow on nflow_workflow_action(workflow_id); + alter table nflow_workflow add constraint fk_workflow_parent foreign key (parent_workflow_id, parent_action_id) references nflow_workflow_action (workflow_id, id) on update no action; +create index nflow_workflow_parent on nflow_workflow(parent_workflow_id, parent_action_id); + alter table nflow_workflow add constraint fk_workflow_root foreign key (root_workflow_id) references nflow_workflow (id) on update no action; +create index nflow_workflow_root on nflow_workflow(root_workflow_id); + create table nflow_workflow_state ( workflow_id int not null, action_id int not null, @@ -61,6 +69,8 @@ create table nflow_workflow_state ( foreign key (workflow_id) references nflow_workflow(id) on delete cascade ); +create index nflow_workflow_state_workflow on nflow_workflow_state(workflow_id); + create table nflow_executor ( id int not null identity(1,1) primary key, host varchar(253) not null, @@ -120,6 +130,14 @@ create table nflow_archive_workflow ( constraint nflow_archive_workflow_uniq unique (type, external_id, executor_group) ); +create index nflow_archive_workflow_activation on nflow_archive_workflow(next_activation, modified); + +create index nflow_archive_workflow_polling on nflow_archive_workflow(next_activation, status, executor_id, executor_group); + +create index nflow_archive_workflow_parent on nflow_archive_workflow(parent_workflow_id, parent_action_id); + +create index nflow_archive_workflow_root on nflow_archive_workflow(root_workflow_id); + create table nflow_archive_workflow_action ( id int not null primary key, workflow_id int not null, @@ -134,6 +152,8 @@ create table nflow_archive_workflow_action ( constraint nflow_archive_workflow_action_uniq unique (workflow_id, id) ); +create index nflow_archive_workflow_action_workflow on nflow_archive_workflow_action(workflow_id); + create table nflow_archive_workflow_state ( workflow_id int not null, action_id int not null, @@ -142,3 +162,5 @@ create table nflow_archive_workflow_state ( primary key (workflow_id, action_id, state_key), foreign key (workflow_id) references nflow_archive_workflow(id) on delete cascade ); + +create index nflow_archive_workflow_state_workflow on nflow_archive_workflow_state(workflow_id); diff --git a/nflow-engine/src/main/resources/scripts/db/update-5.7.0-x/db2.update.ddl.sql b/nflow-engine/src/main/resources/scripts/db/update-5.7.0-x/db2.update.ddl.sql new file mode 100644 index 000000000..1842fdd52 --- /dev/null +++ b/nflow-engine/src/main/resources/scripts/db/update-5.7.0-x/db2.update.ddl.sql @@ -0,0 +1 @@ +create index nflow_workflow_polling on nflow_workflow(next_activation, status, executor_id, executor_group); diff --git a/nflow-engine/src/main/resources/scripts/db/update-5.7.0-x/h2.update.ddl.sql b/nflow-engine/src/main/resources/scripts/db/update-5.7.0-x/h2.update.ddl.sql new file mode 100644 index 000000000..0b06eaad0 --- /dev/null +++ b/nflow-engine/src/main/resources/scripts/db/update-5.7.0-x/h2.update.ddl.sql @@ -0,0 +1 @@ +create index if not exists nflow_workflow_polling on nflow_workflow(next_activation, status, executor_id, executor_group); diff --git a/nflow-engine/src/main/resources/scripts/db/update-5.7.0-x/mysql.legacy.update.ddl.sql b/nflow-engine/src/main/resources/scripts/db/update-5.7.0-x/mysql.legacy.update.ddl.sql new file mode 100644 index 000000000..1842fdd52 --- /dev/null +++ b/nflow-engine/src/main/resources/scripts/db/update-5.7.0-x/mysql.legacy.update.ddl.sql @@ -0,0 +1 @@ +create index nflow_workflow_polling on nflow_workflow(next_activation, status, executor_id, executor_group); diff --git a/nflow-engine/src/main/resources/scripts/db/update-5.7.0-x/mysql.update.ddl.sql b/nflow-engine/src/main/resources/scripts/db/update-5.7.0-x/mysql.update.ddl.sql new file mode 100644 index 000000000..1842fdd52 --- /dev/null +++ b/nflow-engine/src/main/resources/scripts/db/update-5.7.0-x/mysql.update.ddl.sql @@ -0,0 +1 @@ +create index nflow_workflow_polling on nflow_workflow(next_activation, status, executor_id, executor_group); diff --git a/nflow-engine/src/main/resources/scripts/db/update-5.7.0-x/oracle.update.ddl.sql b/nflow-engine/src/main/resources/scripts/db/update-5.7.0-x/oracle.update.ddl.sql new file mode 100644 index 000000000..4014af26f --- /dev/null +++ b/nflow-engine/src/main/resources/scripts/db/update-5.7.0-x/oracle.update.ddl.sql @@ -0,0 +1,2 @@ +create index nflow_workflow_polling on nflow_workflow (next_activation, status, executor_id, executor_group) +/ diff --git a/nflow-engine/src/main/resources/scripts/db/update-5.7.0-x/postgresql.update.ddl.sql b/nflow-engine/src/main/resources/scripts/db/update-5.7.0-x/postgresql.update.ddl.sql new file mode 100644 index 000000000..dc017b1a8 --- /dev/null +++ b/nflow-engine/src/main/resources/scripts/db/update-5.7.0-x/postgresql.update.ddl.sql @@ -0,0 +1,2 @@ +drop index if exists nflow_workflow_polling; +create index nflow_workflow_polling on nflow_workflow(next_activation, status, executor_id, executor_group); diff --git a/nflow-engine/src/main/resources/scripts/db/update-5.7.0-x/sqlserver.update.ddl.sql b/nflow-engine/src/main/resources/scripts/db/update-5.7.0-x/sqlserver.update.ddl.sql new file mode 100644 index 000000000..118283033 --- /dev/null +++ b/nflow-engine/src/main/resources/scripts/db/update-5.7.0-x/sqlserver.update.ddl.sql @@ -0,0 +1,21 @@ +create index nflow_workflow_polling on nflow_workflow(next_activation, status, executor_id, executor_group); + +create index nflow_workflow_parent on nflow_workflow(parent_workflow_id, parent_action_id); + +create index nflow_workflow_root on nflow_workflow(root_workflow_id); + +create index nflow_workflow_action_workflow on nflow_workflow_action(workflow_id); + +create index nflow_workflow_state_workflow on nflow_workflow_state(workflow_id); + +create index nflow_archive_workflow_activation on nflow_archive_workflow(next_activation, modified); + +create index nflow_archive_workflow_polling on nflow_archive_workflow(next_activation, status, executor_id, executor_group); + +create index nflow_archive_workflow_parent on nflow_archive_workflow(parent_workflow_id, parent_action_id); + +create index nflow_archive_workflow_root on nflow_archive_workflow(root_workflow_id); + +create index nflow_archive_workflow_action_workflow on nflow_archive_workflow_action(workflow_id); + +create index nflow_archive_workflow_state_workflow on nflow_archive_workflow_state(workflow_id);