Skip to content

Trigger routes bind every readable Dag and fail past the Postgres parameter limit #76959

Open

Description

@seanghaeli

PermittedTriggerFilter.to_orm (airflow-core/src/airflow/api_fastapi/core_api/security.py, from #76260) narrows trigger queries in SQL with Trigger.dag_id IN (readable Dags) for task triggers and again for callback triggers, plus IN (readable assets) for watchers. So every GET /api/v2/triggers query, both the count and the page, carries about two bind parameters per readable Dag, and GET /api/v2/triggers/{trigger_id} runs the same filter to read one row. The Triggers page, the trigger page and the dashboard card call these on every auto-refresh.

The cost grows with the size of the deployment, not with the number of triggers. For a caller who can read every Dag, on Postgres with the simple auth manager, the list request took about 200 ms at 2,000 Dags and 1.25 s at 10,000 (about 50,000 bind parameters). At 50,000 Dags it fails with a 500, because psycopg 3 refuses a statement with more than 65,535 parameters (number of parameters must be between 0 and 65535). A caller who reads 25,000 of the 50,000 Dags hits the same limit.

Suggestion: keep the other filters and the sort in SQL, read only the matching triggers' ids and what each is used by, check the readable Dags and assets in Python, then load only the requested page by id. For the single trigger, load the row by id and check it in Python. That keeps the totals and ordering exact and the parameter count fixed: in the same setup the list took 70 ms at 2,000 Dags and 470 ms at 10,000, and both routes answered at 50,000.

  • GET /triggers: check readable Dags and assets in Python, page by id, with a test that totals and order match the SQL filter
  • GET /triggers/{trigger_id}: load by id and check permission in Python

Activity

  1. adiranjan25 commented on Nov 12, 2026

    @adiranjan25
    Contributor

    Hi @seanghaeli,

    I'd be interested in working on this issue.

    The scalability problem with large SQL IN parameter lists is closely aligned with my background in database query optimization, distributed data platforms, and performance engineering.

    I'd like to investigate a solution that eliminates the DAG-count-dependent bind parameters while preserving authorization semantics, accurate totals, stable pagination, and existing sorting behavior.

    My proposed validation would include regression tests for task, callback, and asset-watcher triggers; restricted user visibility; and performance testing against larger synthetic DAG populations.

    Before implementation, I'll review the current route and authorization logic to ensure the approach remains compatible with existing Airflow behavior.

    Please let me know if there are any additional constraints or an implementation already underway.

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions