diff --git a/postgres-persistence/src/main/java/com/netflix/conductor/postgres/config/PostgresConfiguration.java b/postgres-persistence/src/main/java/com/netflix/conductor/postgres/config/PostgresConfiguration.java index 62ed27eff..0309df43f 100644 --- a/postgres-persistence/src/main/java/com/netflix/conductor/postgres/config/PostgresConfiguration.java +++ b/postgres-persistence/src/main/java/com/netflix/conductor/postgres/config/PostgresConfiguration.java @@ -13,6 +13,7 @@ package com.netflix.conductor.postgres.config; import java.sql.SQLException; +import java.util.Map; import java.util.Optional; import javax.sql.DataSource; @@ -59,6 +60,7 @@ public PostgresConfiguration(DataSource dataSource, PostgresProperties propertie public Flyway flywayForPrimaryDb() { return Flyway.configure() .locations("classpath:db/migration_postgres") + .configuration(Map.of("flyway.postgresql.transactional.lock", "false")) .schemas(properties.getSchema()) .dataSource(dataSource) .outOfOrder(true) diff --git a/postgres-persistence/src/main/java/com/netflix/conductor/postgres/util/PostgresIndexQueryBuilder.java b/postgres-persistence/src/main/java/com/netflix/conductor/postgres/util/PostgresIndexQueryBuilder.java index 141df11b2..d73ef943f 100644 --- a/postgres-persistence/src/main/java/com/netflix/conductor/postgres/util/PostgresIndexQueryBuilder.java +++ b/postgres-persistence/src/main/java/com/netflix/conductor/postgres/util/PostgresIndexQueryBuilder.java @@ -44,7 +44,7 @@ public class PostgresIndexQueryBuilder { "task_def_name", "update_time", "json_data", - "to_tsvector(json_data::text)" + "jsonb_to_tsvector('english', json_data, '[\"all\"]')" }; private static final String[] VALID_SORT_ORDER = {"ASC", "DESC"}; @@ -186,7 +186,7 @@ private void parseFreeText(String freeText) { conditions.add(cond); } else { Condition cond = new Condition(); - cond.setAttribute("to_tsvector(json_data::text)"); + cond.setAttribute("jsonb_to_tsvector('english', json_data, '[\"all\"]')"); cond.setOperator("@@"); String[] values = {freeText}; cond.setValues(Arrays.asList(values)); diff --git a/postgres-persistence/src/main/resources/db/migration_postgres/V9__indexing_index_fix.sql b/postgres-persistence/src/main/resources/db/migration_postgres/V9__indexing_index_fix.sql new file mode 100644 index 000000000..0f8da6c29 --- /dev/null +++ b/postgres-persistence/src/main/resources/db/migration_postgres/V9__indexing_index_fix.sql @@ -0,0 +1,12 @@ +-- Drop the unused text index on the json_data column +DROP INDEX CONCURRENTLY IF EXISTS workflow_index_json_data_text_idx; +-- Create a new index to enable querying the json by attribute and value +CREATE INDEX CONCURRENTLY IF NOT EXISTS workflow_index_json_data_gin_idx ON workflow_index USING GIN (json_data jsonb_path_ops); + +-- Drop the incorrectly created indices on the workflow_index that should be on the task_index table +DROP INDEX CONCURRENTLY IF EXISTS task_index_json_data_json_idx; +DROP INDEX CONCURRENTLY IF EXISTS task_index_json_data_text_idx; +-- Create the full text index on the json_data column of the task_index table +CREATE INDEX CONCURRENTLY IF NOT EXISTS task_index_json_data_json_idx ON task_index USING GIN (jsonb_to_tsvector('english', json_data, '["all"]')); +-- Create a new index to enable querying the json by attribute and value +CREATE INDEX CONCURRENTLY IF NOT EXISTS task_index_json_data_gin_idx ON task_index USING GIN (json_data jsonb_path_ops); diff --git a/postgres-persistence/src/test/java/com/netflix/conductor/postgres/util/PostgresIndexQueryBuilderTest.java b/postgres-persistence/src/test/java/com/netflix/conductor/postgres/util/PostgresIndexQueryBuilderTest.java index 2036e2f4a..3ce48add9 100644 --- a/postgres-persistence/src/test/java/com/netflix/conductor/postgres/util/PostgresIndexQueryBuilderTest.java +++ b/postgres-persistence/src/test/java/com/netflix/conductor/postgres/util/PostgresIndexQueryBuilderTest.java @@ -268,7 +268,7 @@ void shouldAllowFullTextSearch() throws SQLException { new PostgresIndexQueryBuilder( "table_name", "", freeText, 0, 15, Arrays.asList(query)); String expectedQuery = - "SELECT json_data::TEXT FROM table_name WHERE to_tsvector(json_data::text) @@ to_tsquery(?) LIMIT ? OFFSET ?"; + "SELECT json_data::TEXT FROM table_name WHERE jsonb_to_tsvector('english', json_data, '[\"all\"]') @@ to_tsquery(?) LIMIT ? OFFSET ?"; assertEquals(expectedQuery, builder.getQuery()); }