diff --git a/spec/index.html b/spec/index.html index 2369ddd..804def9 100644 --- a/spec/index.html +++ b/spec/index.html @@ -10424,7 +10424,205 @@

Evaluation Semantics

eval( |D|(|G|), Slice(|L|, |start|, |length|) ) = Slice( eval(|D|(|G|), |L|), |start|, |length| )

+ + +
+

Values Insertion and `EXISTS`

+
+

The following subsections contain draft material for a revised + "`exists`" operation. +

+

+ Background: SPARQL CG SEP-0007 +

+
+
+

Syntax Restriction

+

Additional [[[#sparqlGrammar]]] note:

+
+ Any variable that is assigned to in the graph pattern of `EXISTS`/`NOT EXISTS` must not be in-scope. + This applies to `BIND`, variables introduced by `AS` in a `SELECT` clause, variables in a `VALUES` + clause, and variables introduced by `AS` in `GROUP BY`. +
+

+ Extend the "in-scope" rules to include the possible + variables that are in-scope for the current row: +

+ + + + + + + + + + + +
Syntax FormIn-scope variables
`EXISTS` and `NOT EXISTS` filters v is in-scope if it is in-scope for the pattern to which the `FILTER` is applied. +
+
+

+ This restriction means that values inserted + do not conflict with values assigned to variables within the pattern. +

+

+ This operation is performed as part of query parsing. +

+
+
+
+

Remapping

+

+ Remapping ensures that a variable name used inside a project expression, + but which is not part of the results of the evaluation of the project expression, + does not coincide with a variable mentioned anywhere else in the + algebra expression of a query. +

+

+ Renaming these variables does not change the results of evaluating + the project expresssion. +

+
+ Definition: Projection Expression Variable Remapping +

+ For a projection algebra operation #sparqlProjection `Project(A, PV)` acting on algreg express `A` and with set of variables `PV`, define + a partial mapping `F` from + `V`, + the set of all variables, to `V` where: +

+
F(v) = v1 if v is in PV, where v1 is a fresh variable
+F(v) = v if v is not in PV
+

+ Define the Projection Expression Variable Remapping `ProjectMap(P, PV)` +

+
ProjectMap(Project(A, PV)) = Project(A1, PV) 
+                                where A1 is the result of applying F
+                                to every variable mentioned in A.
+                
+

+ The Projection Expression Variable Remapping yields an algrebra expression that + evaluates to the same results as the Project argument. No variable of `ProjectMap(Project(A, PV))` + that is not in `PV` is mentioned anywhere else in the algebra expression for the query. +

+
+

This process is applied throughout the graph pattern of EXISTS:

+
+ Definition: Variable Remapping +

+ For any algebra expression `X`, define the Variable Remapping `PrjMap(X)` + of algebra expression `X`: +

+
PrjMap(X) = replace all project operations Project(P, PV) 
+                with ProjectMap(P, PV) for each projection in X.
+
+

+ The outcome of `PrjMap` is independent of the order of replacement + (e.g. bottom-up or top-down). + Replacements may happen several times, depending on recursive order + but each time a replacement is made, the variable not used anywhere else. +

+ +
+

+ A variable inside a project expression that is not in the variables projected + is not affected by the values insertion operation because it is renamed apart. +

+

+ This operation is as part of the translation to the SPARQL + algebra. +

+
+
+
+

Values Insertion

+

+ Alternative 1: rewrite the algebra during + translation to the SPARQL algebra + to include a function that evaluates to the current row. +

+ +
+
+ Definition: Values In Scope +

+ Define the function `BindingInScope()`. + Evaluation of `BindingInScope()` results in a table of one row, + being the current binding of the enclosing filter. +

+
+
+ +
+
+ Definition: Access to the current binding +

+ During translation to the SPARQL algebra +

+
+Replace each occurence of `Y` in X where `Y` is one of
+          Basic Graph Pattern,
+          Property Path Expression,
+          `Graph(Var, pattern)`,
+          Inline Data
+          with `join(Y, BindingInScope())`.
+
+
+ c.f. section Translate Graph Patterns + where an empty basic graph pattern start any + GroupGraphPattern. + It happens before the simplification step. +
+
+ +
+

+ Examples +

+
+ +

+ Alternative 2: rewrite the algebra during execution. This corresponds to the + original SEP-0007 proposal. +

+
+
+ Definition: Values Insertion +

+ Define the Values Insertion function `ValuesInsert(X, μ)` +

+
Let Table(μ) = { μ } and multiplicity( μ | Table(μ) = { μ } ) = 1
+
+Replace each occurence of `Y` in X where `Y` is one of
+          Basic Graph Pattern,
+          Property Path Expression,
+          `Graph(Var, pattern)`,
+          Inline Data
+with `join(Y, Table(μ))`.
+ +
+
+
+ +
+

Evaluation of EXISTS

+
+ Definition: Evaluation of Exists +

+ Let `μ` be the current solution mapping for a filter, and `X` a graph pattern, + define the Evaluation of Exists `exists(X)` +

+
exists(X) = true 
+              if eval( D(G), ValuesInScope(PrjMap(X)), μ)
+                 is a non-empty solution sequence.
+exists(X) = false otherwise
+
+
+
+ + +

Extending SPARQL Basic Graph Matching

The overall SPARQL design can be used for queries which assume a more elaborate form of