Skip to content

Commit

Permalink
perf(Persons): Use optimize_aggregation_in_order for person queries (#…
Browse files Browse the repository at this point in the history
…17817)

* perf(Persons): Use optimize_aggregation_in_order for person queries

* Update query snapshots

* Update query snapshots

* Update query snapshots

* Update query snapshots

* Update query snapshots

* Update query snapshots

* Update query snapshots

* Update query snapshots

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
timgl and github-actions[bot] authored Oct 5, 2023
1 parent 0508730 commit 476d102
Show file tree
Hide file tree
Showing 22 changed files with 184 additions and 169 deletions.
8 changes: 4 additions & 4 deletions ee/clickhouse/models/test/__snapshots__/test_cohort.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
GROUP BY id
HAVING max(is_deleted) = 0
AND ((((has(['something'], replaceRegexpAll(JSONExtractRaw(argMax(person.properties, version), '$some_prop'), '^"|"$', ''))))
AND ((has(['something'], replaceRegexpAll(JSONExtractRaw(argMax(person.properties, version), '$another_prop'), '^"|"$', ''))))))) as person
AND ((has(['something'], replaceRegexpAll(JSONExtractRaw(argMax(person.properties, version), '$another_prop'), '^"|"$', '')))))) SETTINGS optimize_aggregation_in_order = 1) as person
UNION ALL
SELECT person_id,
cohort_id,
Expand Down Expand Up @@ -54,7 +54,7 @@
AND ((has(['something1'], replaceRegexpAll(JSONExtractRaw(properties, '$some_prop'), '^"|"$', '')))) )
GROUP BY id
HAVING max(is_deleted) = 0
AND ((has(['something1'], replaceRegexpAll(JSONExtractRaw(argMax(person.properties, version), '$some_prop'), '^"|"$', ''))))) as person
AND ((has(['something1'], replaceRegexpAll(JSONExtractRaw(argMax(person.properties, version), '$some_prop'), '^"|"$', '')))) SETTINGS optimize_aggregation_in_order = 1) as person
UNION ALL
SELECT person_id,
cohort_id,
Expand Down Expand Up @@ -111,7 +111,7 @@
AND (((((NOT has(['something1'], replaceRegexpAll(JSONExtractRaw(properties, '$some_prop'), '^"|"$', ''))))))) )
GROUP BY id
HAVING max(is_deleted) = 0
AND (((((NOT has(['something1'], replaceRegexpAll(JSONExtractRaw(argMax(person.properties, version), '$some_prop'), '^"|"$', ''))))))))) person ON person.person_id = behavior_query.person_id
AND (((((NOT has(['something1'], replaceRegexpAll(JSONExtractRaw(argMax(person.properties, version), '$some_prop'), '^"|"$', ''))))))) SETTINGS optimize_aggregation_in_order = 1)) person ON person.person_id = behavior_query.person_id
WHERE 1 = 1
AND ((((performed_event_condition_15_level_level_0_level_0_level_0_0)))) ) as person
UNION ALL
Expand Down Expand Up @@ -176,7 +176,7 @@
AND (((((NOT has(['something1'], replaceRegexpAll(JSONExtractRaw(properties, '$some_prop'), '^"|"$', ''))))))) )
GROUP BY id
HAVING max(is_deleted) = 0
AND (((((NOT has(['something1'], replaceRegexpAll(JSONExtractRaw(argMax(person.properties, version), '$some_prop'), '^"|"$', ''))))))))) person ON person.person_id = behavior_query.person_id
AND (((((NOT has(['something1'], replaceRegexpAll(JSONExtractRaw(argMax(person.properties, version), '$some_prop'), '^"|"$', ''))))))) SETTINGS optimize_aggregation_in_order = 1)) person ON person.person_id = behavior_query.person_id
WHERE 1 = 1
AND ((((performed_event_condition_17_level_level_0_level_0_level_0_0)))) ) ))
'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
FROM person
WHERE team_id = 2
GROUP BY id
HAVING max(is_deleted) = 0) person ON person.id = funnel_actors.actor_id) aggregation_target_with_props
HAVING max(is_deleted) = 0 SETTINGS optimize_aggregation_in_order = 1) person ON person.id = funnel_actors.actor_id) aggregation_target_with_props
GROUP BY prop.1,
prop.2
HAVING prop.1 NOT IN []
Expand Down Expand Up @@ -242,7 +242,7 @@
AND (has(['Positive'], replaceRegexpAll(JSONExtractRaw(properties, '$browser'), '^"|"$', ''))) )
GROUP BY id
HAVING max(is_deleted) = 0
AND (has(['Positive'], replaceRegexpAll(JSONExtractRaw(argMax(person.properties, version), '$browser'), '^"|"$', '')))) person ON person.id = pdi.person_id
AND (has(['Positive'], replaceRegexpAll(JSONExtractRaw(argMax(person.properties, version), '$browser'), '^"|"$', ''))) SETTINGS optimize_aggregation_in_order = 1) person ON person.id = pdi.person_id
WHERE team_id = 2
AND event IN ['paid', 'user signed up']
AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC')
Expand Down Expand Up @@ -326,7 +326,7 @@
AND (has(['Positive'], replaceRegexpAll(JSONExtractRaw(properties, '$browser'), '^"|"$', ''))) )
GROUP BY id
HAVING max(is_deleted) = 0
AND (has(['Positive'], replaceRegexpAll(JSONExtractRaw(argMax(person.properties, version), '$browser'), '^"|"$', '')))) person ON person.id = pdi.person_id
AND (has(['Positive'], replaceRegexpAll(JSONExtractRaw(argMax(person.properties, version), '$browser'), '^"|"$', ''))) SETTINGS optimize_aggregation_in_order = 1) person ON person.id = pdi.person_id
WHERE team_id = 2
AND event IN ['paid', 'user signed up']
AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC')
Expand Down Expand Up @@ -410,7 +410,7 @@
AND (has(['Negative'], replaceRegexpAll(JSONExtractRaw(properties, '$browser'), '^"|"$', ''))) )
GROUP BY id
HAVING max(is_deleted) = 0
AND (has(['Negative'], replaceRegexpAll(JSONExtractRaw(argMax(person.properties, version), '$browser'), '^"|"$', '')))) person ON person.id = pdi.person_id
AND (has(['Negative'], replaceRegexpAll(JSONExtractRaw(argMax(person.properties, version), '$browser'), '^"|"$', ''))) SETTINGS optimize_aggregation_in_order = 1) person ON person.id = pdi.person_id
WHERE team_id = 2
AND event IN ['paid', 'user signed up']
AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC')
Expand Down Expand Up @@ -494,7 +494,7 @@
AND (has(['Negative'], replaceRegexpAll(JSONExtractRaw(properties, '$browser'), '^"|"$', ''))) )
GROUP BY id
HAVING max(is_deleted) = 0
AND (has(['Negative'], replaceRegexpAll(JSONExtractRaw(argMax(person.properties, version), '$browser'), '^"|"$', '')))) person ON person.id = pdi.person_id
AND (has(['Negative'], replaceRegexpAll(JSONExtractRaw(argMax(person.properties, version), '$browser'), '^"|"$', ''))) SETTINGS optimize_aggregation_in_order = 1) person ON person.id = pdi.person_id
WHERE team_id = 2
AND event IN ['paid', 'user signed up']
AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC')
Expand Down Expand Up @@ -594,7 +594,7 @@
FROM person
WHERE team_id = 2
GROUP BY id
HAVING max(is_deleted) = 0) person ON person.id = funnel_actors.actor_id) aggregation_target_with_props
HAVING max(is_deleted) = 0 SETTINGS optimize_aggregation_in_order = 1) person ON person.id = funnel_actors.actor_id) aggregation_target_with_props
GROUP BY prop.1,
prop.2
HAVING prop.1 NOT IN []
Expand Down Expand Up @@ -666,7 +666,7 @@
AND (has(['Positive'], "pmat_$browser")) )
GROUP BY id
HAVING max(is_deleted) = 0
AND (has(['Positive'], argMax(person."pmat_$browser", version)))) person ON person.id = pdi.person_id
AND (has(['Positive'], argMax(person."pmat_$browser", version))) SETTINGS optimize_aggregation_in_order = 1) person ON person.id = pdi.person_id
WHERE team_id = 2
AND event IN ['paid', 'user signed up']
AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC')
Expand Down Expand Up @@ -750,7 +750,7 @@
AND (has(['Positive'], "pmat_$browser")) )
GROUP BY id
HAVING max(is_deleted) = 0
AND (has(['Positive'], argMax(person."pmat_$browser", version)))) person ON person.id = pdi.person_id
AND (has(['Positive'], argMax(person."pmat_$browser", version))) SETTINGS optimize_aggregation_in_order = 1) person ON person.id = pdi.person_id
WHERE team_id = 2
AND event IN ['paid', 'user signed up']
AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC')
Expand Down Expand Up @@ -834,7 +834,7 @@
AND (has(['Negative'], "pmat_$browser")) )
GROUP BY id
HAVING max(is_deleted) = 0
AND (has(['Negative'], argMax(person."pmat_$browser", version)))) person ON person.id = pdi.person_id
AND (has(['Negative'], argMax(person."pmat_$browser", version))) SETTINGS optimize_aggregation_in_order = 1) person ON person.id = pdi.person_id
WHERE team_id = 2
AND event IN ['paid', 'user signed up']
AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC')
Expand Down Expand Up @@ -918,7 +918,7 @@
AND (has(['Negative'], "pmat_$browser")) )
GROUP BY id
HAVING max(is_deleted) = 0
AND (has(['Negative'], argMax(person."pmat_$browser", version)))) person ON person.id = pdi.person_id
AND (has(['Negative'], argMax(person."pmat_$browser", version))) SETTINGS optimize_aggregation_in_order = 1) person ON person.id = pdi.person_id
WHERE team_id = 2
AND event IN ['paid', 'user signed up']
AND toTimeZone(timestamp, 'UTC') >= toDateTime('2020-01-01 00:00:00', 'UTC')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@
AND (has(['bar'], replaceRegexpAll(JSONExtractRaw(properties, 'foo'), '^"|"$', ''))) )
GROUP BY id
HAVING max(is_deleted) = 0
AND (has(['bar'], replaceRegexpAll(JSONExtractRaw(argMax(person.properties, version), 'foo'), '^"|"$', '')))) person ON person.id = pdi.person_id
AND (has(['bar'], replaceRegexpAll(JSONExtractRaw(argMax(person.properties, version), 'foo'), '^"|"$', ''))) SETTINGS optimize_aggregation_in_order = 1) person ON person.id = pdi.person_id
WHERE team_id = 2
AND event IN ['$pageview', 'insight analyzed']
AND toTimeZone(timestamp, 'UTC') >= toDateTime('2021-01-01 00:00:00', 'UTC')
Expand Down Expand Up @@ -579,7 +579,7 @@
AND (has(['bar'], replaceRegexpAll(JSONExtractRaw(properties, 'foo'), '^"|"$', ''))) )
GROUP BY id
HAVING max(is_deleted) = 0
AND (has(['bar'], replaceRegexpAll(JSONExtractRaw(argMax(person.properties, version), 'foo'), '^"|"$', '')))) person ON person.id = pdi.person_id
AND (has(['bar'], replaceRegexpAll(JSONExtractRaw(argMax(person.properties, version), 'foo'), '^"|"$', ''))) SETTINGS optimize_aggregation_in_order = 1) person ON person.id = pdi.person_id
WHERE team_id = 2
AND toTimeZone(timestamp, 'UTC') >= toDateTime('2021-01-01 00:00:00', 'UTC')
AND toTimeZone(timestamp, 'UTC') <= toDateTime('2021-01-08 23:59:59', 'UTC')
Expand Down Expand Up @@ -711,7 +711,7 @@
AND (has(['bar'], replaceRegexpAll(JSONExtractRaw(properties, 'foo'), '^"|"$', ''))) )
GROUP BY id
HAVING max(is_deleted) = 0
AND (has(['bar'], replaceRegexpAll(JSONExtractRaw(argMax(person.properties, version), 'foo'), '^"|"$', '')))) person ON person.id = pdi.person_id
AND (has(['bar'], replaceRegexpAll(JSONExtractRaw(argMax(person.properties, version), 'foo'), '^"|"$', ''))) SETTINGS optimize_aggregation_in_order = 1) person ON person.id = pdi.person_id
WHERE team_id = 2
AND toTimeZone(timestamp, 'UTC') >= toDateTime('2021-01-01 00:00:00', 'UTC')
AND toTimeZone(timestamp, 'UTC') <= toDateTime('2021-01-08 23:59:59', 'UTC')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
FROM person
WHERE team_id = 2
GROUP BY id
HAVING max(is_deleted) = 0) person ON pdi.person_id = person.id
HAVING max(is_deleted) = 0 SETTINGS optimize_aggregation_in_order = 1) person ON pdi.person_id = person.id
WHERE team_id = 2
AND event = '$pageview'
AND toTimeZone(timestamp, 'UTC') >= toDateTime('2019-12-21 00:00:00', 'UTC')
Expand Down Expand Up @@ -105,7 +105,7 @@
FROM person
WHERE team_id = 2
GROUP BY id
HAVING max(is_deleted) = 0) person ON pdi.person_id = person.id
HAVING max(is_deleted) = 0 SETTINGS optimize_aggregation_in_order = 1) person ON pdi.person_id = person.id
WHERE team_id = 2
AND event = '$pageview'
AND toTimeZone(timestamp, 'UTC') >= toDateTime('2019-12-21 00:00:00', 'UTC')
Expand Down Expand Up @@ -143,7 +143,7 @@
AND ((replaceRegexpAll(JSONExtractRaw(properties, '$browser'), '^"|"$', '') ILIKE '%test%')) )
GROUP BY id
HAVING max(is_deleted) = 0
AND ((replaceRegexpAll(JSONExtractRaw(argMax(person.properties, version), '$browser'), '^"|"$', '') ILIKE '%test%'))) person ON pdi.person_id = person.id
AND ((replaceRegexpAll(JSONExtractRaw(argMax(person.properties, version), '$browser'), '^"|"$', '') ILIKE '%test%')) SETTINGS optimize_aggregation_in_order = 1) person ON pdi.person_id = person.id
WHERE team_id = 2
AND event = '$pageview'
AND toTimeZone(timestamp, 'UTC') >= toDateTime('2019-12-21 00:00:00', 'UTC')
Expand Down Expand Up @@ -204,7 +204,7 @@
FROM person
WHERE team_id = 2
GROUP BY id
HAVING max(is_deleted) = 0) person ON pdi.person_id = person.id
HAVING max(is_deleted) = 0 SETTINGS optimize_aggregation_in_order = 1) person ON pdi.person_id = person.id
INNER JOIN
(SELECT "$session_id",
dateDiff('second', min(timestamp), max(timestamp)) as session_duration
Expand Down Expand Up @@ -245,7 +245,7 @@
FROM person
WHERE team_id = 2
GROUP BY id
HAVING max(is_deleted) = 0) person ON pdi.person_id = person.id
HAVING max(is_deleted) = 0 SETTINGS optimize_aggregation_in_order = 1) person ON pdi.person_id = person.id
INNER JOIN
(SELECT "$session_id",
dateDiff('second', min(timestamp), max(timestamp)) as session_duration
Expand Down
Loading

0 comments on commit 476d102

Please sign in to comment.