From bc73c2905123c5492204c50b7dc2cc874a5a96dd Mon Sep 17 00:00:00 2001 From: sonika-shah <58761340+sonika-shah@users.noreply.github.com> Date: Mon, 27 Apr 2026 01:37:59 +0530 Subject: [PATCH 1/2] Fixes #27158: restore tag_usage prefix-LIKE index on Postgres The 1.11.0 perf migration (#23054) added four `WHERE state = 1` partial indexes on tag_usage; #24063 dropped the matching `state = 1` predicate from getTagsInternalByPrefix (Suggested-state rows are valid for both classification and glossary derivation), leaving every partial index inapplicable. Postgres fell back to a parallel seq scan; MySQL was unaffected because its 1.11.0 indexes were never partial. Adds a non-partial single-col btree on targetfqnhash_lower (mirrors MySQL's idx_targetfqnhash_lower) and rebuilds the four partials as non-partial -- same shape, same INCLUDE columns, predicate coupling removed so future query changes can't silently invalidate them. Verified end-to-end against a local Postgres with 50k rows: seq scan reproduced before the fix (matches reporter's EXPLAIN), bitmap index scan after, both for inline and prepared-statement paths. --- .../mysql/postDataMigrationSQLScript.sql | 1 + .../native/1.12.8/mysql/schemaChanges.sql | 4 +++ .../postgres/postDataMigrationSQLScript.sql | 1 + .../native/1.12.8/postgres/schemaChanges.sql | 27 +++++++++++++++++++ 4 files changed, 33 insertions(+) create mode 100644 bootstrap/sql/migrations/native/1.12.8/mysql/postDataMigrationSQLScript.sql create mode 100644 bootstrap/sql/migrations/native/1.12.8/mysql/schemaChanges.sql create mode 100644 bootstrap/sql/migrations/native/1.12.8/postgres/postDataMigrationSQLScript.sql create mode 100644 bootstrap/sql/migrations/native/1.12.8/postgres/schemaChanges.sql diff --git a/bootstrap/sql/migrations/native/1.12.8/mysql/postDataMigrationSQLScript.sql b/bootstrap/sql/migrations/native/1.12.8/mysql/postDataMigrationSQLScript.sql new file mode 100644 index 000000000000..2a52d93a2945 --- /dev/null +++ b/bootstrap/sql/migrations/native/1.12.8/mysql/postDataMigrationSQLScript.sql @@ -0,0 +1 @@ +-- Placeholder for 1.12.8 MySQL post-data migration script diff --git a/bootstrap/sql/migrations/native/1.12.8/mysql/schemaChanges.sql b/bootstrap/sql/migrations/native/1.12.8/mysql/schemaChanges.sql new file mode 100644 index 000000000000..3a2f5a22421f --- /dev/null +++ b/bootstrap/sql/migrations/native/1.12.8/mysql/schemaChanges.sql @@ -0,0 +1,4 @@ +-- Placeholder for 1.12.8 MySQL schema changes +-- The Postgres-side fix for #27158 has no MySQL counterpart: MySQL's +-- 1.11.0 indexes were already non-partial (no partial-index syntax in +-- MySQL), so the regression that hit Postgres did not affect MySQL. diff --git a/bootstrap/sql/migrations/native/1.12.8/postgres/postDataMigrationSQLScript.sql b/bootstrap/sql/migrations/native/1.12.8/postgres/postDataMigrationSQLScript.sql new file mode 100644 index 000000000000..5909bcf4532b --- /dev/null +++ b/bootstrap/sql/migrations/native/1.12.8/postgres/postDataMigrationSQLScript.sql @@ -0,0 +1 @@ +-- Placeholder for 1.12.8 PostgreSQL post-data migration script diff --git a/bootstrap/sql/migrations/native/1.12.8/postgres/schemaChanges.sql b/bootstrap/sql/migrations/native/1.12.8/postgres/schemaChanges.sql new file mode 100644 index 000000000000..3a4a2079dab3 --- /dev/null +++ b/bootstrap/sql/migrations/native/1.12.8/postgres/schemaChanges.sql @@ -0,0 +1,27 @@ +-- Issue #27158: tag_usage seq-scan on Postgres. #24063 dropped the +-- `state = 1` predicate that 1.11.0's partial indexes required. +-- Fix: add a single-col index, and drop the `WHERE state = 1` filter +-- from the existing partials so query changes can't invalidate them. + +CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_tag_usage_targetfqnhash_lower_pattern +ON tag_usage (targetfqnhash_lower text_pattern_ops); + +DROP INDEX CONCURRENTLY IF EXISTS idx_tag_usage_target_prefix_covering; +CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_tag_usage_target_prefix_covering +ON tag_usage (source, targetfqnhash_lower text_pattern_ops) +INCLUDE (tagFQN, labelType, state); + +DROP INDEX CONCURRENTLY IF EXISTS idx_tag_usage_tagfqn_prefix_covering; +CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_tag_usage_tagfqn_prefix_covering +ON tag_usage (source, tagfqn_lower text_pattern_ops) +INCLUDE (targetFQNHash, labelType, state); + +DROP INDEX CONCURRENTLY IF EXISTS idx_tag_usage_join_source; +CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_tag_usage_join_source +ON tag_usage (tagFQNHash, source) +INCLUDE (targetFQNHash, tagFQN, labelType, state); + +CREATE EXTENSION IF NOT EXISTS pg_trgm; +DROP INDEX CONCURRENTLY IF EXISTS gin_tag_usage_targetfqn_trgm; +CREATE INDEX CONCURRENTLY IF NOT EXISTS gin_tag_usage_targetfqn_trgm +ON tag_usage USING GIN (targetFQNHash gin_trgm_ops); From 5a2bfb335d5ab85de1832a4b894749e1efc51a32 Mon Sep 17 00:00:00 2001 From: sonika-shah <58761340+sonika-shah@users.noreply.github.com> Date: Wed, 29 Apr 2026 19:10:09 +0530 Subject: [PATCH 2/2] Move #27158 tag_usage fix to 1.12.7 + add tagfqn_lower index Ship the fix in the 1.12.7 release line so customers on 1.12.x get it without waiting for 2.0.x. Also closes the second structural gap with MySQL: a non-partial single-col btree on tagfqn_lower mirroring MySQL's idx_tagfqn_lower (1.11.0). 1.12.8 directory removed; 1.12.7's existing schemaChanges.sql now carries the tag_usage indexes alongside the entity_extension migration. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../native/1.12.7/postgres/schemaChanges.sql | 31 +++++++++++++++++++ .../mysql/postDataMigrationSQLScript.sql | 1 - .../native/1.12.8/mysql/schemaChanges.sql | 4 --- .../postgres/postDataMigrationSQLScript.sql | 1 - .../native/1.12.8/postgres/schemaChanges.sql | 27 ---------------- 5 files changed, 31 insertions(+), 33 deletions(-) delete mode 100644 bootstrap/sql/migrations/native/1.12.8/mysql/postDataMigrationSQLScript.sql delete mode 100644 bootstrap/sql/migrations/native/1.12.8/mysql/schemaChanges.sql delete mode 100644 bootstrap/sql/migrations/native/1.12.8/postgres/postDataMigrationSQLScript.sql delete mode 100644 bootstrap/sql/migrations/native/1.12.8/postgres/schemaChanges.sql diff --git a/bootstrap/sql/migrations/native/1.12.7/postgres/schemaChanges.sql b/bootstrap/sql/migrations/native/1.12.7/postgres/schemaChanges.sql index 99bc7b7ff037..e920bd3c46c8 100644 --- a/bootstrap/sql/migrations/native/1.12.7/postgres/schemaChanges.sql +++ b/bootstrap/sql/migrations/native/1.12.7/postgres/schemaChanges.sql @@ -9,3 +9,34 @@ CREATE INDEX IF NOT EXISTS idx_entity_extension_version_order CREATE INDEX IF NOT EXISTS idx_entity_extension_changed_field_keys ON entity_extension USING GIN (changedFieldKeys) WHERE changedFieldKeys IS NOT NULL; + +-- Issue #27158: tag_usage seq-scan on Postgres. #24063 dropped the +-- `state = 1` predicate that 1.11.0's partial indexes required. +-- Fix: add single-col indexes on the `_lower` columns, and drop the +-- `WHERE state = 1` filter from the partials so changes can't invalidate them. + +CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_tag_usage_targetfqnhash_lower_pattern +ON tag_usage (targetfqnhash_lower text_pattern_ops); + +CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_tag_usage_tagfqn_lower_pattern +ON tag_usage (tagfqn_lower text_pattern_ops); + +DROP INDEX CONCURRENTLY IF EXISTS idx_tag_usage_target_prefix_covering; +CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_tag_usage_target_prefix_covering +ON tag_usage (source, targetfqnhash_lower text_pattern_ops) +INCLUDE (tagFQN, labelType, state); + +DROP INDEX CONCURRENTLY IF EXISTS idx_tag_usage_tagfqn_prefix_covering; +CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_tag_usage_tagfqn_prefix_covering +ON tag_usage (source, tagfqn_lower text_pattern_ops) +INCLUDE (targetFQNHash, labelType, state); + +DROP INDEX CONCURRENTLY IF EXISTS idx_tag_usage_join_source; +CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_tag_usage_join_source +ON tag_usage (tagFQNHash, source) +INCLUDE (targetFQNHash, tagFQN, labelType, state); + +CREATE EXTENSION IF NOT EXISTS pg_trgm; +DROP INDEX CONCURRENTLY IF EXISTS gin_tag_usage_targetfqn_trgm; +CREATE INDEX CONCURRENTLY IF NOT EXISTS gin_tag_usage_targetfqn_trgm +ON tag_usage USING GIN (targetFQNHash gin_trgm_ops); diff --git a/bootstrap/sql/migrations/native/1.12.8/mysql/postDataMigrationSQLScript.sql b/bootstrap/sql/migrations/native/1.12.8/mysql/postDataMigrationSQLScript.sql deleted file mode 100644 index 2a52d93a2945..000000000000 --- a/bootstrap/sql/migrations/native/1.12.8/mysql/postDataMigrationSQLScript.sql +++ /dev/null @@ -1 +0,0 @@ --- Placeholder for 1.12.8 MySQL post-data migration script diff --git a/bootstrap/sql/migrations/native/1.12.8/mysql/schemaChanges.sql b/bootstrap/sql/migrations/native/1.12.8/mysql/schemaChanges.sql deleted file mode 100644 index 3a2f5a22421f..000000000000 --- a/bootstrap/sql/migrations/native/1.12.8/mysql/schemaChanges.sql +++ /dev/null @@ -1,4 +0,0 @@ --- Placeholder for 1.12.8 MySQL schema changes --- The Postgres-side fix for #27158 has no MySQL counterpart: MySQL's --- 1.11.0 indexes were already non-partial (no partial-index syntax in --- MySQL), so the regression that hit Postgres did not affect MySQL. diff --git a/bootstrap/sql/migrations/native/1.12.8/postgres/postDataMigrationSQLScript.sql b/bootstrap/sql/migrations/native/1.12.8/postgres/postDataMigrationSQLScript.sql deleted file mode 100644 index 5909bcf4532b..000000000000 --- a/bootstrap/sql/migrations/native/1.12.8/postgres/postDataMigrationSQLScript.sql +++ /dev/null @@ -1 +0,0 @@ --- Placeholder for 1.12.8 PostgreSQL post-data migration script diff --git a/bootstrap/sql/migrations/native/1.12.8/postgres/schemaChanges.sql b/bootstrap/sql/migrations/native/1.12.8/postgres/schemaChanges.sql deleted file mode 100644 index 3a4a2079dab3..000000000000 --- a/bootstrap/sql/migrations/native/1.12.8/postgres/schemaChanges.sql +++ /dev/null @@ -1,27 +0,0 @@ --- Issue #27158: tag_usage seq-scan on Postgres. #24063 dropped the --- `state = 1` predicate that 1.11.0's partial indexes required. --- Fix: add a single-col index, and drop the `WHERE state = 1` filter --- from the existing partials so query changes can't invalidate them. - -CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_tag_usage_targetfqnhash_lower_pattern -ON tag_usage (targetfqnhash_lower text_pattern_ops); - -DROP INDEX CONCURRENTLY IF EXISTS idx_tag_usage_target_prefix_covering; -CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_tag_usage_target_prefix_covering -ON tag_usage (source, targetfqnhash_lower text_pattern_ops) -INCLUDE (tagFQN, labelType, state); - -DROP INDEX CONCURRENTLY IF EXISTS idx_tag_usage_tagfqn_prefix_covering; -CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_tag_usage_tagfqn_prefix_covering -ON tag_usage (source, tagfqn_lower text_pattern_ops) -INCLUDE (targetFQNHash, labelType, state); - -DROP INDEX CONCURRENTLY IF EXISTS idx_tag_usage_join_source; -CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_tag_usage_join_source -ON tag_usage (tagFQNHash, source) -INCLUDE (targetFQNHash, tagFQN, labelType, state); - -CREATE EXTENSION IF NOT EXISTS pg_trgm; -DROP INDEX CONCURRENTLY IF EXISTS gin_tag_usage_targetfqn_trgm; -CREATE INDEX CONCURRENTLY IF NOT EXISTS gin_tag_usage_targetfqn_trgm -ON tag_usage USING GIN (targetFQNHash gin_trgm_ops);