feat: show timeseries [order by timseries] clause #17065
+656
−51
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
feat: show timeseries [order by timseries] clause
Support
ORDER BY TIMESERIESinSHOW TIMESERIESand OptimizeOFFSETwith Subtree Measurement StatisticsBrief
This PR introduces ordering support for
SHOW TIMESERIESby measurement name (lexicographical) and optimizes the performance of theOFFSETclause using subtree measurement statistics.Currently,
SHOW TIMESERIESsupports theORDER BY TIMESERIESclause.When the query scope is within a single database,
OFFSET Xno longer requires traversing the first X measurements one by one. Instead, it skips subtrees in the metadata tree based on subtree measurement counts.Example:
DESC: descending orderASC: ascending order (default if not specified)Design & Implementation Details
1. Syntax Extension
SHOW TIMESERIESto supportorderByTimeseriesClause.ShowTimeSeriesStatementto record sorting requirements.2. Logical Plan Construction
SortNodeat the top of the logical plan to enable global ordering across partitions.LIMITandOFFSETare pushed down to the metadata tree traversal stage inLogicalPlanVisitor.3. Limit/Offset Handling in Multi-Partition Queries
OFFSETcannot be pushed down.Instead,
limit' = limit + offsetis used.when
limit = 0(which is treated as unlimited in IoTDB),limit'was incorrectly pushed down, causing unexpected truncation of results.4. Ordered Traversal in Metadata Tree
MTreeBelowSGMemoryImpl, the iteration strategy of child nodes inschemaReaderis overridden under ordering mode.5. Subtree Measurement Count
Implemented subtree measurement statistics (only for in-memory metadata tree):
subtreeMeasurementCounttoIMemMNodeand related classes.subtreeMeasurementCountalong ancestor paths during measurement insertion and deletion.During schemaReader construction,
acceptFullMatchedNodeis overridden to skip subtree traversal whensubtreeMeasurementCount < offset.Tests
Functional Tests
IoTDBShowTimeseriesOrderByTimeseriesITto verify correctness of ordering and offset behavior.Performance Evaluation
Xranges from 0 to 900,000 with a step of 5,000.Impact
SHOW TIMESERIES.OFFSETvalues in single-partition scenarios