From 485192367412f33c1582de5ca60b05c614d48b07 Mon Sep 17 00:00:00 2001 From: Marius Andra Date: Tue, 16 Apr 2024 11:54:55 +0200 Subject: [PATCH 01/14] fix(cohorts): optimized select from cohort_people --- .../hogql/database/schema/cohort_people.py | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/posthog/hogql/database/schema/cohort_people.py b/posthog/hogql/database/schema/cohort_people.py index 11723f0194619..1b415daf66b68 100644 --- a/posthog/hogql/database/schema/cohort_people.py +++ b/posthog/hogql/database/schema/cohort_people.py @@ -22,17 +22,19 @@ } -def select_from_cohort_people_table(requested_fields: Dict[str, List[str | int]]): +def select_from_cohort_people_table(requested_fields: Dict[str, List[str | int]], team_id: int): from posthog.hogql import ast + from posthog.models import Cohort + + cohort_tuples = list(Cohort.objects.filter(is_static=False, team_id=team_id).values_list("id", "version")) table_name = "raw_cohort_people" - # must always include the person and cohort ids regardless of what other fields are requested - requested_fields = { - "person_id": ["person_id"], - "cohort_id": ["cohort_id"], - **requested_fields, - } + if "person_id" not in requested_fields: + requested_fields = {**requested_fields, "person_id": ["person_id"]} + if "cohort_id" not in requested_fields: + requested_fields = {**requested_fields, "cohort_id": ["cohort_id"]} + fields: List[ast.Expr] = [ ast.Alias(alias=name, expr=ast.Field(chain=[table_name] + chain)) for name, chain in requested_fields.items() ] @@ -40,11 +42,12 @@ def select_from_cohort_people_table(requested_fields: Dict[str, List[str | int]] return ast.SelectQuery( select=fields, select_from=ast.JoinExpr(table=ast.Field(chain=[table_name])), - group_by=[ast.Field(chain=[name]) for name, chain in requested_fields.items()], - having=ast.CompareOperation( - op=ast.CompareOperationOp.Gt, - left=ast.Call(name="sum", args=[ast.Field(chain=[table_name, "sign"])]), - right=ast.Constant(value=0), + where=ast.CompareOperation( + op=ast.CompareOperationOp.In, + left=ast.Tuple( + exprs=[ast.Field(chain=[table_name, "cohort_id"]), ast.Field(chain=[table_name, "version"])] + ), + right=ast.Constant(value=cohort_tuples), ), ) @@ -67,7 +70,7 @@ class CohortPeople(LazyTable): fields: Dict[str, FieldOrTable] = COHORT_PEOPLE_FIELDS def lazy_select(self, requested_fields: Dict[str, List[str | int]], context, node): - return select_from_cohort_people_table(requested_fields) + return select_from_cohort_people_table(requested_fields, context.team_id) def to_printed_clickhouse(self, context): return "cohortpeople" From 5f27776ddaa6a4bc1557b58478280fad9b38feb9 Mon Sep 17 00:00:00 2001 From: Marius Andra Date: Tue, 16 Apr 2024 12:01:30 +0200 Subject: [PATCH 02/14] sign --- .../hogql/database/schema/cohort_people.py | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/posthog/hogql/database/schema/cohort_people.py b/posthog/hogql/database/schema/cohort_people.py index 1b415daf66b68..7ddb2e1d23e35 100644 --- a/posthog/hogql/database/schema/cohort_people.py +++ b/posthog/hogql/database/schema/cohort_people.py @@ -42,12 +42,21 @@ def select_from_cohort_people_table(requested_fields: Dict[str, List[str | int]] return ast.SelectQuery( select=fields, select_from=ast.JoinExpr(table=ast.Field(chain=[table_name])), - where=ast.CompareOperation( - op=ast.CompareOperationOp.In, - left=ast.Tuple( - exprs=[ast.Field(chain=[table_name, "cohort_id"]), ast.Field(chain=[table_name, "version"])] - ), - right=ast.Constant(value=cohort_tuples), + where=ast.And( + exprs=[ + ast.CompareOperation( + op=ast.CompareOperationOp.In, + left=ast.Tuple( + exprs=[ast.Field(chain=[table_name, "cohort_id"]), ast.Field(chain=[table_name, "version"])] + ), + right=ast.Constant(value=cohort_tuples), + ), + ast.CompareOperation( + op=ast.CompareOperationOp.Gt, + left=ast.Field(chain=[table_name, "sign"]), + right=ast.Constant(value=0), + ), + ] ), ) From e850639587b1611ea56d01a44e41e7714eef2a2b Mon Sep 17 00:00:00 2001 From: Marius Andra Date: Tue, 16 Apr 2024 12:07:55 +0200 Subject: [PATCH 03/14] no nulls --- posthog/hogql/database/schema/cohort_people.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/posthog/hogql/database/schema/cohort_people.py b/posthog/hogql/database/schema/cohort_people.py index 7ddb2e1d23e35..deb8c20415e67 100644 --- a/posthog/hogql/database/schema/cohort_people.py +++ b/posthog/hogql/database/schema/cohort_people.py @@ -26,7 +26,11 @@ def select_from_cohort_people_table(requested_fields: Dict[str, List[str | int]] from posthog.hogql import ast from posthog.models import Cohort - cohort_tuples = list(Cohort.objects.filter(is_static=False, team_id=team_id).values_list("id", "version")) + cohort_tuples = list( + Cohort.objects.filter(is_static=False, team_id=team_id) + .exclude(version__isnull=True) + .values_list("id", "version") + ) table_name = "raw_cohort_people" From 8148b1154e0f3ef98fdb910822a0f75a5ec287cb Mon Sep 17 00:00:00 2001 From: Marius Andra Date: Tue, 16 Apr 2024 13:11:53 +0200 Subject: [PATCH 04/14] do distinct --- .../hogql/database/schema/cohort_people.py | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/posthog/hogql/database/schema/cohort_people.py b/posthog/hogql/database/schema/cohort_people.py index deb8c20415e67..f7bade6d3278d 100644 --- a/posthog/hogql/database/schema/cohort_people.py +++ b/posthog/hogql/database/schema/cohort_people.py @@ -45,22 +45,14 @@ def select_from_cohort_people_table(requested_fields: Dict[str, List[str | int]] return ast.SelectQuery( select=fields, + distinct=True, select_from=ast.JoinExpr(table=ast.Field(chain=[table_name])), - where=ast.And( - exprs=[ - ast.CompareOperation( - op=ast.CompareOperationOp.In, - left=ast.Tuple( - exprs=[ast.Field(chain=[table_name, "cohort_id"]), ast.Field(chain=[table_name, "version"])] - ), - right=ast.Constant(value=cohort_tuples), - ), - ast.CompareOperation( - op=ast.CompareOperationOp.Gt, - left=ast.Field(chain=[table_name, "sign"]), - right=ast.Constant(value=0), - ), - ] + where=ast.CompareOperation( + op=ast.CompareOperationOp.In, + left=ast.Tuple( + exprs=[ast.Field(chain=[table_name, "cohort_id"]), ast.Field(chain=[table_name, "version"])] + ), + right=ast.Constant(value=cohort_tuples), ), ) From f1a2f78b608403460e58e95d4f41f83085f674e7 Mon Sep 17 00:00:00 2001 From: Marius Andra Date: Tue, 16 Apr 2024 13:25:45 +0200 Subject: [PATCH 05/14] add test --- .../schema/test/test_cohort_people.py | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 posthog/hogql/database/schema/test/test_cohort_people.py diff --git a/posthog/hogql/database/schema/test/test_cohort_people.py b/posthog/hogql/database/schema/test/test_cohort_people.py new file mode 100644 index 0000000000000..4dce61f10c6f0 --- /dev/null +++ b/posthog/hogql/database/schema/test/test_cohort_people.py @@ -0,0 +1,44 @@ +from posthog.hogql.parser import parse_select +from posthog.hogql.query import execute_hogql_query +from posthog.models import Person, Cohort +from posthog.test.base import ( + APIBaseTest, + ClickhouseTestMixin, +) + + +class TestCohortPeopleTable(ClickhouseTestMixin, APIBaseTest): + def test_select_star(self): + Person.objects.create( + team_id=self.team.pk, + distinct_ids=["1"], + properties={"$some_prop": "something", "$another_prop": "something1"}, + ) + Person.objects.create( + team_id=self.team.pk, + distinct_ids=["2"], + properties={"$some_prop": "something", "$another_prop": "something2"}, + ) + cohort1 = Cohort.objects.create( + team=self.team, + groups=[ + { + "properties": [ + {"key": "$some_prop", "value": "something", "type": "person"}, + ] + } + ], + name="cohort1", + ) + cohort1.calculate_people_ch(pending_version=0) + + response = execute_hogql_query( + parse_select( + "select *, person.properties.$another_prop from cohort_people order by person.properties.$another_prop" + ), + self.team, + ) + assert response.columns == ["person_id", "cohort_id", "$another_prop"] + assert len(response.results) == 2 + assert response.results[0][2] == "something1" + assert response.results[1][2] == "something2" From 6cc97e16556f20d279dec04e77913ce64753f418 Mon Sep 17 00:00:00 2001 From: Marius Andra Date: Tue, 16 Apr 2024 13:29:01 +0200 Subject: [PATCH 06/14] no data if no cohorts --- posthog/hogql/database/schema/cohort_people.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/posthog/hogql/database/schema/cohort_people.py b/posthog/hogql/database/schema/cohort_people.py index f7bade6d3278d..f98b522672602 100644 --- a/posthog/hogql/database/schema/cohort_people.py +++ b/posthog/hogql/database/schema/cohort_people.py @@ -53,7 +53,9 @@ def select_from_cohort_people_table(requested_fields: Dict[str, List[str | int]] exprs=[ast.Field(chain=[table_name, "cohort_id"]), ast.Field(chain=[table_name, "version"])] ), right=ast.Constant(value=cohort_tuples), - ), + ) + if len(cohort_tuples) > 0 + else ast.Constant(value=False), ) From 2eacb570c83235f9cb5e1c20b710bd5792132130 Mon Sep 17 00:00:00 2001 From: Marius Andra Date: Tue, 16 Apr 2024 13:36:56 +0200 Subject: [PATCH 07/14] more --- posthog/hogql/database/schema/test/test_cohort_people.py | 1 + 1 file changed, 1 insertion(+) diff --git a/posthog/hogql/database/schema/test/test_cohort_people.py b/posthog/hogql/database/schema/test/test_cohort_people.py index 4dce61f10c6f0..39fff6f89556f 100644 --- a/posthog/hogql/database/schema/test/test_cohort_people.py +++ b/posthog/hogql/database/schema/test/test_cohort_people.py @@ -39,6 +39,7 @@ def test_select_star(self): self.team, ) assert response.columns == ["person_id", "cohort_id", "$another_prop"] + assert response.results is not None assert len(response.results) == 2 assert response.results[0][2] == "something1" assert response.results[1][2] == "something2" From ac193e1dfec537fd9e3ebff93127da5a87ac0282 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 16 Apr 2024 11:51:34 +0000 Subject: [PATCH 08/14] Update query snapshots --- .../test/__snapshots__/test_in_cohort.ambr | 8 ++++---- .../test/__snapshots__/test_lazy_tables.ambr | 12 ++++-------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/posthog/hogql/transforms/test/__snapshots__/test_in_cohort.ambr b/posthog/hogql/transforms/test/__snapshots__/test_in_cohort.ambr index e0f5ea847110d..9ff7f8ee0ab49 100644 --- a/posthog/hogql/transforms/test/__snapshots__/test_in_cohort.ambr +++ b/posthog/hogql/transforms/test/__snapshots__/test_in_cohort.ambr @@ -31,7 +31,7 @@ FROM events LEFT JOIN ( SELECT person_static_cohort.person_id AS cohort_person_id, 1 AS matched, person_static_cohort.cohort_id AS cohort_id FROM person_static_cohort - WHERE and(equals(person_static_cohort.team_id, 420), in(person_static_cohort.cohort_id, [11]))) AS __in_cohort ON equals(__in_cohort.cohort_person_id, events.person_id) + WHERE and(equals(person_static_cohort.team_id, 420), in(person_static_cohort.cohort_id, [12]))) AS __in_cohort ON equals(__in_cohort.cohort_person_id, events.person_id) WHERE and(equals(events.team_id, 420), 1, ifNull(equals(__in_cohort.matched, 1), 0)) LIMIT 100 SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1 @@ -42,7 +42,7 @@ FROM events LEFT JOIN ( SELECT person_id AS cohort_person_id, 1 AS matched, cohort_id FROM static_cohort_people - WHERE in(cohort_id, [11])) AS __in_cohort ON equals(__in_cohort.cohort_person_id, person_id) + WHERE in(cohort_id, [12])) AS __in_cohort ON equals(__in_cohort.cohort_person_id, person_id) WHERE and(1, equals(__in_cohort.matched, 1)) LIMIT 100 ''' @@ -55,7 +55,7 @@ FROM events LEFT JOIN ( SELECT person_static_cohort.person_id AS cohort_person_id, 1 AS matched, person_static_cohort.cohort_id AS cohort_id FROM person_static_cohort - WHERE and(equals(person_static_cohort.team_id, 420), in(person_static_cohort.cohort_id, [12]))) AS __in_cohort ON equals(__in_cohort.cohort_person_id, events.person_id) + WHERE and(equals(person_static_cohort.team_id, 420), in(person_static_cohort.cohort_id, [13]))) AS __in_cohort ON equals(__in_cohort.cohort_person_id, events.person_id) WHERE and(equals(events.team_id, 420), 1, ifNull(equals(__in_cohort.matched, 1), 0)) LIMIT 100 SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1 @@ -66,7 +66,7 @@ FROM events LEFT JOIN ( SELECT person_id AS cohort_person_id, 1 AS matched, cohort_id FROM static_cohort_people - WHERE in(cohort_id, [12])) AS __in_cohort ON equals(__in_cohort.cohort_person_id, person_id) + WHERE in(cohort_id, [13])) AS __in_cohort ON equals(__in_cohort.cohort_person_id, person_id) WHERE and(1, equals(__in_cohort.matched, 1)) LIMIT 100 ''' diff --git a/posthog/hogql/transforms/test/__snapshots__/test_lazy_tables.ambr b/posthog/hogql/transforms/test/__snapshots__/test_lazy_tables.ambr index ca2923fa1eb85..bd1f0ffd1b241 100644 --- a/posthog/hogql/transforms/test/__snapshots__/test_lazy_tables.ambr +++ b/posthog/hogql/transforms/test/__snapshots__/test_lazy_tables.ambr @@ -4,11 +4,9 @@ SELECT cohort_people__new_person.id AS id FROM ( - SELECT cohortpeople.person_id AS person_id, cohortpeople.cohort_id AS cohort_id, cohortpeople.person_id AS cohort_people___person_id + SELECT DISTINCT cohortpeople.person_id AS cohort_people___person_id, cohortpeople.person_id AS person_id, cohortpeople.cohort_id AS cohort_id FROM cohortpeople - WHERE equals(cohortpeople.team_id, 420) - GROUP BY person_id, cohort_id, cohort_people___person_id - HAVING ifNull(greater(sum(cohortpeople.sign), 0), 0)) AS cohort_people LEFT JOIN ( + WHERE and(equals(cohortpeople.team_id, 420), false)) AS cohort_people LEFT JOIN ( SELECT persons.id AS id, id AS cohort_people__new_person___id FROM ( SELECT person.id AS id @@ -42,11 +40,9 @@ SELECT cohort_people__new_person.id AS id FROM ( - SELECT cohortpeople.person_id AS person_id, cohortpeople.cohort_id AS cohort_id, cohortpeople.person_id AS cohort_people___person_id + SELECT DISTINCT cohortpeople.person_id AS cohort_people___person_id, cohortpeople.person_id AS person_id, cohortpeople.cohort_id AS cohort_id FROM cohortpeople - WHERE equals(cohortpeople.team_id, 420) - GROUP BY person_id, cohort_id, cohort_people___person_id - HAVING ifNull(greater(sum(cohortpeople.sign), 0), 0)) AS cohort_people LEFT JOIN ( + WHERE and(equals(cohortpeople.team_id, 420), false)) AS cohort_people LEFT JOIN ( SELECT persons.id AS id, persons.properties___email AS cohort_people__new_person___properties___email FROM ( SELECT argMax(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, %(hogql_val_0)s), ''), 'null'), '^"|"$', ''), person.version) AS properties___email, person.id AS id From 0a27db3709ffff7af0f2ef24506aa4c082133ece Mon Sep 17 00:00:00 2001 From: Marius Andra Date: Wed, 17 Apr 2024 09:20:46 +0200 Subject: [PATCH 09/14] increase test brutality --- posthog/hogql/database/schema/test/test_cohort_people.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/posthog/hogql/database/schema/test/test_cohort_people.py b/posthog/hogql/database/schema/test/test_cohort_people.py index 39fff6f89556f..0f9c37cbf68ce 100644 --- a/posthog/hogql/database/schema/test/test_cohort_people.py +++ b/posthog/hogql/database/schema/test/test_cohort_people.py @@ -19,6 +19,11 @@ def test_select_star(self): distinct_ids=["2"], properties={"$some_prop": "something", "$another_prop": "something2"}, ) + Person.objects.create( + team_id=self.team.pk, + distinct_ids=["2"], + properties={"$some_prop": "not something", "$another_prop": "something3"}, + ) cohort1 = Cohort.objects.create( team=self.team, groups=[ @@ -31,6 +36,8 @@ def test_select_star(self): name="cohort1", ) cohort1.calculate_people_ch(pending_version=0) + cohort1.calculate_people_ch(pending_version=2) + cohort1.calculate_people_ch(pending_version=4) response = execute_hogql_query( parse_select( From ade9f4b0cae459a271b173501a86f2d5e03e7c07 Mon Sep 17 00:00:00 2001 From: Marius Andra Date: Wed, 17 Apr 2024 09:21:00 +0200 Subject: [PATCH 10/14] use the right term --- frontend/src/scenes/debug/HogQLDebug.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/scenes/debug/HogQLDebug.tsx b/frontend/src/scenes/debug/HogQLDebug.tsx index 3322638e0eda6..781f7b986cfb8 100644 --- a/frontend/src/scenes/debug/HogQLDebug.tsx +++ b/frontend/src/scenes/debug/HogQLDebug.tsx @@ -111,7 +111,7 @@ export function HogQLDebug({ query, setQuery, queryKey }: HogQLDebugProps): JSX. Date: Wed, 17 Apr 2024 09:24:04 +0200 Subject: [PATCH 11/14] null version --- .../schema/test/test_cohort_people.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/posthog/hogql/database/schema/test/test_cohort_people.py b/posthog/hogql/database/schema/test/test_cohort_people.py index 0f9c37cbf68ce..e39b9d5f099e5 100644 --- a/posthog/hogql/database/schema/test/test_cohort_people.py +++ b/posthog/hogql/database/schema/test/test_cohort_people.py @@ -50,3 +50,31 @@ def test_select_star(self): assert len(response.results) == 2 assert response.results[0][2] == "something1" assert response.results[1][2] == "something2" + + def test_empty_version(self): + Person.objects.create( + team_id=self.team.pk, + distinct_ids=["1"], + properties={"$some_prop": "something", "$another_prop": "something1"}, + ) + cohort1 = Cohort.objects.create( + team=self.team, + groups=[ + { + "properties": [ + {"key": "$some_prop", "value": "something", "type": "person"}, + ] + } + ], + name="cohort1", + ) + response = execute_hogql_query( + parse_select( + "select *, person.properties.$another_prop from cohort_people order by person.properties.$another_prop" + ), + self.team, + ) + # never calculated, version empty + assert response.columns == ["person_id", "cohort_id", "$another_prop"] + assert len(response.results) == 0 + assert cohort1.version is None From ad02d11bc58e5c13eb7214f2d3e381c87861a073 Mon Sep 17 00:00:00 2001 From: Marius Andra Date: Wed, 17 Apr 2024 09:46:19 +0200 Subject: [PATCH 12/14] mypy --- posthog/hogql/database/schema/test/test_cohort_people.py | 1 + 1 file changed, 1 insertion(+) diff --git a/posthog/hogql/database/schema/test/test_cohort_people.py b/posthog/hogql/database/schema/test/test_cohort_people.py index e39b9d5f099e5..cccb38133b287 100644 --- a/posthog/hogql/database/schema/test/test_cohort_people.py +++ b/posthog/hogql/database/schema/test/test_cohort_people.py @@ -76,5 +76,6 @@ def test_empty_version(self): ) # never calculated, version empty assert response.columns == ["person_id", "cohort_id", "$another_prop"] + assert response.results is not None assert len(response.results) == 0 assert cohort1.version is None From 9a6c1b62586dfa77cea2e54332d6b589a9447551 Mon Sep 17 00:00:00 2001 From: Marius Andra Date: Wed, 17 Apr 2024 10:27:06 +0200 Subject: [PATCH 13/14] fix --- posthog/hogql/database/schema/test/test_cohort_people.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/posthog/hogql/database/schema/test/test_cohort_people.py b/posthog/hogql/database/schema/test/test_cohort_people.py index cccb38133b287..ea9edd0b97a25 100644 --- a/posthog/hogql/database/schema/test/test_cohort_people.py +++ b/posthog/hogql/database/schema/test/test_cohort_people.py @@ -21,7 +21,7 @@ def test_select_star(self): ) Person.objects.create( team_id=self.team.pk, - distinct_ids=["2"], + distinct_ids=["3"], properties={"$some_prop": "not something", "$another_prop": "something3"}, ) cohort1 = Cohort.objects.create( From d679566ade595f5b41374e373c151809e3e0ffe2 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 17 Apr 2024 08:47:09 +0000 Subject: [PATCH 14/14] Update query snapshots --- .../transforms/test/__snapshots__/test_in_cohort.ambr | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/posthog/hogql/transforms/test/__snapshots__/test_in_cohort.ambr b/posthog/hogql/transforms/test/__snapshots__/test_in_cohort.ambr index 9ff7f8ee0ab49..66816083348f0 100644 --- a/posthog/hogql/transforms/test/__snapshots__/test_in_cohort.ambr +++ b/posthog/hogql/transforms/test/__snapshots__/test_in_cohort.ambr @@ -31,7 +31,7 @@ FROM events LEFT JOIN ( SELECT person_static_cohort.person_id AS cohort_person_id, 1 AS matched, person_static_cohort.cohort_id AS cohort_id FROM person_static_cohort - WHERE and(equals(person_static_cohort.team_id, 420), in(person_static_cohort.cohort_id, [12]))) AS __in_cohort ON equals(__in_cohort.cohort_person_id, events.person_id) + WHERE and(equals(person_static_cohort.team_id, 420), in(person_static_cohort.cohort_id, [13]))) AS __in_cohort ON equals(__in_cohort.cohort_person_id, events.person_id) WHERE and(equals(events.team_id, 420), 1, ifNull(equals(__in_cohort.matched, 1), 0)) LIMIT 100 SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1 @@ -42,7 +42,7 @@ FROM events LEFT JOIN ( SELECT person_id AS cohort_person_id, 1 AS matched, cohort_id FROM static_cohort_people - WHERE in(cohort_id, [12])) AS __in_cohort ON equals(__in_cohort.cohort_person_id, person_id) + WHERE in(cohort_id, [13])) AS __in_cohort ON equals(__in_cohort.cohort_person_id, person_id) WHERE and(1, equals(__in_cohort.matched, 1)) LIMIT 100 ''' @@ -55,7 +55,7 @@ FROM events LEFT JOIN ( SELECT person_static_cohort.person_id AS cohort_person_id, 1 AS matched, person_static_cohort.cohort_id AS cohort_id FROM person_static_cohort - WHERE and(equals(person_static_cohort.team_id, 420), in(person_static_cohort.cohort_id, [13]))) AS __in_cohort ON equals(__in_cohort.cohort_person_id, events.person_id) + WHERE and(equals(person_static_cohort.team_id, 420), in(person_static_cohort.cohort_id, [14]))) AS __in_cohort ON equals(__in_cohort.cohort_person_id, events.person_id) WHERE and(equals(events.team_id, 420), 1, ifNull(equals(__in_cohort.matched, 1), 0)) LIMIT 100 SETTINGS readonly=2, max_execution_time=60, allow_experimental_object_type=1 @@ -66,7 +66,7 @@ FROM events LEFT JOIN ( SELECT person_id AS cohort_person_id, 1 AS matched, cohort_id FROM static_cohort_people - WHERE in(cohort_id, [13])) AS __in_cohort ON equals(__in_cohort.cohort_person_id, person_id) + WHERE in(cohort_id, [14])) AS __in_cohort ON equals(__in_cohort.cohort_person_id, person_id) WHERE and(1, equals(__in_cohort.matched, 1)) LIMIT 100 '''