Theory
After the WHERE clause produces a bag of solutions, solution modifiers shape it. They are applied in a fixed logical order:
WHERE → GROUP BY → HAVING → (project & BIND) → ORDER BY → DISTINCT → OFFSET → LIMIT
| Modifier | Effect |
|---|---|
ORDER BY ?x / ORDER BY DESC(?x) | Sort ascending / descending |
LIMIT n | Return at most n rows |
OFFSET k | Skip the first k rows (pagination) |
DISTINCT | Remove duplicate rows (set semantics) |
REDUCED | May remove duplicates — a perf hint, not a guarantee |
(expr AS ?v) | Project a computed column |
Two professional cautions
LIMITwithoutORDER BYis non-deterministic. The store may return any n rows, and a different n next time. Stable pagination requires a totalORDER BY(add a tiebreaker like the IRI if your sort key isn't unique).DISTINCTis computed over the projected columns. Adding a column can resurrect 'duplicates' that differ only in that column. If you de-dupe on?personbut also project?role, you get one row per (person, role).