:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(property-values): rebuild text index with lowercase preprocessor (#57843)
Andy Zhao9c6b0ee9961e
diff --git a/posthog/clickhouse/migrations/0250_property_values_lowercase_text_index.py b/posthog/clickhouse/migrations/0250_property_values_lowercase_text_index.pynew file mode 100644index 000000000000..b4589524f9e3--- /dev/null+++ b/posthog/clickhouse/migrations/0250_property_values_lowercase_text_index.py@@ -0,0 +1,33 @@+from posthog import settings+from posthog.clickhouse.client.connection import NodeRole+from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions++if settings.CLOUD_DEPLOYMENT in ("US", "EU"):+ _ROLES = [NodeRole.AUX]+elif settings.CLOUD_DEPLOYMENT == "DEV":+ _ROLES = [NodeRole.DATA]+else:+ _ROLES = []++operations = (+ [+ run_sql_with_exceptions(+ "ALTER TABLE property_values DROP INDEX IF EXISTS idx_property_value",+ node_roles=_ROLES,+ is_alter_on_replicated_table=True,+ ),+ run_sql_with_exceptions(+ "ALTER TABLE property_values ADD INDEX IF NOT EXISTS idx_property_value property_value "+ "TYPE text(tokenizer = ngrams(3), preprocessor = lower(property_value)) GRANULARITY 1",+ node_roles=_ROLES,+ is_alter_on_replicated_table=True,+ ),+ run_sql_with_exceptions(+ "ALTER TABLE property_values MATERIALIZE INDEX idx_property_value",+ node_roles=_ROLES,+ is_alter_on_replicated_table=True,+ ),+ ]+ if _ROLES+ else []+)diff --git a/posthog/clickhouse/migrations/max_migration.txt b/posthog/clickhouse/migrations/max_migration.txtindex dc3a5646d3ce..46a57b284006 100644--- a/posthog/clickhouse/migrations/max_migration.txt+++ b/posthog/clickhouse/migrations/max_migration.txt@@ -1 +1 @@-0249_property_values_kafka_named_collection+0250_property_values_lowercase_text_indexdiff --git a/posthog/clickhouse/property_values.py b/posthog/clickhouse/property_values.pyindex ae7ad50d6305..7dda6c9156b2 100644--- a/posthog/clickhouse/property_values.py+++ b/posthog/clickhouse/property_values.py@@ -49,7 +49,7 @@ SETTINGStable_name=TABLE_NAME,engine=AggregatingMergeTree(TABLE_NAME, replication_scheme=ReplicationScheme.REPLICATED),extra_fields=""",- INDEX idx_property_value property_value TYPE text(tokenizer = ngrams(3)) GRANULARITY 1""",+ INDEX idx_property_value property_value TYPE text(tokenizer = ngrams(3), preprocessor = lower(property_value)) GRANULARITY 1""",)diff --git a/posthog/clickhouse/test/__snapshots__/test_schema.ambr b/posthog/clickhouse/test/__snapshots__/test_schema.ambrindex 09f0f74de83c..d6bef1423f66 100644--- a/posthog/clickhouse/test/__snapshots__/test_schema.ambr+++ b/posthog/clickhouse/test/__snapshots__/test_schema.ambr@@ -3381,7 +3381,7 @@`property_count` SimpleAggregateFunction(sum, UInt64),`last_seen` SimpleAggregateFunction(max, DateTime) DEFAULT now(),- INDEX idx_property_value property_value TYPE text(tokenizer = ngrams(3)) GRANULARITY 1+ INDEX idx_property_value property_value TYPE text(tokenizer = ngrams(3), preprocessor = lower(property_value)) GRANULARITY 1) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/77f1df52-4b43-11e9-910f-b8ca3a9b9f3e_noshard/posthog.property_values', '{replica}-{shard}')ORDER BY (team_id, property_type, property_key, property_value)@@ -7561,7 +7561,7 @@`property_count` SimpleAggregateFunction(sum, UInt64),`last_seen` SimpleAggregateFunction(max, DateTime) DEFAULT now(),- INDEX idx_property_value property_value TYPE text(tokenizer = ngrams(3)) GRANULARITY 1+ INDEX idx_property_value property_value TYPE text(tokenizer = ngrams(3), preprocessor = lower(property_value)) GRANULARITY 1) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/77f1df52-4b43-11e9-910f-b8ca3a9b9f3e_noshard/posthog.property_values', '{replica}-{shard}')ORDER BY (team_id, property_type, property_key, property_value)