Query: Optimize schema traversal for non-leading tag IN predicates - #18369
Open
Caideyipi wants to merge 4 commits into
Open
Query: Optimize schema traversal for non-leading tag IN predicates#18369Caideyipi wants to merge 4 commits into
Caideyipi wants to merge 4 commits into
Conversation
Contributor
There was a problem hiding this comment.
its child class do not override the method hasMultiExactMatchTransitions(IFAState state)
Collaborator
Author
There was a problem hiding this comment.
SimpleNFA already overrides this method. PatternDFA intentionally inherits the default false because multi-exact transitions are only constructed by SimpleNFA. The false fallback keeps the existing precise-lookup behavior for FA implementations that do not support multi-exact transitions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Problem
Table-model tag predicates are converted to OR-concatenated precise-filter branches. Both an
INpredicate and its equivalentORexpression therefore produce multiple device patterns.When the predicate is on a non-leading tag and an earlier tag level is not fixed, every expanded pattern traverses the same wildcard prefix independently. With N values, the schema tree prefix is visited N times. Rewriting
INasORdoes not avoid this behavior.Solution
DeviceFilterUtilonly when they differ by a precise value at a non-leading tag behind an unfixed earlier tag level.InFilterattached toExtendedPartialPath.SimpleNFAso the shared wildcard prefix is traversed only once.The comparison intentionally uses a stable 1:1 candidate-count heuristic rather than a wall-clock threshold. An opt-in performance UT confirmed that direct memory-tree child iteration wins the equal-count tie because it avoids one direct child lookup per transition.
Leading-tag predicates and fully fixed prefixes remain as separate precise paths. Branches with null precise values, additional filters on the same tag, or correlated conditions such as
(card = a AND device = x) OR (card = b AND device = y)are not merged.For the motivating case, six values on the second tag are reduced from six schema readers over the same first-tag wildcard subtree to one adaptive reader.
Manual performance UT
SchemaRegionTableDevicePerformanceTestis disabled by default with a JUnit assumption. It compares the legacy N-reader expansion with the merged adaptive reader, verifies identical results, and reports median CPU time, thread allocation, peak-heap delta, and speedup. There are no wall-clock performance assertions.The
valuesproperty accepts a comma-separated sweep, andhit.values=0models the important empty-result case:mvn -pl iotdb-core/datanode \ -Dtest=SchemaRegionTableDevicePerformanceTest \ -Diotdb.schema.non.leading.in.perf.enabled=true \ -Diotdb.schema.non.leading.in.perf.meters=50000 \ -Diotdb.schema.non.leading.in.perf.children.per.meter=8 \ -Diotdb.schema.non.leading.in.perf.values=7,8,9 \ -Diotdb.schema.non.leading.in.perf.hit.values=0 \ -Diotdb.schema.non.leading.in.perf.warmups=2 \ -Diotdb.schema.non.leading.in.perf.iterations=3 \ -Diotdb.schema.non.leading.in.perf.rounds=5 \ testRepresentative local Windows results with 400,000 devices and zero matches:
For the equal-count case, switching from precise lookup to child-key iteration reduced the optimized path from 46.875 ms/op to 31.250 ms/op in the same 50,000-by-8 empty-result workload (about 1.5x faster).
Real-dataset validation
At PR head
a50d9ca, I loaded the two TAG levels relevant to this predicate from a real-world dataset into an in-memory SchemaRegion: 405,421 input rows, 404,060 distinct devices, and 402,032 distinct second-TAG values. The relevant topology had one second-TAG child per first-TAG node.The same schema tree was scanned with the legacy six-reader expansion and the optimized single adaptive reader. Both result-equivalence checks passed. Measurements used 3 warmups, 5 iterations per round, and the median of 7 rounds on Windows 11 with JDK 17.
IN, zero hitsIN, six hitsPeak-heap delta was effectively unchanged at about 331-332 MiB, so no peak-heap improvement is claimed.
Tests
DeviceFilterUtilTest: 10 tests passed, including value-smaller, child-smaller, and equal-count adaptive directionsSchemaPredicateUtilTest: 2 tests passed, covering both expandedINand equivalentORSchemaRegionTableDeviceTest: 20 tests passedSchemaRegionTableDevicePerformanceTest: enabled benchmark passed; disabled mode skips all 4 parameterized instancesThis PR has:
Key changed/added classes
DeviceFilterUtilExtendedPartialPathSimpleNFAAbstractTreeVisitorTraverserDeviceFilterUtilTestSchemaPredicateUtilTestSchemaRegionTableDevicePerformanceTest