Skip to content

Correlated EXISTS #257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Correlated EXISTS #257

wants to merge 5 commits into from

Conversation

afs
Copy link
Contributor

@afs afs commented Aug 13, 2025

Copy link
Member

@TallTed TallTed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incomplete, but better than no review... Some clear fixes; some less clear questions.

@@ -8849,16 +8849,27 @@ <h4>Variable Scope</h4>
<td><code>VALUES varlist { values }</code></td>
<td><code>v</code> is in-scope if <code>v</code> is in <code>varlist</code></td>
</tr>
<tr>
<td>`EXISTS` and `NOT EXISTS` filters</td>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<td>`EXISTS` and `NOT EXISTS` filters</td>
<td>`FILTERs` using `EXISTS` and `NOT EXISTS`</td>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, to @TallTed's edit suggestion: since FILTERs is not a keyword in SPARQL, I would not code-fence it. Additionally, for this rephrasing, it should be "or" instead of "and". So, better something like:

Suggested change
<td>`EXISTS` and `NOT EXISTS` filters</td>
<td>`FILTER` statements using `EXISTS` or `NOT EXISTS`</td>

or:

Suggested change
<td>`EXISTS` and `NOT EXISTS` filters</td>
<td>`FILTER` containing `EXISTS` or `NOT EXISTS`</td>

Now, more generally: Is this really only about filters? Shouldn't BIND with EXISTS or NOT EXISTS be considered as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, I wonder why EXISTS and NOT EXISTS need to be mentioned at all here.

For every FILTER expr, it holds that no variable is in-scope, no matter whether expr contains EXISTS/NOT EXISTS or not. The notion of in-scope variables is about variables that may be in a solution mapping produced for a query construct and a FILTER itself does not result in solution mappings. So, no variable can be in-scope for a FILTER. Of course, there may be variables that are in-scope for a group pattern that contains a FILTER, but that case is covered by the Group-related row above in this table.

<p>The variable <code>v</code> must not be in-scope at the point of the
<code>(expr AS v)</code> form. The scoping for <code>(expr AS v)</code>
applies immediately in <code>SELECT</code> expressions.
</p>
<p>In <code>BIND (expr AS v)</code> requires that the variable <code>v</code> is not
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<p>In <code>BIND (expr AS v)</code> requires that the variable <code>v</code> is not
<p><code>BIND (expr AS v)</code> requires that the variable <code>v</code> is not

Comment on lines 8869 to 8802
<p>In <code>SELECT</code>, the variable <code>v</code> must not be in-scope in the graph
pattern of the <code>SELECT</code> clause, nor used in another select expression earlier in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be non-normative text. I am therefore writing to replace the lowercase RFC2119 language.

Suggested change
<p>In <code>SELECT</code>, the variable <code>v</code> must not be in-scope in the graph
pattern of the <code>SELECT</code> clause, nor used in another select expression earlier in
<p>In <code>SELECT</code>, the variable <code>v</code> cannot be in-scope in the graph
pattern of the <code>SELECT</code> clause, nor have been used in another select expression earlier in

<div class="ednote" id="note-BindingInScope">
<p>
One way to provide `BindingInScope` is to change `eval` to also have the current row
as an argument or a "null" token. . Normally this the "null" token. This would be set in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
as an argument or a "null" token. . Normally this the "null" token. This would be set in
as an argument or a "null" token, and is normally the "null" token. This would be set in

Comment on lines +9006 to +8942
Another way is to have a global (to the execution) variable. In eval-exists, the
old value is recorded, the global set to the new value, and reset on exit - this forms a
stack for nested EXISTS.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear what is reset on exit. I think, maybe, replace that phrase with the global reset to the old value on exit, as suggested below. The hyphen should become either a full stop (as suggested below) or an em-dash (which I think doesn't work as well, here).

Suggested change
Another way is to have a global (to the execution) variable. In eval-exists, the
old value is recorded, the global set to the new value, and reset on exit - this forms a
stack for nested EXISTS.
Another way is to have a global (to the execution) variable. In eval-exists, the
old value is recorded, the global set to the new value, and the global reset to the old value on exit. This forms a
stack for nested `EXISTS`.

<p>
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Replacements may happen several times, depending on recursive order
Replacements may happen several times, depending on recursive order,

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand what's trying to be said here. It might just need the is I've added, but a larger change may be needed.

Suggested change
but each time a replacement is made, the variable not used anywhere else.
but each time a replacement is made, the variable is not used anywhere else.

<div class="note">
<p>
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
is not affected by the values insertion operation because it is renamed apart.
is not affected by the value insertion operation because it is renamed separately.

@@ -10502,6 +10623,12 @@ <h3>Evaluation Semantics</h3>
</div>
<div class="defn">
<p><b>Definition: <span id="defn_evalFilter">Evaluation of Filter</span></b></p>

<p class="ednote">@@ Make current μ available. Or use current language in Exist.
Long term: change eval() to be arity three - 3rd argument is "current row".
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Long term: change eval() to be arity three - 3rd argument is "current row".
Long term: change eval() to be arity three 3rd argument is "current row".

@@ -10994,52 +11125,95 @@ <h3>Grammar</h3>
section 6 <a data-cite="xml11#sec-notation">Notation</a>.</p>
<p>Notes:</p>
<ol>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Order doesn't seem to be important in this <ol>. If there is nothing that refers to these notes by number, then this <ol> should be changed to an <ul>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The numbering is essential so people can talk about the notes conveniently. It is a long list - saying the "8th bullet" is convenient. Counting manually is not convenient.

@hartig
Copy link
Contributor

hartig commented Aug 14, 2025

@afs do you already want feedback on this one? (I am asking because it still has WiP status in the GitHub UI and you didn't say anything in the description.)

@afs
Copy link
Contributor Author

afs commented Aug 14, 2025

@hartig - I was going to bring it up at the next SPARQL TF.

I use marking as "draft" to indicate its still changing so it's more like "FYI" in this state and not a request for feedback but feedback on the design is welcome. (here - the areas are marked @@.)

On this PR, one area that might be of interest is whether "eval(pattern, D, G)" could be useful generalized to take a correlation
row as an extra argument. While it may not be necessary for EXISTS and handling the correlation row could be EXIST specific. But being mindful of future possibilities and the desire to not have too many algorithm variations, it might be a useful way to go while the spec is in WG (i.e pre features+maintenance). It isn't worse than EXIST-specific handling. The timing with regard to your current work might be quite good.

@afs afs force-pushed the exists-correlated branch from 84d3cbd to cdbd2a8 Compare August 14, 2025 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants