Project

General

Profile

Bug #40

MINUS operator fails when subtrahend is empty

Added by ronald - about 17 years ago. Updated about 17 years ago.

Status:
Closed
Priority:
High
Assignee:
Category:
Mulgara
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
fixed

Description

The following simple example fails with an [[IllegalArgumentException]]
<br/>
(&quot;tuples must have variables in common for subtraction to occur&quot;):
<br/>

<br/>
&nbsp;&nbsp;delete select $s &lt;a:bar&gt; $o from &lt;<a href="local:///topazproject#foo">local:///topazproject#foo</a>&gt; where $s &lt;a:bar&gt; $o from &lt;<a href="local:///topazproject#foo&gt;;">local:///topazproject#foo&amp;gt;;</a>
<br/>
&nbsp;&nbsp;insert &lt;a:foo&gt; &lt;a:bar&gt; '0' into &lt;<a href="local:///topazproject#foo&gt;;">local:///topazproject#foo&amp;gt;;</a>
<br/>
&nbsp;&nbsp;select $s &lt;a:bar&gt; $o from &lt;<a href="local:///topazproject#foo">local:///topazproject#foo</a>&gt; where $s &lt;a:bar&gt; $o and $s &lt;a:bar&gt; $x minus $s &lt;a:bar&gt; '1';
<br/>

<br/>
The problem is in [[TuplesOperations]].java . Line 304,
<br/>

<br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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.
#1

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/>
&nbsp;&nbsp;delete select $s &lt;a:bar&gt; $o from &lt;<a href="local:///topazproject#foo">local:///topazproject#foo</a>&gt; where $s &lt;a:bar&gt; $o from &lt;<a href="local:///topazproject#foo">local:///topazproject#foo</a>&gt; ;
<br/>
&nbsp;&nbsp;insert &lt;a:foo&gt; &lt;a:bar&gt; '1' into &lt;<a href="local:///topazproject#foo">local:///topazproject#foo</a>&gt; ;
<br/>
&nbsp;&nbsp;delete &lt;a:foo&gt; &lt;a:bar&gt; '1' into &lt;<a href="local:///topazproject#foo">local:///topazproject#foo</a>&gt; ;
<br/>
&nbsp;&nbsp;insert &lt;a:foo&gt; &lt;a:bar&gt; '0' into &lt;<a href="local:///topazproject#foo">local:///topazproject#foo</a>&gt; ;
<br/>
&nbsp;&nbsp;select $s &lt;a:bar&gt; $o from &lt;<a href="local:///topazproject#foo">local:///topazproject#foo</a>&gt; where $s &lt;a:bar&gt; $o and $s &lt;a:bar&gt; $x minus $s &lt;a:bar&gt; '1' ; 
<br/>

<br/>

