Repository navigation
perf(executor): IF and COALESCE on term ids (#11) - #172
Merged
Merged
Conversation
A product of decimals with more than 18 digits after the point gave no value (oxsdatatypes refuses it). It is now the exact product, as Jena's BigDecimal product: a decimal when it fits 18 fraction digits, else the literal with all its digits, as a long quotient is.
…atdata-eu/tripletrail into claude/project-thread-n3oul3-2
…-n3oul3-2 # Conflicts: # CHANGELOG.md # crates/tripletrail/tests/id_rows.rs # docs/store.md
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 and why
#11: under
--executor ids, aBINDwithIForCOALESCEsent the whole query to the evaluator. These are common in rule sets (COALESCE(?x, 0)after anOPTIONAL,IF(?q > 50, "big", "small")). They now run on term ids, with the evaluator's answers.idvalue::conditioncovers:!=is!(a = b));!, and&&/||with SPARQL's errors (an error and false is false, an error or true is true);BOUND.IFcomputes only the branch it takes, as the evaluator does, so a branch that would give up only does so on the rows that take it. An error in the condition leaves the value unbound.COALESCEgives the first argument that is not an error.idstring. There the branches are any term those kernels make, including variables, IRIs and strings.xsd:decimalcast in a branch keeps its text (7of an integer,1500.0of a double).idvalue::compile_outputnow recurses throughIFandCOALESCE."2.50"^^xsd:decimaland"007"^^xsd:integergo to the term kernels, which copy the constant.ABS(xsd:decimal(?x))) is a computed decimal (7.0), as in the evaluator.direct::computable,idstring::computableandidtree::value_expressionaccept them, so a query that can't run on ids is found before the patterns run.How it was tested
tests/id_rows.rsBINDS has 16 new cases, each compared with the evaluator:&&,||,!,BOUND, and conditions on unbound values fromOPTIONAL;COALESCEof an unbound variable, of a product, of?x / 0, and of a string orSTR;IFinside aFILTER;ABS,* 1andSTR(IF(…));SUM(IF(…))).Oracle with ids as the default, after merging main: all suites pass, apart from the two known plan-shape assertions in
bind_keyed_lookup.133k orders, result cache off, same answers:
BIND(IF(?q > 50, "big", "small") AS ?k)BIND(IF(?q > 50, 1, 0) AS ?k)OPTIONAL { ?o ex:qty ?q } BIND(COALESCE(?q * 2, 0) AS ?t)OPTIONAL { ?o ex:discount ?q } BIND(COALESCE(?q, 0) AS ?t)cargo fmt --checkandcargo clippy -p tripletrail --all-targets -D warningspass.Two gaps showed up that this PR does not change; both are for a follow-up.
GROUP BYover a computed key is slower on ids.BIND(IF(?q > 50, 1, 0) AS ?k) … GROUP BY ?ktakes 20 ms against 12, and the same holds for?q * 2orABS(?q)today. The evaluator's plan counts per?qfirst and computes theBINDonly on the distinct values.OPTIONALwith aFILTERinside it still goes to the evaluator.Documentation
docs/store.md: the id executor's kernels.Docs checked:
docs/store.mdand CHANGELOG are updated. The guide's--executor idssection in13-production.mdlists no functions and stays true. The README doesn't describe the kernels.Main, with #162, is merged in.