Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an issue with the postgres indices as they weren't being used properly #92

Merged
merged 1 commit into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading