# This test checks the query plans from the sql stats virtual tables
# do not contain a full scan when used with query filters.


# Verify that querying by aggregated_ts uses the appropriate spans.
observe-sql
EXPLAIN
SELECT
  *
FROM
  crdb_internal.transaction_statistics
WHERE
  aggregated_ts >= '2022-01-18' AND
  aggregated_ts <= '2022-01-20'
----
----
distribution: local
vectorized: true

• group (hash)
│ group by: aggregated_ts, fingerprint_id, app_name, aggregation_interval
│
└── • union all
    │
    ├── • filter
    │   │ filter: (aggregated_ts >= '2022-01-18 00:00:00+00') AND (aggregated_ts <= '2022-01-20 00:00:00+00')
    │   │
    │   └── • virtual table
    │         table: cluster_transaction_statistics@primary
    │
    └── • scan
          missing stats
          table: transaction_statistics@primary
          spans: [/0/'2022-01-18 00:00:00+00' - /0/'2022-01-20 00:00:00+00'] [/1/'2022-01-18 00:00:00+00' - /1/'2022-01-20 00:00:00+00'] [/2/'2022-01-18 00:00:00+00' - /2/'2022-01-20 00:00:00+00'] [/3/'2022-01-18 00:00:00+00' - /3/'2022-01-20 00:00:00+00'] … (4 more)
----
----
