{"record":{"id":"518692a666701b5e","repo":"mlflow/mlflow","slug":"searching-traces-without-a-time-range-constraint-o","errorCode":null,"errorMessage":"Searching traces without a time range constraint on UC table locations can be slow and expensive. Consider adding a `trace.timestamp_ms` filter to your `filter_string` to limit the scan, e.g. filter_string=\"trace.timestamp_ms > '2024-01-01'\".","messagePattern":"Searching traces without a time range constraint on UC table locations can be slow and expensive\\. Consider adding a `trace\\.timestamp_ms` filter to your `filter_string` to limit the scan, e\\.g\\. filter_string=\"trace\\.timestamp_ms > '2024-01-01'\"\\.","errorType":"console","errorClass":"UserWarning","httpStatus":null,"severity":"warning","filePath":"mlflow/tracing/fluent.py","lineNumber":1194,"sourceCode":"                    \" the `return_type='pandas'` option, or set `return_type='list'`.\"\n                ),\n            )\n\n    _validate_list_param(\"locations\", locations, allow_none=True)\n\n    if flush:\n        _flush_pending_async_trace_writes()\n\n    if not experiment_ids and not locations:\n        _logger.debug(\"Searching traces in the current active experiment\")\n        locations = _get_search_locations(locations)\n\n    if (\n        locations\n        and any(\".\" in loc for loc in locations)\n        and (not filter_string or \"trace.timestamp_ms\" not in filter_string.lower())\n    ):\n        warnings.warn(\n            \"Searching traces without a time range constraint on UC table locations can be slow \"\n            \"and expensive. Consider adding a `trace.timestamp_ms` filter to your `filter_string` \"\n            \"to limit the scan, e.g. filter_string=\\\"trace.timestamp_ms > '2024-01-01'\\\".\",\n            category=UserWarning,\n            stacklevel=2,\n        )\n\n    def pagination_wrapper_func(number_to_get, next_page_token):\n        return TracingClient().search_traces(\n            experiment_ids=experiment_ids,\n            run_id=run_id,\n            max_results=number_to_get,\n            filter_string=filter_string,\n            order_by=order_by,\n            page_token=next_page_token,\n            model_id=model_id,\n            include_spans=include_spans,\n            locations=locations,","sourceCodeStart":1176,"sourceCodeEnd":1212,"githubUrl":"https://github.com/mlflow/mlflow/blob/6a27f2decc0b76eb1b54af31849784addb357dbc/mlflow/tracing/fluent.py#L1176-L1212","documentation":"When search_traces targets a Unity Catalog table location (a dotted location like catalog.schema.table), a full scan without a time filter is slow and costly because UC table traces are not indexed the same way experiment-store traces are. MLflow warns at query time when any location contains a '.' and the filter_string lacks a trace.timestamp_ms predicate.","triggerScenarios":"mlflow.search_traces(locations=['catalog.schema.trace_table']) with no filter_string, or with a filter_string that does not mention trace.timestamp_ms.","commonSituations":"Databricks users querying UC-managed trace tables for dashboards or evals over all history; especially painful on large tables where the query bills warehouse compute for a full table scan.","solutions":["Add a time bound to the filter, e.g. filter_string=\"trace.timestamp_ms > '2025-01-01'\"","Narrow the time window as tightly as possible (and combine with other predicates like attributes.status)","If a broad scan is genuinely intended, silence the UserWarning with warnings.filterwarnings(\"ignore\", category=UserWarning)"],"exampleFix":"// before\ntraces = mlflow.search_traces(locations=[\"main.default.traces\"])\n// after\ntraces = mlflow.search_traces(\n    locations=[\"main.default.traces\"],\n    filter_string=\"trace.timestamp_ms > '2025-06-01'\",\n)","handlingStrategy":"validation","validationCode":"import datetime\ndef bounded_trace_filter(filter_string: str | None, lookback_days: int = 30) -> str:\n    if filter_string and \"trace.timestamp_ms\" in filter_string.lower():\n        return filter_string\n    cutoff = datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(days=lookback_days)\n    ts = str(int(cutoff.timestamp() * 1000))\n    base = f\"trace.timestamp_ms > '{ts}'\"\n    return f\"{filter_string} AND {base}\" if filter_string else base","typeGuard":"def is_unbounded_uc_query(locations: list[str], filter_string: str | None) -> bool:\n    return any(\".\" in loc for loc in locations) and (\n        not filter_string or \"trace.timestamp_ms\" not in filter_string.lower()\n    )","tryCatchPattern":null,"preventionTips":["Always include a trace.timestamp_ms predicate when querying UC table locations","Default to a rolling lookback window in dashboards/eval jobs","Test queries against the warehouse with EXPLAIN or a small window before scheduling them"],"tags":["performance","databricks","unity-catalog","tracing"],"backgroundTag":"expensive-unbounded-query","analyzedSha":"6a27f2decc0b76eb1b54af31849784addb357dbc","analyzedAt":"2026-08-29T20:54:51.419Z","schemaVersion":2},"datasetVersion":"2026-08-29T22:17:34.462Z"}