OPTIONALs and constraints

While implementing OPTIONAL support I found a screw case, the query:

	SELECT ?y ?y1
	WHERE (?x ?y ?z)
	OPTIONAL { (?x ?y1 ?z) }
	AND ?y != ?y1

Is odd because the constriant (?y != ?y1) will fail if applied globally
when y1 is unbound, effectivly removing the OPTIONAL keyword. Making it
equivalent to:

	SELECT ?y ?y1
	WHERE (?x ?y ?z)
	      (?x ?y1 ?z)
	AND ?y != ?y1

Which is almost certainly not what the writer was expecting, though I
/think/ its correct according to the spec. If the constraint is only
applied to the block it makes sense on, we get:

	SELECT ?y ?y1
	WHERE (?x ?y ?z)
	OPTIONAL { (?x ?y1 ?z) AND ?y != ?y1 }

Which is a very differnt query (its what I intended when I wrote it
though). In general I suspect it will be difficiult to come up with
deterministic and unsupprising rules to bind constraints to the correct
query expression block(s). It also makes x AND y different from x && y,
though Andy tells me that's allready the case.

I dont know what the correct interpretation is, or whats a good solution.
My gut reaction is that a global constraint that includes variables only
bound in OPTIONAL block is an error, making the user pick a form
explicitly.

- Steve

Received on Thursday, 24 February 2005 11:36:43 UTC