:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(insights): speed up the earliest-event lookup for "All time" (#101993)
Sandy Spicer5caf339ee804
diff --git a/posthog/clickhouse/query_tagging.py b/posthog/clickhouse/query_tagging.pyindex 65a94eee9c44..ad05bd9b2454 100644--- a/posthog/clickhouse/query_tagging.py+++ b/posthog/clickhouse/query_tagging.py@@ -418,6 +418,7 @@ class QueryTags(BaseModel):workload: Optional[str] = None # enum connection.Workloaddashboard_id: Optional[int] = Noneinsight_id: Optional[int] = None+ lookup: Optional[str] = None # a runner's internal lookup before its real query, e.g. "earliest_timestamp"scanner_id: Optional[str] = None # replay-vision scanner, for per-scanner read meteringexported_asset_id: Optional[int] = Noneexport_format: Optional[str] = Nonediff --git a/posthog/hogql/context.py b/posthog/hogql/context.pyindex 71941a2a518a..112e53faabac 100644--- a/posthog/hogql/context.py+++ b/posthog/hogql/context.py@@ -166,6 +166,10 @@ class HogQLContext:# HogQLQueryModifier, so a query can't disable enforcement.apply_events_retention_floor: bool = True+ # Backend-only opt-in for transforms/events_read_in_order.py. The prefix is slower when the range is short or+ # the filter is selective, so set it only for a query shape that was measured to be faster with it.+ order_events_reads_by_sort_key: bool = False+# Entitlement-derived floors for federated tables that declare a `retention_field`, keyed by# Postgres table name so two such tables can never share one window. Resolved lazily by the# ClickHouse printer the first time each table is printed, so a query that reads none of themdiff --git a/posthog/hogql/printer/test/test_printer.py b/posthog/hogql/printer/test/test_printer.pyindex 5b476ce65d0c..3b8af8b9d755 100644--- a/posthog/hogql/printer/test/test_printer.py+++ b/posthog/hogql/printer/test/test_printer.py@@ -2548,6 +2548,66 @@ class TestPrinter(BaseTest):),)+ @parameterized.expand(+ [+ (+ "utc",+ "UTC",+ True,+ "SELECT event FROM events ORDER BY timestamp DESC LIMIT 10",+ "ORDER BY toDate(events.timestamp) DESC, toTimeZone(events.timestamp, %(hogql_val_0)s) DESC LIMIT 10",+ ),+ (+ "non_utc",+ "US/Pacific",+ True,+ "SELECT event FROM events ORDER BY timestamp DESC LIMIT 10",+ "ORDER BY toDate(events.timestamp) DESC, toTimeZone(events.timestamp, %(hogql_val_0)s) DESC LIMIT 10",+ ),+ (+ "table_alias",+ "UTC",+ True,+ "SELECT e.event FROM events AS e ORDER BY e.timestamp ASC LIMIT 10",+ "ORDER BY toDate(e.timestamp) ASC, toTimeZone(e.timestamp, %(hogql_val_0)s) ASC LIMIT 10",+ ),+ (+ "subquery_with_its_own_limit",+ "UTC",+ True,+ "SELECT event FROM (SELECT event FROM events ORDER BY timestamp DESC LIMIT 10)",+ "ORDER BY toDate(events.timestamp) DESC, toTimeZone(events.timestamp, %(hogql_val_0)s) DESC LIMIT 10)",+ ),+ (+ "cte_with_its_own_limit",+ "UTC",+ True,+ "WITH recent AS (SELECT event FROM events ORDER BY timestamp DESC LIMIT 10) SELECT event FROM recent",+ "ORDER BY toDate(events.timestamp) DESC, toTimeZone(events.timestamp, %(hogql_val_0)s) DESC LIMIT 10)",+ ),+ (+ "off_by_default",+ "UTC",+ False,+ "SELECT event FROM events ORDER BY timestamp DESC LIMIT 10",+ "ORDER BY toTimeZone(events.timestamp, %(hogql_val_0)s) DESC LIMIT 10",+ ),+ ]+ )+ def test_order_by_events_timestamp_reads_in_sort_key_order(+ self, _name: str, timezone: str, opted_in: bool, query: str, expected_order_by: str+ ):+ self.team.timezone = timezone+ self.team.save()+ context = HogQLContext(team_id=self.team.pk, enable_select_queries=True)+ if opted_in:+ context.order_events_reads_by_sort_key = True++ printed = self._select(query, context)++ self.assertIn(expected_order_by, printed)+ self.assertEqual(context.values["hogql_val_0"], timezone)+@parameterized.expand([[diff --git a/posthog/hogql/printer/utils.py b/posthog/hogql/printer/utils.pyindex 539fce0bbad9..e839a94ba2a3 100644--- a/posthog/hogql/printer/utils.py+++ b/posthog/hogql/printer/utils.py@@ -30,6 +30,7 @@ from posthog.hogql.printer.redshift import RedshiftPrinterfrom posthog.hogql.printer.snowflake import SnowflakePrinterfrom posthog.hogql.resolver import ResolverFactory, resolve_typesfrom posthog.hogql.transforms.events_predicate_pushdown import apply_events_predicate_pushdown, events_pushdown_enabled+from posthog.hogql.transforms.events_read_in_order import order_events_reads_by_sort_keyfrom posthog.hogql.transforms.in_cohort import resolve_in_cohorts, resolve_in_cohorts_conjoinedfrom posthog.hogql.transforms.json_property_pushdown import (has_rewritable_json_extract,@@ -412,6 +413,11 @@ def prepare_ast_for_printing(node = clickhouse_property_resolution(node, context)+ if context.order_events_reads_by_sort_key:+ # After property resolution, so the timestamp column is already wrapped and every table type is final.+ with context.timings.measure("events_read_in_order"):+ node = order_events_reads_by_sort_key(node)+# We support global query settings, and local subquery settings.# If the global query is a select query with settings, merge the two.if isinstance(node, ast.SelectQuery) and node.settings is not None and settings is not None:diff --git a/posthog/hogql/transforms/events_read_in_order.py b/posthog/hogql/transforms/events_read_in_order.pynew file mode 100644index 000000000000..6c6beaec35ef--- /dev/null+++ b/posthog/hogql/transforms/events_read_in_order.py@@ -0,0 +1,83 @@+"""Prefix an events ``ORDER BY timestamp`` with ``toDate(timestamp)`` so ClickHouse reads the table in sort-key order.++The events table is sorted by ``(team_id, toDate(timestamp), event, ...)``. ClickHouse reads a table in that order+and stops at the LIMIT only when the ORDER BY prefix matches the sort key syntactically or through a monotonic+function it knows. HogQL prints every events timestamp as ``toTimeZone(events.timestamp, tz)``, which ClickHouse+does not see through, so ``ORDER BY timestamp LIMIT n`` reads and sorts every matching row, even for a UTC team.++``toDate`` is monotonic in the instant, so ``ORDER BY toDate(ts) X, ts X`` is the same total order as+``ORDER BY ts X`` for either direction and the prefix changes no result. Index pruning already sees through the+wrapper, so the WHERE side needs nothing.++The transform runs only when ``HogQLContext.order_events_reads_by_sort_key`` is set. The sort key continues with+``event`` after the date, so the rows of one day are not in timestamp order, and ClickHouse must read and sort a+whole day before it returns the first row. That costs more than a parallel read when the range is short or the+filter is selective.+"""++from posthog.hogql import ast+from posthog.hogql.base import _T_AST+from posthog.hogql.database.schema.events import EventsTable+from posthog.hogql.visitor import TraversingVisitor, clone_expr+++def order_events_reads_by_sort_key(node: _T_AST) -> _T_AST:+ """Add the sort-key prefix to every eligible select in the tree. Mutates in place and returns the node."""+ _EventsReadInOrderTransform().visit(node)+ return node+++class _EventsReadInOrderTransform(TraversingVisitor):+ def visit_select_query(self, node: ast.SelectQuery) -> None:+ super().visit_select_query(node)++ if node.limit is None or not node.order_by:+ return++ first_key = node.order_by[0]+ timestamp_field = _events_timestamp_field(first_key)+ if timestamp_field is None:+ return++ # `_toDate` prints as `toDate` unconditionally. The public `toDate` maps to `toDateOrNull` unless the+ # printer can type its argument, and the sort key match needs the exact function name.+ prefix = ast.OrderExpr(+ expr=ast.Call(name="_toDate", args=[clone_expr(timestamp_field, clear_types=False)]),+ order=first_key.order,+ )+ node.order_by.insert(0, prefix)+++def _events_timestamp_field(order_expr: ast.OrderExpr) -> ast.Field | None:+ """The physical ``events.timestamp`` field an ORDER BY key sorts by, or None when the key is anything else.++ Running the transform twice is a no-op: after the rewrite the first key is the ``toDate`` call, not a field.+ """+ # WITH FILL fabricates rows along the first key, so a new first key would change which rows get filled.+ if order_expr.with_fill is not None:+ return None++ # The property-type pass has already wrapped the column in toTimeZone, and a select alias can wrap it again.+ expr = order_expr.expr+ while isinstance(expr, ast.Alias):+ expr = expr.expr+ if isinstance(expr, ast.Call) and expr.name == "toTimeZone" and expr.args:+ expr = expr.args[0]+ while isinstance(expr, ast.Alias):+ expr = expr.expr++ if not isinstance(expr, ast.Field) or not _is_events_timestamp_type(expr.type):+ return None+ return expr+++def _is_events_timestamp_type(type_: ast.Type | None) -> bool:+ # A computed select alias named `timestamp` resolves to its expression's type, not to the events FieldType.+ while isinstance(type_, ast.FieldAliasType):+ type_ = type_.type+ if not isinstance(type_, ast.FieldType) or type_.name != "timestamp":+ return False+ table_type = type_.table_type+ while isinstance(table_type, ast.TableAliasType):+ table_type = table_type.table_type+ return isinstance(table_type, ast.TableType) and isinstance(table_type.table, EventsTable)diff --git a/posthog/hogql/transforms/test/test_events_read_in_order.py b/posthog/hogql/transforms/test/test_events_read_in_order.pynew file mode 100644index 000000000000..8deabfed7519--- /dev/null+++ b/posthog/hogql/transforms/test/test_events_read_in_order.py@@ -0,0 +1,70 @@+from typing import cast++from posthog.test.base import BaseTest++from parameterized import parameterized++from posthog.hogql import ast+from posthog.hogql.context import HogQLContext+from posthog.hogql.database.database import Database+from posthog.hogql.parser import parse_select+from posthog.hogql.resolver import resolve_types+from posthog.hogql.transforms.events_read_in_order import order_events_reads_by_sort_key+++class TestEventsReadInOrder(BaseTest):+ def _resolved(self, query: str) -> ast.SelectQuery:+ context = HogQLContext(team_id=self.team.pk, team=self.team, enable_select_queries=True)+ context.database = Database.create_for(context.team_id, modifiers=context.modifiers, team=context.team)+ return cast(ast.SelectQuery, resolve_types(parse_select(query), context, dialect="clickhouse"))++ def test_prefixes_once_with_the_same_direction(self):+ node = self._resolved("SELECT event FROM events ORDER BY timestamp DESC LIMIT 10")+ assert node.order_by is not None+ original_key = node.order_by[0]++ order_events_reads_by_sort_key(node)+ order_events_reads_by_sort_key(node)++ prefix, key = node.order_by+ assert key is original_key+ assert prefix.order == "DESC"+ assert isinstance(prefix.expr, ast.Call)+ assert prefix.expr.name == "_toDate"+ assert isinstance(prefix.expr.args[0], ast.Field)+ assert prefix.expr.args[0].chain == ["timestamp"]++ @parameterized.expand(+ [+ ("no_limit", "SELECT event FROM events ORDER BY timestamp DESC"),+ ("other_first_key", "SELECT event FROM events ORDER BY event, timestamp LIMIT 10"),+ (+ "select_alias_named_timestamp",+ "SELECT toStartOfDay(timestamp) AS timestamp FROM events ORDER BY timestamp LIMIT 10",+ ),+ ("other_table_timestamp_column", "SELECT timestamp FROM heatmaps ORDER BY timestamp DESC LIMIT 10"),+ ("persons_created_at", "SELECT id FROM persons ORDER BY created_at DESC LIMIT 10"),+ ("with_fill", "SELECT event FROM events ORDER BY timestamp WITH FILL LIMIT 10"),+ ]+ )+ def test_leaves_other_order_bys_alone(self, _name: str, query: str):+ node = self._resolved(query)+ assert node.order_by is not None+ keys_before = [id(key) for key in node.order_by]++ order_events_reads_by_sort_key(node)++ assert [id(key) for key in node.order_by] == keys_before++ def test_leaves_window_order_by_alone(self):+ node = self._resolved("SELECT event, row_number() OVER (ORDER BY timestamp DESC) AS n FROM events LIMIT 10")+ window = node.select[1]+ assert isinstance(window, ast.Alias)+ assert isinstance(window.expr, ast.WindowFunction)+ assert window.expr.over_expr is not None+ assert window.expr.over_expr.order_by is not None+ keys_before = [id(key) for key in window.expr.over_expr.order_by]++ order_events_reads_by_sort_key(node)++ assert [id(key) for key in window.expr.over_expr.order_by] == keys_beforediff --git a/posthog/hogql_queries/utils/test/test_timestamp_utils.py b/posthog/hogql_queries/utils/test/test_timestamp_utils.pyindex 67ca9bf4c5a4..6a17c6287b81 100644--- a/posthog/hogql_queries/utils/test/test_timestamp_utils.py+++ b/posthog/hogql_queries/utils/test/test_timestamp_utils.py@@ -13,6 +13,8 @@ from parameterized import parameterizedfrom posthog.schema import ActionsNode, DataWarehouseNode, DateRange, EventsNode, IntervalType+from posthog.hogql.query import execute_hogql_query+from posthog.clickhouse.query_tagging import Feature, Product, get_query_tags, tags_contextfrom posthog.hogql_queries.utils.query_date_range import QueryDateRangefrom posthog.hogql_queries.utils.timestamp_utils import (@@ -391,6 +393,26 @@ class TestTimestampUtils(APIBaseTest, ClickhouseDestroyTablesMixin):assert get_earliest_timestamp_unfiltered(self.team) == earliest_timestamp+ def test_unfiltered_earliest_timestamp_reads_in_sort_key_order(self):+ printed: list[str | None] = []+ lookups: list[str | None] = []++ def run(*args, **kwargs):+ lookups.append(get_query_tags().lookup)+ response = execute_hogql_query(*args, **kwargs)+ printed.append(response.clickhouse)+ return response++ with patch("posthog.hogql_queries.utils.timestamp_utils.execute_hogql_query", side_effect=run):+ get_earliest_timestamp_unfiltered(self.team)++ assert printed[0] is not None+ self.assertRegex(+ printed[0],+ r"ORDER BY\s+toDate\(events\.timestamp\) ASC,\s+toTimeZone\(events\.timestamp, %\(hogql_val_\d+\)s\) ASC\s+LIMIT 1",+ )+ self.assertEqual(lookups, ["earliest_timestamp"])+@parameterized.expand([# Naive inputs are interpreted in the passed (team) timezone, not UTC.@@ -535,6 +557,7 @@ class TestTimestampUtils(APIBaseTest, ClickhouseDestroyTablesMixin):tags = get_query_tags()captured["product"] = tags.productcaptured["feature"] = tags.feature+ captured["lookup"] = tags.lookupresult = MagicMock()result.results = [[datetime.datetime(2020, 1, 1, tzinfo=datetime.UTC)]]return result@@ -548,3 +571,4 @@ class TestTimestampUtils(APIBaseTest, ClickhouseDestroyTablesMixin):self.assertEqual(captured["product"], expected_product)self.assertEqual(captured["feature"], expected_feature)+ self.assertEqual(captured["lookup"], "earliest_timestamp")diff --git a/posthog/hogql_queries/utils/timestamp_utils.py b/posthog/hogql_queries/utils/timestamp_utils.pyindex 73f0e5cad708..0eac1f41a6ed 100644--- a/posthog/hogql_queries/utils/timestamp_utils.py+++ b/posthog/hogql_queries/utils/timestamp_utils.py@@ -23,6 +23,7 @@ from posthog.schema import (from posthog.hogql import astfrom posthog.hogql.ast import SelectQuery+from posthog.hogql.context import HogQLContextfrom posthog.hogql.property import action_to_exprfrom posthog.hogql.query import execute_hogql_query@@ -172,7 +173,8 @@ def _earliest_timestamp_query_tags() -> AbstractContextManager[None]:marketing analytics keep their own attribution."""current = get_query_tags()- overrides: dict[str, Any] = {}+ # The query-scan trigger uses this tag to leave the lookup out of the run it judges.+ overrides: dict[str, Any] = {"lookup": "earliest_timestamp"}if current.product is None:overrides["product"] = Product.PRODUCT_ANALYTICSif current.feature is None:@@ -293,7 +295,12 @@ def get_earliest_timestamp_unfiltered(team: Team) -> datetime:)with _earliest_timestamp_query_tags():- result = execute_hogql_query(query=query, team=team)+ result = execute_hogql_query(+ query=query,+ team=team,+ # The read has no upper bound and no filter, so the first row in sort key order is the answer.+ context=HogQLContext(team_id=team.pk, order_events_reads_by_sort_key=True),+ )if result and len(result.results) > 0 and len(result.results[0]) > 0 and result.results[0][0] is not None:earliest_timestamp = _coerce_to_datetime(result.results[0][0], team.timezone_info)# Only cache real results: a team with no events yet should keep re-checking rather thandiff --git a/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_external_clicks_table.ambr b/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_external_clicks_table.ambrindex bb2f107f39fc..a7f26be6d5f8 100644--- a/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_external_clicks_table.ambr+++ b/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_external_clicks_table.ambr@@ -4,7 +4,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,diff --git a/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_web_overview.ambr b/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_web_overview.ambrindex ef5ac64a7823..56b0e710b17e 100644--- a/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_web_overview.ambr+++ b/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_web_overview.ambr@@ -4,7 +4,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,diff --git a/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_web_stats_table.ambr b/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_web_stats_table.ambrindex 6f7f7e7293cf..e8ab6ebee7a8 100644--- a/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_web_stats_table.ambr+++ b/products/web_analytics/backend/hogql_queries/test/__snapshots__/test_web_stats_table.ambr@@ -4,7 +4,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -157,7 +157,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -267,7 +267,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -377,7 +377,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -487,7 +487,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -587,7 +587,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -687,7 +687,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -787,7 +787,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -887,7 +887,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -1050,7 +1050,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -1613,7 +1613,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -1687,7 +1687,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -1761,7 +1761,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -1835,7 +1835,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -1952,7 +1952,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -2087,7 +2087,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -2164,7 +2164,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -2404,7 +2404,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -2488,7 +2488,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -2728,7 +2728,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -2866,7 +2866,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -3002,7 +3002,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -3138,7 +3138,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -3222,7 +3222,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -3306,7 +3306,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -3390,7 +3390,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -3467,7 +3467,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -3551,7 +3551,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -3629,7 +3629,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -3707,7 +3707,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -3828,7 +3828,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -3891,7 +3891,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -3965,7 +3965,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -4039,7 +4039,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -4113,7 +4113,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -4176,7 +4176,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -4249,7 +4249,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -4322,7 +4322,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -4397,7 +4397,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -4589,7 +4589,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -4661,7 +4661,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -4724,7 +4724,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -4873,7 +4873,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -5042,7 +5042,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -5114,7 +5114,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -5224,7 +5224,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -5287,7 +5287,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -5350,7 +5350,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -5413,7 +5413,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -5477,7 +5477,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -5585,7 +5585,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -5648,7 +5648,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -5711,7 +5711,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -5906,7 +5906,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -6330,7 +6330,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -6436,7 +6436,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -6542,7 +6542,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -6618,7 +6618,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,@@ -6770,7 +6770,7 @@SELECT toTimeZone(events.timestamp, 'UTC') AS timestampFROM eventsWHERE and(equals(events.team_id, 99999), greater(events.timestamp, toDateTime64('2015-01-01 00:00:00.000000', 6, 'UTC')))- ORDER BY toTimeZone(events.timestamp, 'UTC') ASC+ ORDER BY toDate(events.timestamp) ASC, toTimeZone(events.timestamp, 'UTC') ASCLIMIT 1 SETTINGS readonly=2,max_execution_time=60,allow_experimental_object_type=1,