#2

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.
#3

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/>
&nbsp;&nbsp;DEBUG 36:34 [[ConstraintOperations]]&gt; Resolving [$s a:bar &quot;1&quot; $_from] against [[ModelExpression]][class org.mulgara.query.ModelResource]
<br/>
&nbsp;&nbsp;DEBUG 36:34 [[ConstraintOperations]]&gt; Localizing Constraint[class org.mulgara.query.ConstraintImpl]
<br/>
&nbsp;&nbsp;DEBUG 36:34 XAStringPoolImpl&gt; findGNode(&lt;a:bar&gt;) = 35
<br/>
&nbsp;&nbsp;DEBUG 36:34 XAStringPoolImpl&gt; findGNode(&quot;1&quot;) = 0
<br/>
&nbsp;&nbsp;DEBUG 36:34 [[ConstraintOperations]]&gt; Localized Constraint[class org.mulgara.query.ConstraintImpl] to: [$s gn35 qn1 $_from]
<br/>
&nbsp;&nbsp;DEBUG 36:34 XAStringPoolImpl&gt; findGNode(&lt;#foo&gt;) = 33
<br/>
&nbsp;&nbsp;DEBUG 36:34 [[ConstraintOperations]]&gt; Rewriting Modelgn33 in [$s gn35 qn1 $_from]
<br/>
&nbsp;&nbsp;DEBUG 36:34 [[ConstraintOperations]]&gt; Rewrote Modelgn33 in [$s gn35 qn1 $_from] to [$s gn35 qn1 gn33]
<br/>
&nbsp;&nbsp;DEBUG 36:34 [[DatabaseOperationContext]]&gt; Resolving [$s gn35 qn1 gn33]
<br/>
&nbsp;&nbsp;DEBUG 36:34 XAStringPoolImpl&gt; findSPObject(33) = &lt;#foo&gt;
<br/>
&nbsp;&nbsp;DEBUG 36:34 [[DatabaseOperationContext]]&gt; Checking for an alias on: <a href="local:///topazproject#foo">local:///topazproject#foo</a>
<br/>
&nbsp;&nbsp;DEBUG 36:34 [[DatabaseOperationContext]]&gt; Finding resolver factory for model 33
<br/>
&nbsp;&nbsp;DEBUG 36:34 [[DatabaseOperationContext]]&gt; Model 33 type is <a href="http://mulgara.org/mulgara#Model">http://mulgara.org/mulgara#Model</a>
<br/>
&nbsp;&nbsp;DEBUG 36:34 [[ConstraintOperations]]&gt; Resolved [$s a:bar &quot;1&quot; $_from] against [[ModelExpression]][class org.mulgara.query.ModelResource] to:
<br/>
&nbsp;&nbsp;{(0 rows)
<br/>
&nbsp;&nbsp;}
<br/>
&nbsp;&nbsp;DEBUG 36:34 [[ConstraintOperations]]&gt; Resolved [[ConstraintExpression]][class org.mulgara.query.ConstraintImpl] to:
<br/>
&nbsp;&nbsp;{(0 rows)
<br/>
&nbsp;&nbsp;}
<br/>
&nbsp;&nbsp;DEBUG 36:34 [[TuplesOperations]]&gt; subtracting
<br/>
&nbsp;&nbsp;{(0 rows)
<br/>
&nbsp;&nbsp;} from
<br/>
&nbsp;&nbsp;{$Meta   $Predicate  $Object  $Subject  (35 rows)
<br/>
&nbsp;&nbsp;[000001  000002  000003  000001  ]
<br/>
&nbsp;&nbsp;[000001  000002  000003  000033  ]
<br/>
&nbsp;&nbsp;[000006  000005  000001  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000002  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000003  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000004  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000005  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000006  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000007  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000008  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000009  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000010  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000011  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000012  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000013  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000014  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000015  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000016  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000017  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000018  000004  ]
<br/>
&nbsp;&nbsp;...
<br/>
&nbsp;&nbsp;} from constraint [$s gn35 $x gn33]
<br/>

<br/>
and here are the same entries after doing the insert+delete:
<br/>

<br/>
&nbsp;&nbsp;DEBUG 38:38 [[ConstraintOperations]]&gt; Resolving [$s a:bar &quot;1&quot; $_from] against [[ModelExpression]][class org.mulgara.query.ModelResource]
<br/>
&nbsp;&nbsp;DEBUG 38:38 [[ConstraintOperations]]&gt; Localizing Constraint[class org.mulgara.query.ConstraintImpl]
<br/>
&nbsp;&nbsp;DEBUG 38:38 XAStringPoolImpl&gt; findGNode(&lt;a:bar&gt;) = 35
<br/>
&nbsp;&nbsp;DEBUG 38:38 XAStringPoolImpl&gt; findGNode(&quot;1&quot;) = 37
<br/>
&nbsp;&nbsp;DEBUG 38:38 [[ConstraintOperations]]&gt; Localized Constraint[class org.mulgara.query.ConstraintImpl] to: [$s gn35 gn37 $_from]
<br/>
&nbsp;&nbsp;DEBUG 38:38 XAStringPoolImpl&gt; findGNode(&lt;#foo&gt;) = 33
<br/>
&nbsp;&nbsp;DEBUG 38:38 [[ConstraintOperations]]&gt; Rewriting Modelgn33 in [$s gn35 gn37 $_from]
<br/>
&nbsp;&nbsp;DEBUG 38:38 [[ConstraintOperations]]&gt; Rewrote Modelgn33 in [$s gn35 gn37 $_from] to [$s gn35 gn37 gn33]
<br/>
&nbsp;&nbsp;DEBUG 38:38 [[DatabaseOperationContext]]&gt; Resolving [$s gn35 gn37 gn33]
<br/>
&nbsp;&nbsp;DEBUG 38:38 XAStringPoolImpl&gt; findSPObject(33) = &lt;#foo&gt;
<br/>
&nbsp;&nbsp;DEBUG 38:38 [[DatabaseOperationContext]]&gt; Checking for an alias on: <a href="local:///topazproject#foo">local:///topazproject#foo</a>
<br/>
&nbsp;&nbsp;DEBUG 38:38 [[DatabaseOperationContext]]&gt; Finding resolver factory for model 33
<br/>
&nbsp;&nbsp;DEBUG 38:38 [[DatabaseOperationContext]]&gt; Model 33 type is <a href="http://mulgara.org/mulgara#Model">http://mulgara.org/mulgara#Model</a>
<br/>
&nbsp;&nbsp;DEBUG 38:38 [[StatementStoreResolution]]&gt; Resolving constraint against statementStore: [$s gn35 gn37 gn33]
<br/>
&nbsp;&nbsp;DEBUG 38:38 [[StatementStoreResolution]]&gt; findingTuples for prefixDefinition(false, true, true, true) on 9904841
<br/>
&nbsp;&nbsp;DEBUG 38:38 [[StatementStoreResolution]]&gt; prefixDefinition = B[ false true true true ]
<br/>
&nbsp;&nbsp;DEBUG 38:38 [[StatementStoreResolution]]&gt; indexedTuples.variables = V[ $Meta $Predicate $Object $Subject ]
<br/>
&nbsp;&nbsp;DEBUG 38:38 [[StatementStoreResolution]]&gt; columnOrder = I[ 3 1 2 0 ]
<br/>
&nbsp;&nbsp;DEBUG 38:38 [[StatementStoreResolution]]&gt; Column order returned I[ 3 1 2 0 ]
<br/>
&nbsp;&nbsp;DEBUG 38:38 [[StatementStoreResolution]]&gt; Initialising prefix[] on 9904841 baseDefn = B[ false true true true ] constraint = [$s gn35 gn37 gn33] prefixDefn = B[ false true true true ]
<br/>
&nbsp;&nbsp;DEBUG 38:38 [[StatementStoreResolution]]&gt; prefix defined = L[ 33 35 37 * ]
<br/>
&nbsp;&nbsp;DEBUG 38:38 [[ConstraintOperations]]&gt; Resolved [$s a:bar &quot;1&quot; $_from] against [[ModelExpression]][class org.mulgara.query.ModelResource] to:
<br/>
&nbsp;&nbsp;{$Meta   $Predicate  $Object  $Subject  (35 rows)
<br/>
&nbsp;&nbsp;[000001  000002  000003  000001  ]
<br/>
&nbsp;&nbsp;[000001  000002  000003  000033  ]
<br/>
&nbsp;&nbsp;[000006  000005  000001  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000002  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000003  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000004  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000005  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000006  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000007  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000008  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000009  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000010  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000011  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000012  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000013  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000014  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000015  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000016  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000017  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000018  000004  ]
<br/>
&nbsp;&nbsp;...
<br/>
&nbsp;&nbsp;} from constraint [$s gn35 gn37 gn33]
<br/>
&nbsp;&nbsp;DEBUG 38:38 [[ConstraintOperations]]&gt; Resolved [[ConstraintExpression]][class org.mulgara.query.ConstraintImpl] to:
<br/>
&nbsp;&nbsp;{$Meta   $Predicate  $Object  $Subject  (35 rows)
<br/>
&nbsp;&nbsp;[000001  000002  000003  000001  ]
<br/>
&nbsp;&nbsp;[000001  000002  000003  000033  ]
<br/>
&nbsp;&nbsp;[000006  000005  000001  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000002  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000003  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000004  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000005  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000006  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000007  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000008  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000009  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000010  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000011  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000012  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000013  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000014  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000015  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000016  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000017  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000018  000004  ]
<br/>
&nbsp;&nbsp;...
<br/>
&nbsp;&nbsp;} from constraint [$s gn35 gn37 gn33]
<br/>
&nbsp;&nbsp;DEBUG 38:38 [[TuplesOperations]]&gt; subtracting
<br/>
&nbsp;&nbsp;{$Meta   $Predicate  $Object  $Subject  (35 rows)
<br/>
&nbsp;&nbsp;[000001  000002  000003  000001  ]
<br/>
&nbsp;&nbsp;[000001  000002  000003  000033  ]
<br/>
&nbsp;&nbsp;[000006  000005  000001  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000002  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000003  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000004  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000005  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000006  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000007  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000008  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000009  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000010  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000011  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000012  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000013  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000014  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000015  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000016  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000017  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000018  000004  ]
<br/>
&nbsp;&nbsp;...
<br/>
&nbsp;&nbsp;} from constraint [$s gn35 gn37 gn33] from
<br/>
&nbsp;&nbsp;{$Meta   $Predicate  $Object  $Subject  (35 rows)
<br/>
&nbsp;&nbsp;[000001  000002  000003  000001  ]
<br/>
&nbsp;&nbsp;[000001  000002  000003  000033  ]
<br/>
&nbsp;&nbsp;[000006  000005  000001  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000002  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000003  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000004  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000005  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000006  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000007  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000008  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000009  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000010  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000011  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000012  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000013  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000014  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000015  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000016  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000017  000004  ]
<br/>
&nbsp;&nbsp;[000006  000005  000018  000004  ]
<br/>
&nbsp;&nbsp;...
<br/>
&nbsp;&nbsp;} from constraint [$s gn35 $x gn33]
<br/>

<br/>

Also available in: Atom PDF