diff --git a/spec/index.html b/spec/index.html index 49fa947..1fe9613 100644 --- a/spec/index.html +++ b/spec/index.html @@ -10640,7 +10640,211 @@
The following subsections contain draft material for a revised + "`exists`" operation. +
++ Background: SPARQL CG SEP-0007 +
+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 Form | +In-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 inserted values + do not conflict with values assigned to variables within the pattern. +
++ This operation is performed as part of query parsing. +
++ 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. +
++ For a projection algebra operation + `Project(A, PV)` acting on algebra expression `A` and with set of variables `PV`, + define a mapping `F` from `V`, + the set of all variables, + to `V` where: +
+F(v) = v1 if v is not in PV, where v1 is a fresh variable +F(v) = v if v is 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
:
+ 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(Project(A, PV), PV) for each projection in X.+
+ The outcome of `PrjMap` is independent of the order of replacement + (whether "bottom-up" or "top-down") order. + 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. +
++ Alternative 1: rewrite the algebra during + translation to the SPARQL algebra + to include a function that evaluates to the current row. +
+ ++ Define the function `BindingInScope()`. + Evaluation of `BindingInScope()` results in a table of one row, + being the current binding of the enclosing filter. +
+Need to define `BindingInScope`
++ During translation to the SPARQL algebra +
+Define putting in the `BindingInScope` operator
++Replace each occurence of Y where Y is one of + Basic Graph Pattern, + Property Path Patterns, + Graph(Var, pattern), + Inline Data + with join(Y, BindingInScope()).+
+ Examples +
++ Alternative 2: rewrite the algebra during execution. This corresponds to the + original SEP-0007 proposal. +
++ Define the function `InsertValues(X, μ)` +
+Let Table(μ) = { μ } and multiplicity( μ | Table(μ) = { μ } ) = 1 + +Replace each occurence of Y in X where Y is one of + Basic Graph Pattern, + Property Path Patterns, + Graph(Var, pattern), + Inline Data + with join(Y, Table(μ)).+ +
+ Let `μ` be the current solution mapping for a filter, and `X` a graph pattern, + define the Evaluation of Exists `exists(X)` +
++ @@ Set up the current row for `BindingdInScope`. +
+exists(X) = true + if eval( D(G), μ) + is a non-empty solution sequence. +exists(X) = false otherwise+
The overall SPARQL design can be used for queries which assume a more elaborate form of