Repository navigation
Page by subject whatever a path's declared maxCount; IRI tie-break on every page - #417
Merged
Merged
Conversation
…I on every page A row LIMIT counted a subject twice when the data held two values of a maxCount-1 path (a label in two languages), so a page held fewer subjects than asked. Paged selects now use the sub-SELECT of subjects whenever a row carries any value besides its subject; a select of subjects only keeps its plain LIMIT. An offset without an orderBy pages in subject order.
A GROUP BY reads every subject before the LIMIT; a DISTINCT streams. The page keeps GROUP BY only for a MIN/MAX sort key or a HAVING.
Merged
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.
What changed
limit/offset(and.one()) are documented to page over root subjects, with ties broken by the subject IRI. Two cases broke that contract:maxCount: 1path that holds several values in the data (e.g.rdfs:labelin several languages). Paging trusted the declaredmaxCount, so it used a plain rowLIMIT. Each extra value became an extra row, so a page held fewer subjects than asked and could repeat a subject across pages.LIMITpath ordered only by the select's keys, with no IRI tie-break. Subjects with equal or missing sort values had no stable order across pages.The fix is in
src/sparql/irToAlgebra.ts:pageBySubject) whenever a row carries any value besides its subject: a traversal, or a path in the projection or the order. This holds whatever the path's declaredmaxCount(newreadsPathPerRow). A select of subjects only (Person.select().where(...)) keeps its plainLIMIT, because there a row is a subject.ASC(?subject)tie-break. Anoffsetwithout anorderBynow pages in subject order, on both paths..for(id)still reads without aLIMIT.Example:
Person.select((p) => p.name).minus(Employee).orderBy((p) => p.name).limit(7)Before:
After:
MINUS and
wherefilters were already applied before the LIMIT on both paths; that part is unchanged.Tests
src/tests/select-paging-data-beyond-shape.test.ts. Unit SPARQL tests cover the sub-SELECT for single-valued projections, traversals and.one(), plus the IRI tie-break, MINUS inside the page, and offset without an order. Live Fuseki tests use a subject with two values of amaxCount: 1path, three subjects tied on the sort key, two without it, and an excluded subject.Tests: 8 failed, 3 passed, 11 total. The live failures were a subject counted twice (+ "a1") and a page missing a subject (- "a3").LIMITfor single-valued selects (select-subject-paging,sparql-select-goldenselectOne/outerWhereLimit,sparql-algebraouterWhereLimit).SELECT DISTINCTwith no GROUP BY; an order on the subject itself → no GROUP BY.FUSEKI_BASE_URL=http://localhost:3961 FUSEKI_ADMIN_PASSWORD=admin npm test, afternpx linked build):The typecheck (
tsc -p tsconfig-tests.json) passed as part ofnpm test.Benchmark
Run on a local inferring Fuseki (the test image, TDB2 in memory) with two graphs:
items100k: 100,000 instances of one class (~500k triples). Each has 1–3 language-taggedrdfs:labelvalues (only ~2,000 distinct base labels, so many ties) and two single-valued fields.schema: the schema.org vocabulary (~1,000rdfs:Classes with label and comment).The select reads every field. Each time is the median of 2–3 runs after a warm-up, in seconds; the number of distinct subjects returned is in parentheses. "old" is the row
LIMITonmain. "sub-SELECT (GROUP BY)" is this PR's first commit. "sub-SELECT (DISTINCT)" is what this PR ships for a page with no sort value to aggregate (commit 2:SELECT DISTINCT ?s … [ORDER BY ?s] LIMIT, which streams, where a GROUP BY reads every subject first).Reading the table:
orderByon a path, the page is 3–4× faster than the old rowLIMITon the large set. The old query sorts and de-duplicates every joined row. The page sorts one MIN per subject over only the sort path.LIMITanswered in 0.03 s. The DISTINCT page brings that back to 0.03 s. The old rowLIMITalso returned too few subjects (13 of 20, 51 of 100) on data with several labels.Follow-ups
isIri()/isBlank()(.where((c) => c.isIri())throws "is accessed in a query, but it does not have a @linkedProperty decorator"). Excluding blank nodes (e.g. anonymousowl:unionOfclass expressions) in the query itself needs that, or a$-prefixed node fact like$type(). Not part of this PR.