Skip to content

Commit

Permalink
Fix an issue with the postgres indices as they weren't being used pro…
Browse files Browse the repository at this point in the history
…perly (#92)
  • Loading branch information
bjpirt authored Mar 3, 2024
1 parent 2b86a87 commit 9d36327
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down

0 comments on commit 9d36327

Please sign in to comment.