CoollZzz opened a new pull request, #19250:
URL: https://github.com/apache/iotdb/pull/19250

   ## Description
   
   ### Problem
   
   The ordered rate-family accumulators (`Ordered*Accumulator` / 
`GroupedOrdered*Accumulator`) were effectively unreachable. 
`AggregationNode.Aggregation#inputOrderedByTimeAscending` was only derived from 
the child ordering, and for a normal rate query that ordering contains only the 
pre-grouped tag keys (or the `date_bin` window key) — the raw time column never 
appears in it. The flag therefore stayed `false` and every rate query used the 
naive accumulator, which buffers all `(time, value)` samples of each group.
   
   Found while reviewing #19227.
   
   ### Change
   
   Derive the flag from the physical ordering guarantee of the table scan 
instead of the plan's ordering property.
   
   In the non-split branch (`childrenNodes.size() == 1`) of 
`TableDistributedPlanGenerator#visitAggregation`, the input is considered 
per-group time ordered when:
   
   1. the aggregation is `SINGLE`, the scan order is ascending, and only 
order-preserving nodes (projection / filter) sit between the aggregation and a 
plain table scan; and
   2. either only one device is scanned, or the grouping keys cover all tag 
columns of the table, so that each group belongs to at most one device.
   
   The rate function's second argument must also resolve (through projections) 
to the scan's native time column, because it may legally be any 
`INT64`/`TIMESTAMP` column; otherwise the scan's time ordering says nothing 
about the argument's order.
   
   The new condition is OR-ed with the existing ordering-based check, so plans 
with an explicit `ORDER BY time` keep working as before.
   
   ### Scope
   
   - No planning or splitting decision is changed: only the single-child 
(non-split) branch annotates the aggregation.
   - `AccumulatorFactory` still requires `step == SINGLE`, because the ordered 
accumulators do not support intermediate states. PARTIAL/FINAL stages, 
multi-region split aggregations and TUMBLE/HOP (table function processors) keep 
the naive accumulator.
   - Descending scans and order-changing nodes (sort / union / table function 
processor) never enable the flag.
   
   ### Verification
   
   - `RateOrderedInputTest`: single device, grouping by all tags, grouping by a 
tag subset, descending scan, non-`SINGLE` step, projection symbol resolution, 
order-changing child.
   - `RateOrderedPlannerTest`: planner-level checks — a single-device query 
sets the flag; a multi-device query and an `irate(s1, s2)` query (non-time 
second argument) keep it `false`.
   - Runtime check on a 1C1D instance: `SELECT irate(s1, time) FROM t WHERE 
device_id = 'd1'` constructs `OrderedIrateAccumulator`, while the multi-device 
query still constructs `NaiveIrateAccumulator`.
   
   ### Follow-up
   
   - After #19227 is merged, add the integral family to 
`isOrderedInputFunction`.
   - Enabling the ordered accumulators at the PARTIAL stage requires a 
mergeable intermediate state and is a separate change.
   
   <hr>
   
   This PR has:
   - [x] been self-reviewed.
   - [x] added Javadocs for most classes and all non-trivial methods.
   - [x] added comments explaining the "why" and the intent of the code 
wherever would not be obvious for an unfamiliar read
   - [x] added unit tests or modified existing tests to cover new code paths, 
ensuring the threshold for code coverage.
   - [ ] added integration tests.
   - [x] been tested in a test IoTDB cluster.
   
   <hr>
   
   ##### Key changed/added classes (or packages if there are too many classes) 
in this PR
   
   - 
`org.apache.iotdb.db.queryengine.plan.relational.planner.distribute.TableDistributedPlanGenerator`
   - 
`org.apache.iotdb.db.queryengine.plan.relational.planner.distribute.RateOrderedInputTest`
 (new)
   - 
`org.apache.iotdb.db.queryengine.plan.relational.planner.distribute.RateOrderedPlannerTest`
 (new)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to