Files
greptimedb/src/query/AGENTS.md
T
dennis zhuang b9aa627180 fix(query): forward scalar subquery filters to region scans (#9738)
* fix(query): forward scalar subquery filters to region scans

Since DataFusion 55, uncorrelated scalar subqueries run in ScalarSubqueryExec
instead of being rewritten into joins, so filters such as
ts = (SELECT ts ... ORDER BY ts DESC LIMIT 1) no longer reach region scans
through a join dynamic filter. MergeScanExec now captures such filters as
remote dynamic filters, keeps them in the parent FilterExec, and replaces the
subquery with its result before querying regions.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* fix(query): check the remote dyn filter budget across pushdown phases

Filters captured in the Pre and Post phases are sent in one request, but each
phase validated the initial registration budget alone. When their sum exceeded
the budget, serialization dropped every registration, including join and TopK
filters. Validate the combined set and keep filters accepted by the other phase.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* fix(query): keep IN-bearing scalar subquery filters at the parent

Oversized remote dyn filter payloads replace IN lists with true. That only
widens a conjunction of bounds, but inside an arbitrary predicate such as
(host IN (...)) = (SELECT flag ...) it can drop rows the parent filter would
keep. Do not forward scalar subquery filters that contain IN lists.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* chore(query): note the IN fallback restriction for scalar subquery filters

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* chore(query): document the scalar subquery dyn filter bridge removal condition

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* test(query): keep only dyn_filters of region scans in the scalar subquery plan case

#9565 added scan diagnostics to EXPLAIN ANALYZE VERBOSE and partition filter
rendering changed; the case only checks the forwarded dyn filter.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

---------

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-10-20 08:03:35 +00:00

2.0 KiB

query — Agent & Contributor Guide

Navigation map for src/query. Repo-wide invariants: .agents/architecture-invariants.md.

query owns SQL/PromQL/log planning, GreptimeDB optimizer rules, DataFusion execution, and distributed query plans. Protocols live in servers; statement side effects live in operator.

Module map

Area Path Entry point
Logical planning src/query/src/planner.rs, src/query/src/parser.rs LogicalPlanner, QueryStatement
Query engine src/query/src/query_engine.rs, src/query/src/query_engine/ Engine traits, factory, state, serialization
DataFusion execution src/query/src/datafusion.rs, src/query/src/datafusion/ Physical planning and execution
Optimizers src/query/src/optimizer.rs, src/query/src/optimizer/ GreptimeDB logical/physical rules
Distributed plans src/query/src/dist_plan.rs, src/query/src/dist_plan/ MergeScan, pruning, merge/sort, remote filters
Remote reads src/query/src/region_query.rs RegionQueryHandler boundary
Query languages src/query/src/promql/, src/query/src/log_query/ PromQL and log planners

Change coupling

  • Optimizer or MergeScan changes usually touch rule ordering, physical planning, serialization, and distributed-plan tests together.
  • User-visible SQL/PromQL/log behavior needs planner coverage and a sqlness case.
  • MergeScanExec sends remote dyn filters captured in every filter pushdown phase in one request; the initial registration budget applies to all of them together (dist_plan/dyn_filter_bridge.rs).
  • RegionQueryHandler changes require the frontend implementation to move with it.
  • DataFusion dependency changes follow the pinned-fork rule in the repo-wide invariants.

Testing

cargo nextest run -p query
cargo sqlness bare -t <case>

Check both standalone and distributed plans when changing src/query/src/dist_plan/.