Bug #40
MINUS operator fails when subtrahend is empty
Start date:
Due date:
% Done:
0%
Estimated time:
Resolution:
fixed
Description
The following simple example fails with an [[IllegalArgumentException]]
<br/>
("tuples must have variables in common for subtraction to occur"):
<br/>
<br/>
delete select $s <a:bar> $o from <<a href="local:///topazproject#foo">local:///topazproject#foo</a>> where $s <a:bar> $o from <<a href="local:///topazproject#foo>;">local:///topazproject#foo&gt;;</a>
<br/>
insert <a:foo> <a:bar> '0' into <<a href="local:///topazproject#foo>;">local:///topazproject#foo&gt;;</a>
<br/>
select $s <a:bar> $o from <<a href="local:///topazproject#foo">local:///topazproject#foo</a>> where $s <a:bar> $o and $s <a:bar> $x minus $s <a:bar> '1';
<br/>
<br/>
The problem is in [[TuplesOperations]].java . Line 304,
<br/>
<br/>
Set matchingVars = getMatchingVars(minuend, subtrahend);
<br/>
<br/>
returns a non-empty set consisting of [$s]; but the sort() call on
<br/>
line 324 returns a truly empty tuples (line 749), which causes the
<br/>
exception on line 103 of Difference.java because getMatchingVars()
<br/>
now returns empty.
<br/>
<br/>
Attached is a simple patch which adds an explicit check for an empty
<br/>
minued or subtrahend.
Updated by ronald - about 17 years ago
Actually, in order to trigger the bug a triple matching the subtrahend
<br/>
must have been inserted and then removed. So the full sequence really
<br/>
looks like this:
<br/>
<br/>
delete select $s <a:bar> $o from <<a href="local:///topazproject#foo">local:///topazproject#foo</a>> where $s <a:bar> $o from <<a href="local:///topazproject#foo">local:///topazproject#foo</a>> ;
<br/>
insert <a:foo> <a:bar> '1' into <<a href="local:///topazproject#foo">local:///topazproject#foo</a>> ;
<br/>
delete <a:foo> <a:bar> '1' into <<a href="local:///topazproject#foo">local:///topazproject#foo</a>> ;
<br/>
insert <a:foo> <a:bar> '0' into <<a href="local:///topazproject#foo">local:///topazproject#foo</a>> ;
<br/>
select $s <a:bar> $o from <<a href="local:///topazproject#foo">local:///topazproject#foo</a>> where $s <a:bar> $o and $s <a:bar> $x minus $s <a:bar> '1' ;
<br/>
<br/>
Updated by Paula Gearon about 17 years ago
While the fix for this is in, empty tuples should not be sent to this method in the first place. This should be investigated.
<br/>
<br/>
The fact that the non-empty tuples will only appear if the tuples had recently contained data makes me wonder if the constraint resolution cache is the cause. Perhaps it returns an out of date object, and updating the object returns a valid tuples, which correctly contains no data.
Updated by ronald - about 17 years ago
I was wondering about the empty-but-has-vars tuples too. Here is output
<br/>
from the log comparing the two cases. First before the extra insert and
<br/>
delete:
<br/>
<br/>
DEBUG 36:34 [[ConstraintOperations]]> Resolving [$s a:bar "1" $_from] against [[ModelExpression]][class org.mulgara.query.ModelResource]
<br/>
DEBUG 36:34 [[ConstraintOperations]]> Localizing Constraint[class org.mulgara.query.ConstraintImpl]
<br/>
DEBUG 36:34 XAStringPoolImpl> findGNode(<a:bar>) = 35
<br/>
DEBUG 36:34 XAStringPoolImpl> findGNode("1") = 0
<br/>
DEBUG 36:34 [[ConstraintOperations]]> Localized Constraint[class org.mulgara.query.ConstraintImpl] to: [$s gn35 qn1 $_from]
<br/>
DEBUG 36:34 XAStringPoolImpl> findGNode(<#foo>) = 33
<br/>
DEBUG 36:34 [[ConstraintOperations]]> Rewriting Modelgn33 in [$s gn35 qn1 $_from]
<br/>
DEBUG 36:34 [[ConstraintOperations]]> Rewrote Modelgn33 in [$s gn35 qn1 $_from] to [$s gn35 qn1 gn33]
<br/>
DEBUG 36:34 [[DatabaseOperationContext]]> Resolving [$s gn35 qn1 gn33]
<br/>
DEBUG 36:34 XAStringPoolImpl> findSPObject(33) = <#foo>
<br/>
DEBUG 36:34 [[DatabaseOperationContext]]> Checking for an alias on: <a href="local:///topazproject#foo">local:///topazproject#foo</a>
<br/>
DEBUG 36:34 [[DatabaseOperationContext]]> Finding resolver factory for model 33
<br/>
DEBUG 36:34 [[DatabaseOperationContext]]> Model 33 type is <a href="http://mulgara.org/mulgara#Model">http://mulgara.org/mulgara#Model</a>
<br/>
DEBUG 36:34 [[ConstraintOperations]]> Resolved [$s a:bar "1" $_from] against [[ModelExpression]][class org.mulgara.query.ModelResource] to:
<br/>
{(0 rows)
<br/>
}
<br/>
DEBUG 36:34 [[ConstraintOperations]]> Resolved [[ConstraintExpression]][class org.mulgara.query.ConstraintImpl] to:
<br/>
{(0 rows)
<br/>
}
<br/>
DEBUG 36:34 [[TuplesOperations]]> subtracting
<br/>
{(0 rows)
<br/>
} from
<br/>
{$Meta $Predicate $Object $Subject (35 rows)
<br/>
[000001 000002 000003 000001 ]
<br/>
[000001 000002 000003 000033 ]
<br/>
[000006 000005 000001 000004 ]
<br/>
[000006 000005 000002 000004 ]
<br/>
[000006 000005 000003 000004 ]
<br/>
[000006 000005 000004 000004 ]
<br/>
[000006 000005 000005 000004 ]
<br/>
[000006 000005 000006 000004 ]
<br/>
[000006 000005 000007 000004 ]
<br/>
[000006 000005 000008 000004 ]
<br/>
[000006 000005 000009 000004 ]
<br/>
[000006 000005 000010 000004 ]
<br/>
[000006 000005 000011 000004 ]
<br/>
[000006 000005 000012 000004 ]
<br/>
[000006 000005 000013 000004 ]
<br/>
[000006 000005 000014 000004 ]
<br/>
[000006 000005 000015 000004 ]
<br/>
[000006 000005 000016 000004 ]
<br/>
[000006 000005 000017 000004 ]
<br/>
[000006 000005 000018 000004 ]
<br/>
...
<br/>
} from constraint [$s gn35 $x gn33]
<br/>
<br/>
and here are the same entries after doing the insert+delete:
<br/>
<br/>
DEBUG 38:38 [[ConstraintOperations]]> Resolving [$s a:bar "1" $_from] against [[ModelExpression]][class org.mulgara.query.ModelResource]
<br/>
DEBUG 38:38 [[ConstraintOperations]]> Localizing Constraint[class org.mulgara.query.ConstraintImpl]
<br/>
DEBUG 38:38 XAStringPoolImpl> findGNode(<a:bar>) = 35
<br/>
DEBUG 38:38 XAStringPoolImpl> findGNode("1") = 37
<br/>
DEBUG 38:38 [[ConstraintOperations]]> Localized Constraint[class org.mulgara.query.ConstraintImpl] to: [$s gn35 gn37 $_from]
<br/>
DEBUG 38:38 XAStringPoolImpl> findGNode(<#foo>) = 33
<br/>
DEBUG 38:38 [[ConstraintOperations]]> Rewriting Modelgn33 in [$s gn35 gn37 $_from]
<br/>
DEBUG 38:38 [[ConstraintOperations]]> Rewrote Modelgn33 in [$s gn35 gn37 $_from] to [$s gn35 gn37 gn33]
<br/>
DEBUG 38:38 [[DatabaseOperationContext]]> Resolving [$s gn35 gn37 gn33]
<br/>
DEBUG 38:38 XAStringPoolImpl> findSPObject(33) = <#foo>
<br/>
DEBUG 38:38 [[DatabaseOperationContext]]> Checking for an alias on: <a href="local:///topazproject#foo">local:///topazproject#foo</a>
<br/>
DEBUG 38:38 [[DatabaseOperationContext]]> Finding resolver factory for model 33
<br/>
DEBUG 38:38 [[DatabaseOperationContext]]> Model 33 type is <a href="http://mulgara.org/mulgara#Model">http://mulgara.org/mulgara#Model</a>
<br/>
DEBUG 38:38 [[StatementStoreResolution]]> Resolving constraint against statementStore: [$s gn35 gn37 gn33]
<br/>
DEBUG 38:38 [[StatementStoreResolution]]> findingTuples for prefixDefinition(false, true, true, true) on 9904841
<br/>
DEBUG 38:38 [[StatementStoreResolution]]> prefixDefinition = B[ false true true true ]
<br/>
DEBUG 38:38 [[StatementStoreResolution]]> indexedTuples.variables = V[ $Meta $Predicate $Object $Subject ]
<br/>
DEBUG 38:38 [[StatementStoreResolution]]> columnOrder = I[ 3 1 2 0 ]
<br/>
DEBUG 38:38 [[StatementStoreResolution]]> Column order returned I[ 3 1 2 0 ]
<br/>
DEBUG 38:38 [[StatementStoreResolution]]> Initialising prefix[] on 9904841 baseDefn = B[ false true true true ] constraint = [$s gn35 gn37 gn33] prefixDefn = B[ false true true true ]
<br/>
DEBUG 38:38 [[StatementStoreResolution]]> prefix defined = L[ 33 35 37 * ]
<br/>
DEBUG 38:38 [[ConstraintOperations]]> Resolved [$s a:bar "1" $_from] against [[ModelExpression]][class org.mulgara.query.ModelResource] to:
<br/>
{$Meta $Predicate $Object $Subject (35 rows)
<br/>
[000001 000002 000003 000001 ]
<br/>
[000001 000002 000003 000033 ]
<br/>
[000006 000005 000001 000004 ]
<br/>
[000006 000005 000002 000004 ]
<br/>
[000006 000005 000003 000004 ]
<br/>
[000006 000005 000004 000004 ]
<br/>
[000006 000005 000005 000004 ]
<br/>
[000006 000005 000006 000004 ]
<br/>
[000006 000005 000007 000004 ]
<br/>
[000006 000005 000008 000004 ]
<br/>
[000006 000005 000009 000004 ]
<br/>
[000006 000005 000010 000004 ]
<br/>
[000006 000005 000011 000004 ]
<br/>
[000006 000005 000012 000004 ]
<br/>
[000006 000005 000013 000004 ]
<br/>
[000006 000005 000014 000004 ]
<br/>
[000006 000005 000015 000004 ]
<br/>
[000006 000005 000016 000004 ]
<br/>
[000006 000005 000017 000004 ]
<br/>
[000006 000005 000018 000004 ]
<br/>
...
<br/>
} from constraint [$s gn35 gn37 gn33]
<br/>
DEBUG 38:38 [[ConstraintOperations]]> Resolved [[ConstraintExpression]][class org.mulgara.query.ConstraintImpl] to:
<br/>
{$Meta $Predicate $Object $Subject (35 rows)
<br/>
[000001 000002 000003 000001 ]
<br/>
[000001 000002 000003 000033 ]
<br/>
[000006 000005 000001 000004 ]
<br/>
[000006 000005 000002 000004 ]
<br/>
[000006 000005 000003 000004 ]
<br/>
[000006 000005 000004 000004 ]
<br/>
[000006 000005 000005 000004 ]
<br/>
[000006 000005 000006 000004 ]
<br/>
[000006 000005 000007 000004 ]
<br/>
[000006 000005 000008 000004 ]
<br/>
[000006 000005 000009 000004 ]
<br/>
[000006 000005 000010 000004 ]
<br/>
[000006 000005 000011 000004 ]
<br/>
[000006 000005 000012 000004 ]
<br/>
[000006 000005 000013 000004 ]
<br/>
[000006 000005 000014 000004 ]
<br/>
[000006 000005 000015 000004 ]
<br/>
[000006 000005 000016 000004 ]
<br/>
[000006 000005 000017 000004 ]
<br/>
[000006 000005 000018 000004 ]
<br/>
...
<br/>
} from constraint [$s gn35 gn37 gn33]
<br/>
DEBUG 38:38 [[TuplesOperations]]> subtracting
<br/>
{$Meta $Predicate $Object $Subject (35 rows)
<br/>
[000001 000002 000003 000001 ]
<br/>
[000001 000002 000003 000033 ]
<br/>
[000006 000005 000001 000004 ]
<br/>
[000006 000005 000002 000004 ]
<br/>
[000006 000005 000003 000004 ]
<br/>
[000006 000005 000004 000004 ]
<br/>
[000006 000005 000005 000004 ]
<br/>
[000006 000005 000006 000004 ]
<br/>
[000006 000005 000007 000004 ]
<br/>
[000006 000005 000008 000004 ]
<br/>
[000006 000005 000009 000004 ]
<br/>
[000006 000005 000010 000004 ]
<br/>
[000006 000005 000011 000004 ]
<br/>
[000006 000005 000012 000004 ]
<br/>
[000006 000005 000013 000004 ]
<br/>
[000006 000005 000014 000004 ]
<br/>
[000006 000005 000015 000004 ]
<br/>
[000006 000005 000016 000004 ]
<br/>
[000006 000005 000017 000004 ]
<br/>
[000006 000005 000018 000004 ]
<br/>
...
<br/>
} from constraint [$s gn35 gn37 gn33] from
<br/>
{$Meta $Predicate $Object $Subject (35 rows)
<br/>
[000001 000002 000003 000001 ]
<br/>
[000001 000002 000003 000033 ]
<br/>
[000006 000005 000001 000004 ]
<br/>
[000006 000005 000002 000004 ]
<br/>
[000006 000005 000003 000004 ]
<br/>
[000006 000005 000004 000004 ]
<br/>
[000006 000005 000005 000004 ]
<br/>
[000006 000005 000006 000004 ]
<br/>
[000006 000005 000007 000004 ]
<br/>
[000006 000005 000008 000004 ]
<br/>
[000006 000005 000009 000004 ]
<br/>
[000006 000005 000010 000004 ]
<br/>
[000006 000005 000011 000004 ]
<br/>
[000006 000005 000012 000004 ]
<br/>
[000006 000005 000013 000004 ]
<br/>
[000006 000005 000014 000004 ]
<br/>
[000006 000005 000015 000004 ]
<br/>
[000006 000005 000016 000004 ]
<br/>
[000006 000005 000017 000004 ]
<br/>
[000006 000005 000018 000004 ]
<br/>
...
<br/>
} from constraint [$s gn35 $x gn33]
<br/>
<br/>