Hello Ivan,
thanks a lot for answering.
On 01/10/2011 05:44 PM, Ivan Mikhailov wrote:
> It's hard to diagnose without dumps of EXPLAINs of these queries.
> Most probably, the last triple pattern has been moved toward the leading
> position because the selectivity of the fixed object variant was
> overestimated. You can try to check variants that restrict graphs, if
> that is possible. E.g., the following may be correct:
>
> select distinct ?r where {
> { graph ?g { ?r ?v1 ?v2 .
> FILTER(bif:contains(?v2, \"'hello' AND 'world'\")) . }
> }
> UNION
> { graph ?g { ?r ?v1 ?v3 .
> ?v3 ?v4 ?v2 .
> FILTER(bif:contains(?v2, \"'hello' AND 'world'\")) .
> }
> ?v4 rdfs:subPropertyOf rdfs:label .
> } .
> graph ?g { ?r nao:userVisible 1 }
> }
sadly I cannot restrict via graphs as the data is scattered between a
lot of them. Still that is not a big deal as I can use the faster query
and then filter the results on the client side. This is less clean but
according to my experiments seems really worth it.
It just seemed weird to me.
For completeness I am attaching the explains of the two queries in case
you want to look at them.
Cheers,
Sebastian
> Best Regards,
>
> Ivan Mikhailov
> OpenLink Software
> http://virtuoso.openlinksw.com
>
> On Mon, 2011-01-10 at 16:22 +0100, Sebastian Trüg wrote:
>> Hi list,
>>
>> again I have a question about query performance: why is there a big
>> difference in query execution time between
>>
>> select distinct ?r ?v where {
>> { ?r ?v1 ?v2 .
>> FILTER(bif:contains(?v2, "'hello' AND 'world'")) .
>> }
>> UNION
>> { ?r ?v1 ?v3 .
>> ?v3 ?v4 ?v2 .
>> ?v4 rdfs:subPropertyOf rdfs:label .
>> FILTER(bif:contains(?v2, \"'hello' AND 'world'\")) .
>> } .
>> ?r nao:userVisible ?v
>> }
>>
>> and
>>
>> select distinct ?r where {
>> { ?r ?v1 ?v2 .
>> FILTER(bif:contains(?v2, \"'hello' AND 'world'\")) .
>> }
>> UNION
>> { ?r ?v1 ?v3 .
>> ?v3 ?v4 ?v2 .
>> ?v4 rdfs:subPropertyOf rdfs:label .
>> FILTER(bif:contains(?v2, \"'hello' AND 'world'\")) .
>> } .
>> ?r nao:userVisible 1
>> }
>>
>> The first one returns in no time while the second one takes time.
>>
>> Any ideas?
>>
>> Cheers,
>> Sebastian
>>
>> ------------------------------------------------------------------------------
>> Gaining the trust of online customers is vital for the success of any company
>> that requires sensitive data to be transmitted over the Web. Learn how to
>> best implement a security strategy that keeps consumers' information secure
>> and instills the confidence they need to proceed with transactions.
>> http://p.sf.net/sfu/oracle-sfdevnl
>> _______________________________________________
>> Virtuoso-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/virtuoso-users
>
>
>
SQL> explain( 'sparql select distinct ?r where { { ?r ?v1 ?v2 .
FILTER(bif:contains(?v2, "\'hello\' AND \'world\'")) . } UNION { ?r ?v1
?v3 . ?v3 ?v4 ?v2 . ?v4 rdfs:subPropertyOf rdfs:label .
FILTER(bif:contains(?v2, "\'hello\' AND \'world\'")) . } . ?r
<http://www.semanticdesktop.org/ontologies/2007/08/15/nao#userVisible> 1 }' );
REPORT
VARCHAR
_______________________________________________________________________________
{
Precode:
0: $20 "MIN_BNODE_IRI_ID" := Call MIN_BNODE_IRI_ID ()
5: BReturn 0
Subquery 21
{
Subquery 23
{
Union
{
CONTAINS (<constant ([ __enc "UTF-8" ] 'hello' AND 'world')>) node on
DB.DBA.RDF_OBJ_RO_FLAGS_WORDS 0 rows
$29 "t4.O"
from DB.DBA.RDF_QUAD by RDF_QUAD_OP 4.2e+02 rows
Key RDF_QUAD_OP ASC ($34 "t4.P")
inlined <col=548 O = $29 "t4.O">
from DB.DBA.RDF_QUAD by RDF_QUAD_POGS 5.2 rows
Key RDF_QUAD_POGS ASC ($38 "t4.S")
<col=547 P = $34 "t4.P"> , <col=548 O = $29 "t4.O">
from DB.DBA.RDF_QUAD by RDF_QUAD 0.31 rows
Key RDF_QUAD ASC ($43 "t5.O", $42 "t5.S")
inlined <col=547 P = <constant (#i3303140)>> , <col=546 S = $38 "t4.S"> ,
<col=548 O = <constant (1)>>
Local Test
0: $46 "ISIRI_ID" := Call ISIRI_ID ($43 "t5.O")
5: $47 "temp" := artm <constant (1)> - $46 "ISIRI_ID"
9: if (<constant (0)> 1(=) $47 "temp") then 13 else 12 unkn 13
12: BReturn 1
13: BReturn 0
Local Code
0: $24 "r" := := artm $42 "t5.S"
4: BReturn 0
Subquery Select($24 "r", <$45 "<DB.DBA.RDF_QUAD t5>" spec 5>, <$40
"<DB.DBA.RDF_QUAD t4>" spec 5>, <$36 "<DB.DBA.RDF_QUAD t4>" spec 5>)
}
{
from DB.DBA.RDF_QUAD by RDF_QUAD_POGS 8.3e+03 rows
Key RDF_QUAD_POGS ASC ($56 "s-1-6-t1.S", $55 "s-1-6-t1.O")
row specs: <col=548 O LIKE <constant (T�)>>
from DB.DBA.RDF_QUAD by RDF_QUAD 0.31 rows
Key RDF_QUAD ASC ($61 "s-1-1-t4.O", $60 "s-1-1-t4.S")
inlined <col=547 P = <constant (#i3303140)>> , <col=546 S = $56 "s-1-6-t1.S">
, <col=548 O = <constant (1)>>
Local Test
0: $64 "ISIRI_ID" := Call ISIRI_ID ($61 "s-1-1-t4.O")
5: $65 "temp" := artm <constant (1)> - $64 "ISIRI_ID"
9: if (<constant (0)> 1(=) $65 "temp") then 13 else 12 unkn 13
12: BReturn 1
13: BReturn 0
Subquery 66
{
from DB.DBA.RDF_QUAD by RDF_QUAD_SP 1 rows
Key RDF_QUAD_SP ASC ($74 "s-1-6-t2-int.S", $73 "s-1-6-t2-int.P")
inlined <col=546 S = $55 "s-1-6-t1.O">
from DB.DBA.RDF_QUAD by RDF_QUAD 0.053 rows
Key RDF_QUAD ASC ($79 "s-1-6-t2-int.O", $84 "s-1-6-t2-int.G")
inlined <col=547 P = $73 "s-1-6-t2-int.P"> , <col=546 S = $55 "s-1-6-t1.O">
CONTAINS (<constant ([ __enc "UTF-8" ] 'hello' AND 'world')>) node on
DB.DBA.RDF_OBJ_RO_FLAGS_WORDS 0 rows
$79 "s-1-6-t2-int.O"
After code:
0: $67 "aa67003~G" := := artm $84 "s-1-6-t2-int.G"
4: $68 "71af6d9~S" := := artm $74 "s-1-6-t2-int.S"
8: $69 "ac27003~P" := := artm $73 "s-1-6-t2-int.P"
12: $70 "ddcb702~O" := := artm $79 "s-1-6-t2-int.O"
16: BReturn 0
Subquery Select($67 "aa67003~G", $68 "71af6d9~S", $69 "ac27003~P", $70
"ddcb702~O", <$86 "<DB.DBA.RDF_QUAD s-1-6-t2-int>" spec 5>, <$76
"<DB.DBA.RDF_QUAD s-1-6-t2-int>" spec 5>)
}
from DB.DBA.RDF_QUAD by RDF_QUAD 0.34 rows
Key RDF_QUAD ASC ()
inlined <col=547 P = <constant (#i1020582)>> , <col=546 S = $69 "ac27003~P"> ,
<col=548 O = <constant (#i1040125)>>
row specs: <col=548 O LIKE <constant (T�)>> , <col=546 S < $20
"MIN_BNODE_IRI_ID">
Local Code
0: $24 "r" := := artm $60 "s-1-1-t4.S"
4: BReturn 0
Subquery Select($24 "r", <$45 "<DB.DBA.RDF_QUAD t5>" spec 5>, <$40
"<DB.DBA.RDF_QUAD t4>" spec 5>, <$36 "<DB.DBA.RDF_QUAD t4>" spec 5>)
}
}
After code:
0: $103 "__ID2I" := Call __ID2I ($24 "r")
5: BReturn 0
Distinct (HASH) ($24 "r")
After code:
0: $22 "r" := := artm $103 "__ID2I"
4: BReturn 0
Subquery Select($22 "r")
}
After code:
0: $115 "r" := Call __RO2SQ ($22 "r")
5: BReturn 0
Select ($115 "r")
}
104 Rows. -- 11 msec.
SQL> explain( 'sparql select distinct ?r ?v where { { ?r ?v1 ?v2 .
FILTER(bif:contains(?v2, "\'hello\' AND \'world\'")) . } UNION { ?r ?v1
?v3 . ?v3 ?v4 ?v2 . ?v4 rdfs:subPropertyOf rdfs:label .
FILTER(bif:contains(?v2, "\'hello\' AND \'world\'")) . } . ?r
<http://www.semanticdesktop.org/ontologies/2007/08/15/nao#userVisible> ?v }' );
REPORT
VARCHAR
_______________________________________________________________________________
{
Precode:
0: $20 "MIN_BNODE_IRI_ID" := Call MIN_BNODE_IRI_ID ()
5: BReturn 0
Subquery 21
{
Subquery 24
{
Union
{
CONTAINS (<constant ([ __enc "UTF-8" ] 'hello' AND 'world')>) node on
DB.DBA.RDF_OBJ_RO_FLAGS_WORDS 0 rows
$31 "t4.O"
from DB.DBA.RDF_QUAD by RDF_QUAD_OP 4.2e+02 rows
Key RDF_QUAD_OP ASC ($36 "t4.P")
inlined <col=548 O = $31 "t4.O">
from DB.DBA.RDF_QUAD by RDF_QUAD_POGS 5.2 rows
Key RDF_QUAD_POGS ASC ($40 "t4.S")
<col=547 P = $36 "t4.P"> , <col=548 O = $31 "t4.O">
from DB.DBA.RDF_QUAD by RDF_QUAD 0.94 rows
Key RDF_QUAD ASC ($45 "t5.S", $44 "t5.O")
inlined <col=547 P = <constant (#i3303140)>> , <col=546 S = $40 "t4.S">
Local Code
0: $25 "r" := := artm $45 "t5.S"
4: $26 "v" := := artm $44 "t5.O"
8: BReturn 0
Subquery Select($25 "r", $26 "v", <$47 "<DB.DBA.RDF_QUAD t5>" spec 5>, <$42
"<DB.DBA.RDF_QUAD t4>" spec 5>, <$38 "<DB.DBA.RDF_QUAD t4>" spec 5>)
}
{
Subquery 54
{
CONTAINS (<constant ([ __enc "UTF-8" ] 'hello' AND 'world')>) node on
DB.DBA.RDF_OBJ_RO_FLAGS_WORDS 0 rows
$62 "s-1-6-t2-int.O"
from DB.DBA.RDF_QUAD by RDF_QUAD_OP 4.2e+02 rows
Key RDF_QUAD_OP ASC ($67 "s-1-6-t2-int.P")
inlined <col=548 O = $62 "s-1-6-t2-int.O">
from DB.DBA.RDF_QUAD by RDF_QUAD_POGS 5.2 rows
Key RDF_QUAD_POGS ASC ($72 "s-1-6-t2-int.G", $71 "s-1-6-t2-int.S")
<col=547 P = $67 "s-1-6-t2-int.P"> , <col=548 O = $62 "s-1-6-t2-int.O">
Local Code
0: $55 "aa67003~G" := := artm $72 "s-1-6-t2-int.G"
4: $56 "71af6d9~S" := := artm $71 "s-1-6-t2-int.S"
8: $57 "ac27003~P" := := artm $67 "s-1-6-t2-int.P"
12: $58 "ddcb702~O" := := artm $62 "s-1-6-t2-int.O"
16: BReturn 0
Subquery Select($55 "aa67003~G", $56 "71af6d9~S", $57 "ac27003~P", $58
"ddcb702~O", <$74 "<DB.DBA.RDF_QUAD s-1-6-t2-int>" spec 5>, <$69
"<DB.DBA.RDF_QUAD s-1-6-t2-int>" spec 5>)
}
from DB.DBA.RDF_QUAD by RDF_QUAD 0.29 rows
Key RDF_QUAD ASC ()
inlined <col=547 P = <constant (#i1020582)>> , <col=546 S = $57 "ac27003~P"> ,
<col=548 O = <constant (#i1040125)>>
row specs: <col=548 O LIKE <constant (T�)>> , <col=546 S < $20
"MIN_BNODE_IRI_ID">
from DB.DBA.RDF_QUAD by RDF_QUAD_OP 5.2 rows
Key RDF_QUAD_OP ASC ($85 "s-1-6-t1.P")
inlined <col=548 O = $56 "71af6d9~S">
row specs: <col=548 O LIKE <constant (T�)>>
from DB.DBA.RDF_QUAD by RDF_QUAD_POGS 5.2 rows
Key RDF_QUAD_POGS ASC ($89 "s-1-6-t1.S")
<col=547 P = $85 "s-1-6-t1.P"> , <col=548 O = $56 "71af6d9~S">
row specs: <col=548 O LIKE <constant (T�)>>
from DB.DBA.RDF_QUAD by RDF_QUAD 0.94 rows
Key RDF_QUAD ASC ($94 "s-1-1-t4.S", $93 "s-1-1-t4.O")
inlined <col=547 P = <constant (#i3303140)>> , <col=546 S = $89 "s-1-6-t1.S">
Local Code
0: $25 "r" := := artm $94 "s-1-1-t4.S"
4: $26 "v" := := artm $93 "s-1-1-t4.O"
8: BReturn 0
Subquery Select($25 "r", $26 "v", <$47 "<DB.DBA.RDF_QUAD t5>" spec 5>, <$42
"<DB.DBA.RDF_QUAD t4>" spec 5>, <$38 "<DB.DBA.RDF_QUAD t4>" spec 5>)
}
}
After code:
0: $104 "__ID2I" := Call __ID2I ($25 "r")
5: $105 "__RO2SQ" := Call __RO2SQ ($26 "v")
10: BReturn 0
Distinct (HASH) ($25 "r", $26 "v")
After code:
0: $22 "r" := := artm $104 "__ID2I"
4: $23 "v" := := artm $105 "__RO2SQ"
8: BReturn 0
Subquery Select($22 "r", $23 "v")
}
After code:
0: $117 "r" := Call __RO2SQ ($22 "r")
5: $118 "v" := Call __RO2SQ ($23 "v")
10: BReturn 0
Select ($117 "r", $118 "v")
}
101 Rows. -- 3 msec.