Skip to content

Limit path flatten max length - #4258

Open
rvesse wants to merge 1 commit into
apache:mainfrom
rvesse:path-flatten-limit
Open

rvesse wants to merge 1 commit into
apache:mainfrom
rvesse:path-flatten-limit

Conversation

@rvesse

@rvesse rvesse commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

When TransformPathFlattern/TransformPathFlattenAlgebra run they expand some paths of the form :x :p{N,M} ?y into multiple triple patterns within a BGP e.g. :x :p ?q0 . ?q0 :p ?y etc. This is safe for short values of M but can result in extremely large expansions if M is a large value. The large expansion is unlikely to make the query run any faster. This commit introduces a new static control for the maximum expansion length capped at 10 and does not apply full expansion to anything longer than that.


  • Tests are included.
  • Documentation change and updates are provided for the Apache Jena website
  • Commits have been squashed to remove intermediate development commit messages.
  • Key commit messages start with the issue number (GH-xxxx)

By submitting this pull request, I acknowledge that I am making a contribution to the Apache Software Foundation under the terms and conditions of the Contributor's Agreement.


See the Apache Jena "Contributing" guide.

When TransformPathFlatten/TransformPathFlattenAlgebra run they expand
some paths of the form :x :p{N,M} ?y into multiple triple patterns
within a BGP e.g. :x :p ?q0 . ?q0 :p ?y etc.  This is safe for short
values of M but can result in extremely large expansions if M is a large
value.  The large expansion is unlikely to make the query run any faster
and a sufficiently large value can cause the query optimiser to fail with
memory/stack issues.  This commit introduces a new static control for
the maximum expansion length capped at 10 and does not apply full
expansion to anything longer than that.
@rvesse rvesse self-assigned this Sep 25, 2026
@rvesse rvesse added performance Performance ARQ labels Sep 25, 2026
@afs

afs commented Sep 26, 2026 •

Copy link
Copy Markdown
Member

I agree with the intent.

just checking here but I think you mean N, not M.
:p{N,M}, it splits into :p{N} / :p{0,M-N} ((pathN N :p) and (mod 0 M-N :p)).
and the first part pathN is written triple patterns.

Unless there is evidence to the contrary, maybe the limit (<10) should be lower - e.g. 5.

@rvesse

rvesse commented Sep 28, 2026

Copy link
Copy Markdown
Member Author

I agree with the intent.

just checking here but I think you mean N, not M. :p{N,M}, it splits into :p{N} / :p{0,M-N} ((pathN N :p) and (mod 0 M-N :p)). and the first part pathN is written triple patterns.

Yes sorry, got the terminology confused

Unless there is evidence to the contrary, maybe the limit (<10) should be lower - e.g. 5.

Yeah I think that's probably sensible, can adjust the PR accordingly

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants