Skip to content

perf(parser): elide redundant static edge type filters - #2559

Draft
linhongyu510 wants to merge 2 commits into
apache:masterfrom
linhongyu510:perf/elide-redundant-edge-type-filter-2481
Draft

perf(parser): elide redundant static edge type filters#2559
linhongyu510 wants to merge 2 commits into
apache:masterfrom
linhongyu510:perf/elide-redundant-edge-type-filter-2481

Conversation

@linhongyu510

Copy link
Copy Markdown

Summary

  • remove type(r) = "<label>" when the same fixed-length relationship variable is already constrained by MATCH ... [r:<label>]
  • preserve all non-redundant predicates and avoid mutating the original OPTIONAL MATCH WHERE tree
  • add positive, negative, conjunction, disjunction, optional-match, variable-length, and variable-reuse regression coverage

Correctness boundary

The rewrite is intentionally conservative. It only handles a direct equality whose left side is type(<single relationship variable>) and whose right side is the exact static relationship label. It does not rewrite OR expressions, unlabeled relationships, variable-length relationships, mismatched labels, or ambiguous repeated bindings.

Verification

  • RED on current master: the EXPLAIN regression failed because the P relationship scan still contained _label_name(...) = "P"
  • PostgreSQL 18.6 targeted regression: expr, cypher_match, and cypher_vle passed
  • PostgreSQL 18.6 full regression suite: 42/42 passed
  • build completed with GCC and LLVM bitcode generation

Benchmark

20,000 (:X)-[:P]->(:Y) relationships, 12 alternating query pairs in an isolated PostgreSQL 18.6 container:

Revision Plain typed MATCH median Redundant type(r) median Ratio
current master 2.854 ms 4.622 ms 1.620x
this PR 2.936 ms 2.925 ms 0.996x

All 24 measured queries returned 20000. This demonstrates removal of the redundant runtime filter in this environment; it does not claim universal absolute latency.

Closes #2481

Implementation and verification were AI-assisted. I reviewed the AST constraints, final diff, regression output, and benchmark results before submission.

Add an EXPLAIN regression that expects a statically typed relationship predicate to produce the same filter-free plan as the equivalent MATCH without the redundant type check.\n\nRefs apache#2481
Preserve non-redundant predicates and avoid mutating the original OPTIONAL MATCH WHERE tree.

Refs apache#2481
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A redundant type(r) = 'P' check makes a statically typed relationship query about 6x slower

1 participant