: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
perf(clickhouse): undo bloom filter change (#94903)
Sven Lange6db00e942ec6
diff --git a/posthog/clickhouse/hcl/golden/local-multi/data.hcl b/posthog/clickhouse/hcl/golden/local-multi/data.hclindex 996d8d8390c5..544a7a618e5c 100644--- a/posthog/clickhouse/hcl/golden/local-multi/data.hcl+++ b/posthog/clickhouse/hcl/golden/local-multi/data.hcl@@ -5496,8 +5496,8 @@ database "posthog" {granularity = 1}index "bloom_filter_$session_id" {- expr = "`$session_id`"- type = "bloom_filter(0.01)"+ expr = "nullIf(nullIf(`$session_id`, ''), 'null')"+ type = "bloom_filter"granularity = 1}index "minmax_$group_0" {diff --git a/posthog/clickhouse/hcl/golden/local-single/all.hcl b/posthog/clickhouse/hcl/golden/local-single/all.hclindex 33e05ced5a1f..4795d1fb89ee 100644--- a/posthog/clickhouse/hcl/golden/local-single/all.hcl+++ b/posthog/clickhouse/hcl/golden/local-single/all.hcl@@ -9883,8 +9883,8 @@ SQLgranularity = 1}index "bloom_filter_$session_id" {- expr = "`$session_id`"- type = "bloom_filter(0.01)"+ expr = "nullIf(nullIf(`$session_id`, ''), 'null')"+ type = "bloom_filter"granularity = 1}index "minmax_$group_0" {diff --git a/posthog/clickhouse/hcl/roles/data/shared/tables.hcl b/posthog/clickhouse/hcl/roles/data/shared/tables.hclindex 28432650b3dd..c4787ca2f3c8 100644--- a/posthog/clickhouse/hcl/roles/data/shared/tables.hcl+++ b/posthog/clickhouse/hcl/roles/data/shared/tables.hcl@@ -211,8 +211,8 @@ database "posthog" {granularity = 1}index "bloom_filter_$session_id" {- expr = "`$session_id`"- type = "bloom_filter(0.01)"+ expr = "nullIf(nullIf(`$session_id`, ''), 'null')"+ type = "bloom_filter"granularity = 1}engine "replicated_replacing_merge_tree" {diff --git a/posthog/clickhouse/hcl/sql/local-multi/data.sql b/posthog/clickhouse/hcl/sql/local-multi/data.sqlindex 8d178dd20276..b925c1afdf0a 100644--- a/posthog/clickhouse/hcl/sql/local-multi/data.sql+++ b/posthog/clickhouse/hcl/sql/local-multi/data.sql@@ -1027,7 +1027,7 @@ CREATE TABLE posthog.sharded_events (INDEX bloom_filter_$ai_experiment_id `mat_$ai_experiment_id` TYPE bloom_filter GRANULARITY 1,INDEX minmax_$ai_experiment_id `mat_$ai_experiment_id` TYPE minmax GRANULARITY 1,INDEX minmax_$session_id_uuid `$session_id_uuid` TYPE minmax GRANULARITY 1,- INDEX bloom_filter_$session_id `$session_id` TYPE bloom_filter(0.01) GRANULARITY 1,+ INDEX bloom_filter_$session_id nullIf(nullIf(`$session_id`, ''), 'null') TYPE bloom_filter GRANULARITY 1,INDEX minmax_$group_0 `$group_0` TYPE minmax GRANULARITY 1,INDEX minmax_$group_1 `$group_1` TYPE minmax GRANULARITY 1,INDEX minmax_$group_2 `$group_2` TYPE minmax GRANULARITY 1,diff --git a/posthog/clickhouse/hcl/sql/local-single/all.sql b/posthog/clickhouse/hcl/sql/local-single/all.sqlindex 1ae5c9a64d98..65c66268443a 100644--- a/posthog/clickhouse/hcl/sql/local-single/all.sql+++ b/posthog/clickhouse/hcl/sql/local-single/all.sql@@ -1774,7 +1774,7 @@ CREATE TABLE posthog.sharded_events (INDEX bloom_filter_$ai_experiment_id `mat_$ai_experiment_id` TYPE bloom_filter GRANULARITY 1,INDEX minmax_$ai_experiment_id `mat_$ai_experiment_id` TYPE minmax GRANULARITY 1,INDEX minmax_$session_id_uuid `$session_id_uuid` TYPE minmax GRANULARITY 1,- INDEX bloom_filter_$session_id `$session_id` TYPE bloom_filter(0.01) GRANULARITY 1,+ INDEX bloom_filter_$session_id nullIf(nullIf(`$session_id`, ''), 'null') TYPE bloom_filter GRANULARITY 1,INDEX minmax_$group_0 `$group_0` TYPE minmax GRANULARITY 1,INDEX minmax_$group_1 `$group_1` TYPE minmax GRANULARITY 1,INDEX minmax_$group_2 `$group_2` TYPE minmax GRANULARITY 1,diff --git a/posthog/clickhouse/migrations/0314_session_id_bloom_filter_on_bare_column.py b/posthog/clickhouse/migrations/0314_session_id_bloom_filter_on_bare_column.pydeleted file mode 100644index 277627a0c64d..000000000000--- a/posthog/clickhouse/migrations/0314_session_id_bloom_filter_on_bare_column.py+++ /dev/null@@ -1,23 +0,0 @@-from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions--DROP_EXPRESSION_BLOOM_FILTER_INDEX = "ALTER TABLE sharded_events DROP INDEX IF EXISTS `bloom_filter_$session_id`"--ADD_BARE_COLUMN_BLOOM_FILTER_INDEX = """-ALTER TABLE sharded_events-ADD INDEX IF NOT EXISTS `bloom_filter_$session_id` `$session_id`-TYPE bloom_filter(0.01)-GRANULARITY 1-"""--operations = [- run_sql_with_exceptions(- DROP_EXPRESSION_BLOOM_FILTER_INDEX,- sharded=True,- is_alter_on_replicated_table=True,- ),- run_sql_with_exceptions(- ADD_BARE_COLUMN_BLOOM_FILTER_INDEX,- sharded=True,- is_alter_on_replicated_table=True,- ),-]diff --git a/posthog/clickhouse/migrations/max_migration.txt b/posthog/clickhouse/migrations/max_migration.txtindex 12f07a5bdbdc..e86622ea942d 100644--- a/posthog/clickhouse/migrations/max_migration.txt+++ b/posthog/clickhouse/migrations/max_migration.txt@@ -1 +1 @@-0314_session_id_bloom_filter_on_bare_column+0313_logs_pattern_bucketsdiff --git a/posthog/clickhouse/test/test_0314.py b/posthog/clickhouse/test/test_0314.pydeleted file mode 100644index ad8aea0d9038..000000000000--- a/posthog/clickhouse/test/test_0314.py+++ /dev/null@@ -1,55 +0,0 @@-import importlib--from posthog.test.base import ClickhouseDestroyTablesMixin, _create_event, flush_persons_and_events--from parameterized import parameterized--from posthog.hogql.test.test_property_skip_indexes import _run_explain_and_get_skip_indexes--from posthog.clickhouse.client import sync_execute--module = importlib.import_module("posthog.clickhouse.migrations.0314_session_id_bloom_filter_on_bare_column")--INDEX_FROM_0293 = """-ALTER TABLE sharded_events-ADD INDEX IF NOT EXISTS `bloom_filter_$session_id` nullIf(nullIf(`$session_id`, ''), 'null')-TYPE bloom_filter GRANULARITY 1-"""-SESSION_ID = "019f9a50-0000-7000-8000-000000000001"---def _apply_migration() -> None:- sync_execute(module.DROP_EXPRESSION_BLOOM_FILTER_INDEX)- sync_execute(module.ADD_BARE_COLUMN_BLOOM_FILTER_INDEX)---def _session_id_bloom_filter_indexes() -> list[tuple[str, str]]:- return sync_execute(- "SELECT name, expr FROM system.data_skipping_indices "- "WHERE database = currentDatabase() AND table = 'sharded_events' AND type = 'bloom_filter' "- "AND position(expr, '$session_id') > 0"- )---class Test0314(ClickhouseDestroyTablesMixin):- def test_replaces_the_expression_index_with_one_on_the_bare_column_and_can_be_reapplied(self):- sync_execute(INDEX_FROM_0293)- _apply_migration()- _apply_migration()- assert _session_id_bloom_filter_indexes() == [("bloom_filter_$session_id", "`$session_id`")]-- @parameterized.expand(- [- ("has", "has(%(session_ids)s, `$session_id`)"),- ("equals", "equals(`$session_id`, %(session_id)s)"),- ]- )- def test_bare_column_index_engages_under_default_hogql_settings(self, _name: str, predicate: str):- _apply_migration()- _create_event(team=self.team, distinct_id="d", event="$pageview", properties={"$session_id": SESSION_ID})- flush_persons_and_events()- values = {"team_id": self.team.pk, "session_ids": [SESSION_ID], "session_id": SESSION_ID}- skip_indexes = _run_explain_and_get_skip_indexes(- f"SELECT count() FROM events WHERE team_id = %(team_id)s AND {predicate}", values- )- assert "bloom_filter_$session_id" in skip_indexes