From edb3a4649c7f4a61535d1fff23f0eb31bbd95786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Oberm=C3=BCller?= Date: Tue, 2 Apr 2024 18:09:36 +0200 Subject: [PATCH] fix(hogql): reverse join order for actors (#21216) --- posthog/hogql/test/test_resolver.py | 12 +- posthog/hogql_queries/actors_query_runner.py | 6 +- .../test/__snapshots__/test_funnel.ambr | 64 +- .../test_funnel_correlation.ambr | 568 +++++++++--------- .../test_funnel_correlations_persons.ambr | 70 +-- .../__snapshots__/test_funnel_persons.ambr | 42 +- .../test_funnel_strict_persons.ambr | 42 +- .../test_funnel_trends_persons.ambr | 42 +- .../test_funnel_unordered_persons.ambr | 14 +- .../test_retention_query_runner.ambr | 32 +- 10 files changed, 447 insertions(+), 445 deletions(-) diff --git a/posthog/hogql/test/test_resolver.py b/posthog/hogql/test/test_resolver.py index 88b7b2c50e0b5..d0fc046441f18 100644 --- a/posthog/hogql/test/test_resolver.py +++ b/posthog/hogql/test/test_resolver.py @@ -359,10 +359,12 @@ def test_visit_hogqlx_tag_source(self): node = cast(ast.SelectQuery, resolve_types(self._select(query), self.context, dialect="hogql")) hogql = print_prepared_ast(node, HogQLContext(team_id=self.team.pk, enable_select_queries=True), "hogql") expected = ( - f"SELECT id, email FROM " - f"(SELECT id, properties.email AS email FROM persons INNER JOIN " - f"(SELECT DISTINCT person_id FROM events) " - f"AS source ON equals(persons.id, source.person_id) ORDER BY id ASC) " - f"LIMIT 10000" + "SELECT id, email FROM " + "(SELECT id, properties.email AS email FROM " + "(SELECT DISTINCT person_id FROM events) " + "AS source INNER JOIN " + "persons ON equals(persons.id, source.person_id) ORDER BY id ASC) " + "LIMIT 10000" ) + assert hogql == expected diff --git a/posthog/hogql_queries/actors_query_runner.py b/posthog/hogql_queries/actors_query_runner.py index 93e9f40c70739..215c7ed183165 100644 --- a/posthog/hogql_queries/actors_query_runner.py +++ b/posthog/hogql_queries/actors_query_runner.py @@ -142,11 +142,11 @@ def source_table_join(self) -> ast.JoinExpr: source_alias = "source" return ast.JoinExpr( - table=ast.Field(chain=[self.strategy.origin]), + table=source_query, + alias=source_alias, next_join=ast.JoinExpr( - table=source_query, + table=ast.Field(chain=[self.strategy.origin]), join_type="INNER JOIN", - alias=source_alias, constraint=ast.JoinConstraint( expr=ast.CompareOperation( op=ast.CompareOperationOp.Eq, diff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel.ambr b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel.ambr index 8379672352c1c..8beaed1b11bc2 100644 --- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel.ambr +++ b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel.ambr @@ -98,13 +98,6 @@ toTimeZone(persons.created_at, 'UTC') AS created_at, 1 FROM - (SELECT argMax(person.created_at, person.version) AS created_at, - person.id AS id - FROM person - WHERE equals(person.team_id, 2) - GROUP BY person.id - HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons - INNER JOIN (SELECT aggregation_target AS actor_id FROM (SELECT aggregation_target AS aggregation_target, @@ -185,7 +178,14 @@ HAVING ifNull(equals(steps, max_steps), isNull(steps) and isNull(max_steps))) WHERE ifNull(in(steps, [2, 3]), 0) - ORDER BY aggregation_target ASC) AS source ON equals(persons.id, source.actor_id) + ORDER BY aggregation_target ASC) AS source + INNER JOIN + (SELECT argMax(person.created_at, person.version) AS created_at, + person.id AS id + FROM person + WHERE equals(person.team_id, 2) + GROUP BY person.id + HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id) ORDER BY toTimeZone(persons.created_at, 'UTC') DESC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -493,13 +493,6 @@ toTimeZone(persons.created_at, 'UTC') AS created_at, 1 FROM - (SELECT argMax(person.created_at, person.version) AS created_at, - person.id AS id - FROM person - WHERE equals(person.team_id, 2) - GROUP BY person.id - HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons - INNER JOIN (SELECT aggregation_target AS actor_id FROM (SELECT aggregation_target AS aggregation_target, @@ -592,7 +585,14 @@ HAVING ifNull(equals(steps, max_steps), isNull(steps) and isNull(max_steps))) WHERE ifNull(in(steps, [1, 2, 3]), 0) - ORDER BY aggregation_target ASC) AS source ON equals(persons.id, source.actor_id) + ORDER BY aggregation_target ASC) AS source + INNER JOIN + (SELECT argMax(person.created_at, person.version) AS created_at, + person.id AS id + FROM person + WHERE equals(person.team_id, 2) + GROUP BY person.id + HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id) ORDER BY toTimeZone(persons.created_at, 'UTC') DESC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -607,13 +607,6 @@ toTimeZone(persons.created_at, 'UTC') AS created_at, 1 FROM - (SELECT argMax(person.created_at, person.version) AS created_at, - person.id AS id - FROM person - WHERE equals(person.team_id, 2) - GROUP BY person.id - HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons - INNER JOIN (SELECT aggregation_target AS actor_id FROM (SELECT aggregation_target AS aggregation_target, @@ -706,7 +699,14 @@ HAVING ifNull(equals(steps, max_steps), isNull(steps) and isNull(max_steps))) WHERE ifNull(in(steps, [2, 3]), 0) - ORDER BY aggregation_target ASC) AS source ON equals(persons.id, source.actor_id) + ORDER BY aggregation_target ASC) AS source + INNER JOIN + (SELECT argMax(person.created_at, person.version) AS created_at, + person.id AS id + FROM person + WHERE equals(person.team_id, 2) + GROUP BY person.id + HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id) ORDER BY toTimeZone(persons.created_at, 'UTC') DESC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -721,13 +721,6 @@ toTimeZone(persons.created_at, 'UTC') AS created_at, 1 FROM - (SELECT argMax(person.created_at, person.version) AS created_at, - person.id AS id - FROM person - WHERE equals(person.team_id, 2) - GROUP BY person.id - HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons - INNER JOIN (SELECT aggregation_target AS actor_id FROM (SELECT aggregation_target AS aggregation_target, @@ -820,7 +813,14 @@ HAVING ifNull(equals(steps, max_steps), isNull(steps) and isNull(max_steps))) WHERE ifNull(in(steps, [3]), 0) - ORDER BY aggregation_target ASC) AS source ON equals(persons.id, source.actor_id) + ORDER BY aggregation_target ASC) AS source + INNER JOIN + (SELECT argMax(person.created_at, person.version) AS created_at, + person.id AS id + FROM person + WHERE equals(person.team_id, 2) + GROUP BY person.id + HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id) ORDER BY toTimeZone(persons.created_at, 'UTC') DESC LIMIT 101 OFFSET 0 SETTINGS readonly=2, diff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation.ambr b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation.ambr index b5e3e020c1ec0..41b0c76b35d61 100644 --- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation.ambr +++ b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlation.ambr @@ -312,12 +312,6 @@ persons.id AS id, source.matching_events AS matching_events FROM - (SELECT person.id AS id - FROM person - WHERE equals(person.team_id, 2) - GROUP BY person.id - HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM @@ -427,7 +421,13 @@ ORDER BY aggregation_target ASC) AS funnel_actors WHERE ifNull(equals(funnel_actors.steps, 2), 0) GROUP BY funnel_actors.actor_id - ORDER BY funnel_actors.actor_id ASC) AS source ON equals(persons.id, source.actor_id) + ORDER BY funnel_actors.actor_id ASC) AS source + INNER JOIN + (SELECT person.id AS id + FROM person + WHERE equals(person.team_id, 2) + GROUP BY person.id + HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id) ORDER BY persons.id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -455,12 +455,6 @@ persons.id AS id, source.matching_events AS matching_events FROM - (SELECT person.id AS id - FROM person - WHERE equals(person.team_id, 2) - GROUP BY person.id - HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM @@ -570,7 +564,13 @@ ORDER BY aggregation_target ASC) AS funnel_actors WHERE ifNull(notEquals(funnel_actors.steps, 2), 1) GROUP BY funnel_actors.actor_id - ORDER BY funnel_actors.actor_id ASC) AS source ON equals(persons.id, source.actor_id) + ORDER BY funnel_actors.actor_id ASC) AS source + INNER JOIN + (SELECT person.id AS id + FROM person + WHERE equals(person.team_id, 2) + GROUP BY person.id + HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id) ORDER BY persons.id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -598,12 +598,6 @@ persons.id AS id, source.matching_events AS matching_events FROM - (SELECT person.id AS id - FROM person - WHERE equals(person.team_id, 2) - GROUP BY person.id - HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM @@ -713,7 +707,13 @@ ORDER BY aggregation_target ASC) AS funnel_actors WHERE ifNull(equals(funnel_actors.steps, 2), 0) GROUP BY funnel_actors.actor_id - ORDER BY funnel_actors.actor_id ASC) AS source ON equals(persons.id, source.actor_id) + ORDER BY funnel_actors.actor_id ASC) AS source + INNER JOIN + (SELECT person.id AS id + FROM person + WHERE equals(person.team_id, 2) + GROUP BY person.id + HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id) ORDER BY persons.id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -741,12 +741,6 @@ persons.id AS id, source.matching_events AS matching_events FROM - (SELECT person.id AS id - FROM person - WHERE equals(person.team_id, 2) - GROUP BY person.id - HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM @@ -856,7 +850,13 @@ ORDER BY aggregation_target ASC) AS funnel_actors WHERE ifNull(notEquals(funnel_actors.steps, 2), 1) GROUP BY funnel_actors.actor_id - ORDER BY funnel_actors.actor_id ASC) AS source ON equals(persons.id, source.actor_id) + ORDER BY funnel_actors.actor_id ASC) AS source + INNER JOIN + (SELECT person.id AS id + FROM person + WHERE equals(person.team_id, 2) + GROUP BY person.id + HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id) ORDER BY persons.id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -1278,13 +1278,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM events AS event @@ -1377,7 +1370,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`) WHERE and(equals(event.team_id, 2), greaterOrEquals(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-01 00:00:00', 6, 'UTC'))), less(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-14 23:59:59', 6, 'UTC'))), equals(event.team_id, 2), greater(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), funnel_actors.first_timestamp), less(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), coalesce(funnel_actors.final_timestamp, plus(toTimeZone(funnel_actors.first_timestamp, 'UTC'), toIntervalDay(14)), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-14 23:59:59', 6, 'UTC')))), notIn(event.event, ['paid', 'user signed up']), equals(event.event, 'positively_related'), ifNull(equals(funnel_actors.steps, 2), 0)) GROUP BY actor_id - ORDER BY actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -1389,13 +1389,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM events AS event @@ -1488,7 +1481,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`) WHERE and(equals(event.team_id, 2), greaterOrEquals(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-01 00:00:00', 6, 'UTC'))), less(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-14 23:59:59', 6, 'UTC'))), equals(event.team_id, 2), greater(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), funnel_actors.first_timestamp), less(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), coalesce(funnel_actors.final_timestamp, plus(toTimeZone(funnel_actors.first_timestamp, 'UTC'), toIntervalDay(14)), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-14 23:59:59', 6, 'UTC')))), notIn(event.event, ['paid', 'user signed up']), equals(event.event, 'positively_related'), ifNull(notEquals(funnel_actors.steps, 2), 1)) GROUP BY actor_id - ORDER BY actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -1500,13 +1500,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM events AS event @@ -1599,7 +1592,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`) WHERE and(equals(event.team_id, 2), greaterOrEquals(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-01 00:00:00', 6, 'UTC'))), less(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-14 23:59:59', 6, 'UTC'))), equals(event.team_id, 2), greater(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), funnel_actors.first_timestamp), less(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), coalesce(funnel_actors.final_timestamp, plus(toTimeZone(funnel_actors.first_timestamp, 'UTC'), toIntervalDay(14)), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-14 23:59:59', 6, 'UTC')))), notIn(event.event, ['paid', 'user signed up']), equals(event.event, 'negatively_related'), ifNull(equals(funnel_actors.steps, 2), 0)) GROUP BY actor_id - ORDER BY actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -1611,13 +1611,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM events AS event @@ -1710,7 +1703,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`) WHERE and(equals(event.team_id, 2), greaterOrEquals(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-01 00:00:00', 6, 'UTC'))), less(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-14 23:59:59', 6, 'UTC'))), equals(event.team_id, 2), greater(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), funnel_actors.first_timestamp), less(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), coalesce(funnel_actors.final_timestamp, plus(toTimeZone(funnel_actors.first_timestamp, 'UTC'), toIntervalDay(14)), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-14 23:59:59', 6, 'UTC')))), notIn(event.event, ['paid', 'user signed up']), equals(event.event, 'negatively_related'), ifNull(notEquals(funnel_actors.steps, 2), 1)) GROUP BY actor_id - ORDER BY actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -1866,13 +1866,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM events AS event @@ -1965,7 +1958,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`) WHERE and(equals(event.team_id, 2), greaterOrEquals(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-01 00:00:00', 6, 'UTC'))), less(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-14 23:59:59', 6, 'UTC'))), equals(event.team_id, 2), greater(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), funnel_actors.first_timestamp), less(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), coalesce(funnel_actors.final_timestamp, plus(toTimeZone(funnel_actors.first_timestamp, 'UTC'), toIntervalDay(14)), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-14 23:59:59', 6, 'UTC')))), notIn(event.event, ['paid', 'user signed up']), equals(event.event, 'negatively_related'), ifNull(equals(funnel_actors.steps, 2), 0)) GROUP BY actor_id - ORDER BY actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -1977,13 +1977,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM events AS event @@ -2076,7 +2069,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`) WHERE and(equals(event.team_id, 2), greaterOrEquals(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-01 00:00:00', 6, 'UTC'))), less(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-14 23:59:59', 6, 'UTC'))), equals(event.team_id, 2), greater(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), funnel_actors.first_timestamp), less(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), coalesce(funnel_actors.final_timestamp, plus(toTimeZone(funnel_actors.first_timestamp, 'UTC'), toIntervalDay(14)), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-14 23:59:59', 6, 'UTC')))), notIn(event.event, ['paid', 'user signed up']), equals(event.event, 'negatively_related'), ifNull(notEquals(funnel_actors.steps, 2), 1)) GROUP BY actor_id - ORDER BY actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -2216,13 +2216,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM events AS event @@ -2315,7 +2308,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`) WHERE and(equals(event.team_id, 2), greaterOrEquals(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-01 00:00:00', 6, 'UTC'))), less(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-14 23:59:59', 6, 'UTC'))), equals(event.team_id, 2), greater(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), funnel_actors.first_timestamp), less(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), coalesce(funnel_actors.final_timestamp, plus(toTimeZone(funnel_actors.first_timestamp, 'UTC'), toIntervalDay(14)), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-14 23:59:59', 6, 'UTC')))), notIn(event.event, ['paid', 'user signed up']), equals(event.event, 'positively_related'), ifNull(equals(funnel_actors.steps, 2), 0)) GROUP BY actor_id - ORDER BY actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -2327,13 +2327,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM events AS event @@ -2426,7 +2419,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`) WHERE and(equals(event.team_id, 2), greaterOrEquals(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-01 00:00:00', 6, 'UTC'))), less(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-14 23:59:59', 6, 'UTC'))), equals(event.team_id, 2), greater(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), funnel_actors.first_timestamp), less(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), coalesce(funnel_actors.final_timestamp, plus(toTimeZone(funnel_actors.first_timestamp, 'UTC'), toIntervalDay(14)), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-14 23:59:59', 6, 'UTC')))), notIn(event.event, ['paid', 'user signed up']), equals(event.event, 'positively_related'), ifNull(notEquals(funnel_actors.steps, 2), 1)) GROUP BY actor_id - ORDER BY actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -2438,13 +2438,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM events AS event @@ -2537,7 +2530,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`) WHERE and(equals(event.team_id, 2), greaterOrEquals(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-01 00:00:00', 6, 'UTC'))), less(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-14 23:59:59', 6, 'UTC'))), equals(event.team_id, 2), greater(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), funnel_actors.first_timestamp), less(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), coalesce(funnel_actors.final_timestamp, plus(toTimeZone(funnel_actors.first_timestamp, 'UTC'), toIntervalDay(14)), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-14 23:59:59', 6, 'UTC')))), notIn(event.event, ['paid', 'user signed up']), equals(event.event, 'negatively_related'), ifNull(equals(funnel_actors.steps, 2), 0)) GROUP BY actor_id - ORDER BY actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -2549,13 +2549,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM events AS event @@ -2648,7 +2641,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`) WHERE and(equals(event.team_id, 2), greaterOrEquals(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-01 00:00:00', 6, 'UTC'))), less(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-14 23:59:59', 6, 'UTC'))), equals(event.team_id, 2), greater(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), funnel_actors.first_timestamp), less(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), coalesce(funnel_actors.final_timestamp, plus(toTimeZone(funnel_actors.first_timestamp, 'UTC'), toIntervalDay(14)), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-14 23:59:59', 6, 'UTC')))), notIn(event.event, ['paid', 'user signed up']), equals(event.event, 'negatively_related'), ifNull(notEquals(funnel_actors.steps, 2), 1)) GROUP BY actor_id - ORDER BY actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -2804,13 +2804,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM events AS event @@ -2903,7 +2896,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`) WHERE and(equals(event.team_id, 2), greaterOrEquals(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-01 00:00:00', 6, 'UTC'))), less(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-14 23:59:59', 6, 'UTC'))), equals(event.team_id, 2), greater(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), funnel_actors.first_timestamp), less(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), coalesce(funnel_actors.final_timestamp, plus(toTimeZone(funnel_actors.first_timestamp, 'UTC'), toIntervalDay(14)), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-14 23:59:59', 6, 'UTC')))), notIn(event.event, ['paid', 'user signed up']), equals(event.event, 'negatively_related'), ifNull(equals(funnel_actors.steps, 2), 0)) GROUP BY actor_id - ORDER BY actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -2915,13 +2915,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM events AS event @@ -3014,7 +3007,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors ON equals(funnel_actors.actor_id, event.`$group_0`) WHERE and(equals(event.team_id, 2), greaterOrEquals(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-01 00:00:00', 6, 'UTC'))), less(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-14 23:59:59', 6, 'UTC'))), equals(event.team_id, 2), greater(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), funnel_actors.first_timestamp), less(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), coalesce(funnel_actors.final_timestamp, plus(toTimeZone(funnel_actors.first_timestamp, 'UTC'), toIntervalDay(14)), assumeNotNull(parseDateTime64BestEffortOrNull('2020-01-14 23:59:59', 6, 'UTC')))), notIn(event.event, ['paid', 'user signed up']), equals(event.event, 'negatively_related'), ifNull(notEquals(funnel_actors.steps, 2), 1)) GROUP BY actor_id - ORDER BY actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -3169,13 +3169,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM @@ -3275,7 +3268,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors WHERE ifNull(equals(funnel_actors.steps, 2), 0) GROUP BY funnel_actors.actor_id - ORDER BY funnel_actors.actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY funnel_actors.actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -3287,13 +3287,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM @@ -3393,7 +3386,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors WHERE ifNull(notEquals(funnel_actors.steps, 2), 1) GROUP BY funnel_actors.actor_id - ORDER BY funnel_actors.actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY funnel_actors.actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -3405,13 +3405,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM @@ -3511,7 +3504,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors WHERE ifNull(equals(funnel_actors.steps, 2), 0) GROUP BY funnel_actors.actor_id - ORDER BY funnel_actors.actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY funnel_actors.actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -3523,13 +3523,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM @@ -3629,7 +3622,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors WHERE ifNull(notEquals(funnel_actors.steps, 2), 1) GROUP BY funnel_actors.actor_id - ORDER BY funnel_actors.actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY funnel_actors.actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -3927,13 +3927,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM @@ -4033,7 +4026,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors WHERE ifNull(equals(funnel_actors.steps, 2), 0) GROUP BY funnel_actors.actor_id - ORDER BY funnel_actors.actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY funnel_actors.actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -4045,13 +4045,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM @@ -4151,7 +4144,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors WHERE ifNull(notEquals(funnel_actors.steps, 2), 1) GROUP BY funnel_actors.actor_id - ORDER BY funnel_actors.actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY funnel_actors.actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -4163,13 +4163,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM @@ -4269,7 +4262,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors WHERE ifNull(equals(funnel_actors.steps, 2), 0) GROUP BY funnel_actors.actor_id - ORDER BY funnel_actors.actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY funnel_actors.actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -4281,13 +4281,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM @@ -4387,7 +4380,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors WHERE ifNull(notEquals(funnel_actors.steps, 2), 1) GROUP BY funnel_actors.actor_id - ORDER BY funnel_actors.actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY funnel_actors.actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -4685,13 +4685,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM @@ -4791,7 +4784,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors WHERE ifNull(equals(funnel_actors.steps, 2), 0) GROUP BY funnel_actors.actor_id - ORDER BY funnel_actors.actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY funnel_actors.actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -4803,13 +4803,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM @@ -4909,7 +4902,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors WHERE ifNull(notEquals(funnel_actors.steps, 2), 1) GROUP BY funnel_actors.actor_id - ORDER BY funnel_actors.actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY funnel_actors.actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -4921,13 +4921,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM @@ -5027,7 +5020,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors WHERE ifNull(equals(funnel_actors.steps, 2), 0) GROUP BY funnel_actors.actor_id - ORDER BY funnel_actors.actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY funnel_actors.actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -5039,13 +5039,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM @@ -5145,7 +5138,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors WHERE ifNull(notEquals(funnel_actors.steps, 2), 1) GROUP BY funnel_actors.actor_id - ORDER BY funnel_actors.actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY funnel_actors.actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -5443,13 +5443,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM @@ -5549,7 +5542,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors WHERE ifNull(equals(funnel_actors.steps, 2), 0) GROUP BY funnel_actors.actor_id - ORDER BY funnel_actors.actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY funnel_actors.actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -5561,13 +5561,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM @@ -5667,7 +5660,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors WHERE ifNull(notEquals(funnel_actors.steps, 2), 1) GROUP BY funnel_actors.actor_id - ORDER BY funnel_actors.actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY funnel_actors.actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -5679,13 +5679,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM @@ -5785,7 +5778,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors WHERE ifNull(equals(funnel_actors.steps, 2), 0) GROUP BY funnel_actors.actor_id - ORDER BY funnel_actors.actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY funnel_actors.actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -5797,13 +5797,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM @@ -5903,7 +5896,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors WHERE ifNull(notEquals(funnel_actors.steps, 2), 1) GROUP BY funnel_actors.actor_id - ORDER BY funnel_actors.actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY funnel_actors.actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -6201,13 +6201,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM @@ -6307,7 +6300,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors WHERE ifNull(equals(funnel_actors.steps, 2), 0) GROUP BY funnel_actors.actor_id - ORDER BY funnel_actors.actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY funnel_actors.actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -6319,13 +6319,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM @@ -6425,7 +6418,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors WHERE ifNull(notEquals(funnel_actors.steps, 2), 1) GROUP BY funnel_actors.actor_id - ORDER BY funnel_actors.actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY funnel_actors.actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -6437,13 +6437,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM @@ -6543,7 +6536,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors WHERE ifNull(equals(funnel_actors.steps, 2), 0) GROUP BY funnel_actors.actor_id - ORDER BY funnel_actors.actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY funnel_actors.actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -6555,13 +6555,6 @@ ''' SELECT source.actor_id AS actor_id FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM @@ -6661,7 +6654,14 @@ ORDER BY aggregation_target ASC) AS funnel_actors WHERE ifNull(notEquals(funnel_actors.steps, 2), 1) GROUP BY funnel_actors.actor_id - ORDER BY funnel_actors.actor_id ASC) AS source ON equals(groups.key, source.actor_id) + ORDER BY funnel_actors.actor_id ASC) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, diff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlations_persons.ambr b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlations_persons.ambr index 62715e7d96b63..cdfd93b09cb4e 100644 --- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlations_persons.ambr +++ b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_correlations_persons.ambr @@ -5,12 +5,6 @@ persons.id AS id, source.matching_events AS matching_events FROM - (SELECT person.id AS id - FROM person - WHERE equals(person.team_id, 2) - GROUP BY person.id - HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM events AS event @@ -117,7 +111,13 @@ ORDER BY aggregation_target ASC) AS funnel_actors ON equals(event__pdi.person_id, funnel_actors.actor_id) WHERE and(equals(event.team_id, 2), greaterOrEquals(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2021-01-01 00:00:00', 6, 'UTC'))), less(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2021-01-08 23:59:59', 6, 'UTC'))), equals(event.team_id, 2), greater(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), funnel_actors.first_timestamp), less(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), coalesce(funnel_actors.final_timestamp, plus(toTimeZone(funnel_actors.first_timestamp, 'UTC'), toIntervalDay(14)), assumeNotNull(parseDateTime64BestEffortOrNull('2021-01-08 23:59:59', 6, 'UTC')))), notIn(event.event, ['$pageview', 'insight analyzed']), equals(event.event, 'insight loaded'), ifNull(equals(funnel_actors.steps, 2), 0)) GROUP BY actor_id - ORDER BY actor_id ASC) AS source ON equals(persons.id, source.actor_id) + ORDER BY actor_id ASC) AS source + INNER JOIN + (SELECT person.id AS id + FROM person + WHERE equals(person.team_id, 2) + GROUP BY person.id + HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id) ORDER BY persons.id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -145,12 +145,6 @@ persons.id AS id, source.matching_events AS matching_events FROM - (SELECT person.id AS id - FROM person - WHERE equals(person.team_id, 2) - GROUP BY person.id - HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM events AS event @@ -323,7 +317,13 @@ ORDER BY aggregation_target ASC) AS funnel_actors ON equals(event__pdi.person_id, funnel_actors.actor_id) WHERE and(equals(event.team_id, 2), greaterOrEquals(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2021-01-01 00:00:00', 6, 'UTC'))), less(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), assumeNotNull(parseDateTime64BestEffortOrNull('2021-01-08 23:59:59', 6, 'UTC'))), equals(event.team_id, 2), greater(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), funnel_actors.first_timestamp), less(toTimeZone(toDateTime(toTimeZone(event.timestamp, 'UTC'), 'UTC'), 'UTC'), coalesce(funnel_actors.final_timestamp, plus(toTimeZone(funnel_actors.first_timestamp, 'UTC'), toIntervalDay(14)), assumeNotNull(parseDateTime64BestEffortOrNull('2021-01-08 23:59:59', 6, 'UTC')))), notIn(event.event, ['$pageview', 'insight analyzed', 'insight updated']), equals(event.event, 'insight loaded'), ifNull(notEquals(funnel_actors.steps, 3), 1)) GROUP BY actor_id - ORDER BY actor_id ASC) AS source ON equals(persons.id, source.actor_id) + ORDER BY actor_id ASC) AS source + INNER JOIN + (SELECT person.id AS id + FROM person + WHERE equals(person.team_id, 2) + GROUP BY person.id + HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id) ORDER BY persons.id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -351,12 +351,6 @@ persons.id AS id, source.matching_events AS matching_events FROM - (SELECT person.id AS id - FROM person - WHERE equals(person.team_id, 2) - GROUP BY person.id - HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM @@ -466,7 +460,13 @@ ORDER BY aggregation_target ASC) AS funnel_actors WHERE ifNull(equals(funnel_actors.steps, 2), 0) GROUP BY funnel_actors.actor_id - ORDER BY funnel_actors.actor_id ASC) AS source ON equals(persons.id, source.actor_id) + ORDER BY funnel_actors.actor_id ASC) AS source + INNER JOIN + (SELECT person.id AS id + FROM person + WHERE equals(person.team_id, 2) + GROUP BY person.id + HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id) ORDER BY persons.id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -494,12 +494,6 @@ persons.id AS id, source.matching_events AS matching_events FROM - (SELECT person.id AS id - FROM person - WHERE equals(person.team_id, 2) - GROUP BY person.id - HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM @@ -609,7 +603,13 @@ ORDER BY aggregation_target ASC) AS funnel_actors WHERE ifNull(equals(funnel_actors.steps, 2), 0) GROUP BY funnel_actors.actor_id - ORDER BY funnel_actors.actor_id ASC) AS source ON equals(persons.id, source.actor_id) + ORDER BY funnel_actors.actor_id ASC) AS source + INNER JOIN + (SELECT person.id AS id + FROM person + WHERE equals(person.team_id, 2) + GROUP BY person.id + HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id) ORDER BY persons.id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -637,12 +637,6 @@ persons.id AS id, source.matching_events AS matching_events FROM - (SELECT person.id AS id - FROM person - WHERE equals(person.team_id, 2) - GROUP BY person.id - HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons - INNER JOIN (SELECT funnel_actors.actor_id AS actor_id, any(funnel_actors.matching_events) AS matching_events FROM @@ -752,7 +746,13 @@ ORDER BY aggregation_target ASC) AS funnel_actors WHERE ifNull(notEquals(funnel_actors.steps, 2), 1) GROUP BY funnel_actors.actor_id - ORDER BY funnel_actors.actor_id ASC) AS source ON equals(persons.id, source.actor_id) + ORDER BY funnel_actors.actor_id ASC) AS source + INNER JOIN + (SELECT person.id AS id + FROM person + WHERE equals(person.team_id, 2) + GROUP BY person.id + HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id) ORDER BY persons.id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, diff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_persons.ambr b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_persons.ambr index 723165d9d8320..0218c64c21632 100644 --- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_persons.ambr +++ b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_persons.ambr @@ -5,12 +5,6 @@ persons.id AS id, source.matching_events AS matching_events FROM - (SELECT person.id AS id - FROM person - WHERE equals(person.team_id, 2) - GROUP BY person.id - HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons - INNER JOIN (SELECT aggregation_target AS actor_id, step_0_matching_events AS matching_events FROM @@ -159,7 +153,13 @@ HAVING ifNull(equals(steps, max_steps), isNull(steps) and isNull(max_steps))) WHERE ifNull(in(steps, [1, 2, 3]), 0) - ORDER BY aggregation_target ASC) AS source ON equals(persons.id, source.actor_id) + ORDER BY aggregation_target ASC) AS source + INNER JOIN + (SELECT person.id AS id + FROM person + WHERE equals(person.team_id, 2) + GROUP BY person.id + HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id) ORDER BY persons.id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -187,12 +187,6 @@ persons.id AS id, source.matching_events AS matching_events FROM - (SELECT person.id AS id - FROM person - WHERE equals(person.team_id, 2) - GROUP BY person.id - HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons - INNER JOIN (SELECT aggregation_target AS actor_id, step_1_matching_events AS matching_events FROM @@ -341,7 +335,13 @@ HAVING ifNull(equals(steps, max_steps), isNull(steps) and isNull(max_steps))) WHERE ifNull(in(steps, [2, 3]), 0) - ORDER BY aggregation_target ASC) AS source ON equals(persons.id, source.actor_id) + ORDER BY aggregation_target ASC) AS source + INNER JOIN + (SELECT person.id AS id + FROM person + WHERE equals(person.team_id, 2) + GROUP BY person.id + HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id) ORDER BY persons.id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -369,12 +369,6 @@ persons.id AS id, source.matching_events AS matching_events FROM - (SELECT person.id AS id - FROM person - WHERE equals(person.team_id, 2) - GROUP BY person.id - HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons - INNER JOIN (SELECT aggregation_target AS actor_id, step_1_matching_events AS matching_events FROM @@ -523,7 +517,13 @@ HAVING ifNull(equals(steps, max_steps), isNull(steps) and isNull(max_steps))) WHERE ifNull(equals(steps, 2), 0) - ORDER BY aggregation_target ASC) AS source ON equals(persons.id, source.actor_id) + ORDER BY aggregation_target ASC) AS source + INNER JOIN + (SELECT person.id AS id + FROM person + WHERE equals(person.team_id, 2) + GROUP BY person.id + HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id) ORDER BY persons.id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, diff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_strict_persons.ambr b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_strict_persons.ambr index 1496e07c65e02..43eee21ac83ce 100644 --- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_strict_persons.ambr +++ b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_strict_persons.ambr @@ -5,12 +5,6 @@ persons.id AS id, source.matching_events AS matching_events FROM - (SELECT person.id AS id - FROM person - WHERE equals(person.team_id, 2) - GROUP BY person.id - HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons - INNER JOIN (SELECT aggregation_target AS actor_id, step_0_matching_events AS matching_events FROM @@ -119,7 +113,13 @@ HAVING ifNull(equals(steps, max_steps), isNull(steps) and isNull(max_steps))) WHERE ifNull(in(steps, [1, 2, 3]), 0) - ORDER BY aggregation_target ASC) AS source ON equals(persons.id, source.actor_id) + ORDER BY aggregation_target ASC) AS source + INNER JOIN + (SELECT person.id AS id + FROM person + WHERE equals(person.team_id, 2) + GROUP BY person.id + HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id) ORDER BY persons.id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -147,12 +147,6 @@ persons.id AS id, source.matching_events AS matching_events FROM - (SELECT person.id AS id - FROM person - WHERE equals(person.team_id, 2) - GROUP BY person.id - HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons - INNER JOIN (SELECT aggregation_target AS actor_id, step_1_matching_events AS matching_events FROM @@ -261,7 +255,13 @@ HAVING ifNull(equals(steps, max_steps), isNull(steps) and isNull(max_steps))) WHERE ifNull(in(steps, [2, 3]), 0) - ORDER BY aggregation_target ASC) AS source ON equals(persons.id, source.actor_id) + ORDER BY aggregation_target ASC) AS source + INNER JOIN + (SELECT person.id AS id + FROM person + WHERE equals(person.team_id, 2) + GROUP BY person.id + HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id) ORDER BY persons.id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -289,12 +289,6 @@ persons.id AS id, source.matching_events AS matching_events FROM - (SELECT person.id AS id - FROM person - WHERE equals(person.team_id, 2) - GROUP BY person.id - HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons - INNER JOIN (SELECT aggregation_target AS actor_id, step_1_matching_events AS matching_events FROM @@ -403,7 +397,13 @@ HAVING ifNull(equals(steps, max_steps), isNull(steps) and isNull(max_steps))) WHERE ifNull(equals(steps, 2), 0) - ORDER BY aggregation_target ASC) AS source ON equals(persons.id, source.actor_id) + ORDER BY aggregation_target ASC) AS source + INNER JOIN + (SELECT person.id AS id + FROM person + WHERE equals(person.team_id, 2) + GROUP BY person.id + HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id) ORDER BY persons.id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, diff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_trends_persons.ambr b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_trends_persons.ambr index 32518bdbf9bbc..2c6daed30808b 100644 --- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_trends_persons.ambr +++ b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_trends_persons.ambr @@ -5,12 +5,6 @@ persons.id AS id, source.matching_events AS matching_events FROM - (SELECT person.id AS id - FROM person - WHERE equals(person.team_id, 2) - GROUP BY person.id - HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons - INNER JOIN (SELECT aggregation_target AS actor_id, step_1_matching_events AS matching_events FROM @@ -145,7 +139,13 @@ GROUP BY aggregation_target, entrance_period_start) WHERE ifNull(greaterOrEquals(steps_completed, 2), 0) - ORDER BY aggregation_target ASC) AS source ON equals(persons.id, source.actor_id) + ORDER BY aggregation_target ASC) AS source + INNER JOIN + (SELECT person.id AS id + FROM person + WHERE equals(person.team_id, 2) + GROUP BY person.id + HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id) ORDER BY persons.id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -173,12 +173,6 @@ persons.id AS id, source.matching_events AS matching_events FROM - (SELECT person.id AS id - FROM person - WHERE equals(person.team_id, 2) - GROUP BY person.id - HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons - INNER JOIN (SELECT aggregation_target AS actor_id, final_matching_events AS matching_events FROM @@ -313,7 +307,13 @@ GROUP BY aggregation_target, entrance_period_start) WHERE and(ifNull(greaterOrEquals(steps_completed, 1), 0), ifNull(less(steps_completed, 3), 0)) - ORDER BY aggregation_target ASC) AS source ON equals(persons.id, source.actor_id) + ORDER BY aggregation_target ASC) AS source + INNER JOIN + (SELECT person.id AS id + FROM person + WHERE equals(person.team_id, 2) + GROUP BY person.id + HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id) ORDER BY persons.id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -341,12 +341,6 @@ persons.id AS id, source.matching_events AS matching_events FROM - (SELECT person.id AS id - FROM person - WHERE equals(person.team_id, 2) - GROUP BY person.id - HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons - INNER JOIN (SELECT aggregation_target AS actor_id, final_matching_events AS matching_events FROM @@ -481,7 +475,13 @@ GROUP BY aggregation_target, entrance_period_start) WHERE ifNull(greaterOrEquals(steps_completed, 3), 0) - ORDER BY aggregation_target ASC) AS source ON equals(persons.id, source.actor_id) + ORDER BY aggregation_target ASC) AS source + INNER JOIN + (SELECT person.id AS id + FROM person + WHERE equals(person.team_id, 2) + GROUP BY person.id + HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id) ORDER BY persons.id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, diff --git a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_unordered_persons.ambr b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_unordered_persons.ambr index 5ced3fb2b9766..7f607b21570bc 100644 --- a/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_unordered_persons.ambr +++ b/posthog/hogql_queries/insights/funnels/test/__snapshots__/test_funnel_unordered_persons.ambr @@ -5,12 +5,6 @@ persons.id AS id, source.matching_events AS matching_events FROM - (SELECT person.id AS id - FROM person - WHERE equals(person.team_id, 2) - GROUP BY person.id - HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons - INNER JOIN (SELECT aggregation_target AS actor_id, array() AS matching_events FROM @@ -263,7 +257,13 @@ HAVING ifNull(equals(steps, max_steps), isNull(steps) and isNull(max_steps))) WHERE ifNull(in(steps, [1, 2, 3]), 0) - ORDER BY aggregation_target ASC) AS source ON equals(persons.id, source.actor_id) + ORDER BY aggregation_target ASC) AS source + INNER JOIN + (SELECT person.id AS id + FROM person + WHERE equals(person.team_id, 2) + GROUP BY person.id + HAVING ifNull(equals(argMax(person.is_deleted, person.version), 0), 0) SETTINGS optimize_aggregation_in_order=1) AS persons ON equals(persons.id, source.actor_id) ORDER BY persons.id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, diff --git a/posthog/hogql_queries/insights/test/__snapshots__/test_retention_query_runner.ambr b/posthog/hogql_queries/insights/test/__snapshots__/test_retention_query_runner.ambr index 4e2714d2e7212..f961e10d59a03 100644 --- a/posthog/hogql_queries/insights/test/__snapshots__/test_retention_query_runner.ambr +++ b/posthog/hogql_queries/insights/test/__snapshots__/test_retention_query_runner.ambr @@ -50,13 +50,6 @@ SELECT groups.key AS key, source.appearances AS appearances FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT actor_activity.actor_id AS actor_id, groupArray(actor_activity.intervals_from_base) AS appearance_intervals, arraySort(appearance_intervals) AS appearances, @@ -99,7 +92,14 @@ FROM events WHERE and(equals(events.team_id, 2), equals(events.event, '$pageview'), not(has([''], events.`$group_0`)), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfWeek(toDateTime64('2020-06-07 00:00:00.000000', 6, 'UTC'), 0)), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-07-27 00:00:00.000000', 6, 'UTC'))))) AS target_event) WHERE and(or(0, ifNull(equals(breakdown_values, [0]), 0)), or(1, isNull(intervals_from_base)))) AS actor_activity - GROUP BY actor_activity.actor_id) AS source ON equals(groups.key, source.actor_id) + GROUP BY actor_activity.actor_id) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY length(source.appearances) DESC, source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2, @@ -204,13 +204,6 @@ SELECT groups.key AS key, source.appearances AS appearances FROM - (SELECT groups.group_type_index AS index, - groups.group_key AS key - FROM groups - WHERE equals(groups.team_id, 2) - GROUP BY groups.group_type_index, - groups.group_key) AS groups - INNER JOIN (SELECT actor_activity.actor_id AS actor_id, groupArray(actor_activity.intervals_from_base) AS appearance_intervals, arraySort(appearance_intervals) AS appearances, @@ -253,7 +246,14 @@ FROM events WHERE and(equals(events.team_id, 2), equals(events.event, '$pageview'), not(has([''], events.`$group_0`)), and(greaterOrEquals(toTimeZone(events.timestamp, 'UTC'), toStartOfWeek(toDateTime64('2020-06-07 00:00:00.000000', 6, 'UTC'), 0)), lessOrEquals(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-07-27 00:00:00.000000', 6, 'UTC'))))) AS target_event) WHERE and(or(0, ifNull(equals(breakdown_values, [0]), 0)), or(1, isNull(intervals_from_base)))) AS actor_activity - GROUP BY actor_activity.actor_id) AS source ON equals(groups.key, source.actor_id) + GROUP BY actor_activity.actor_id) AS source + INNER JOIN + (SELECT groups.group_type_index AS index, + groups.group_key AS key + FROM groups + WHERE equals(groups.team_id, 2) + GROUP BY groups.group_type_index, + groups.group_key) AS groups ON equals(groups.key, source.actor_id) ORDER BY length(source.appearances) DESC, source.actor_id ASC LIMIT 101 OFFSET 0 SETTINGS readonly=2,