Skip to content

Instantly share code, notes, and snippets.

@quoll
Created August 9, 2022 19:35
Show Gist options
  • Save quoll/b704177fd2226adc73c8be427d4b3683 to your computer and use it in GitHub Desktop.
Save quoll/b704177fd2226adc73c8be427d4b3683 to your computer and use it in GitHub Desktop.
Query plan for count based intersection
# select ?s ?inter
# from <tag:stardog:api:context:default>
# from :entailed
# WHERE
# { { SELECT ?inter (COUNT(DISTINCT ?c) AS ?inter_cnt)
# WHERE
# { ?inter owl:intersectionOf/rdf:rest*/rdf:first ?c }
# GROUP BY ?inter
# }
# { SELECT ?s ?inter (COUNT(DISTINCT ?c) AS ?instance_cnt)
# WHERE
# { ?inter owl:intersectionOf/rdf:rest*/rdf:first ?c .
# ?s rdf:type ?c
# }
# GROUP BY ?s ?inter
# }
# FILTER ( ?instance_cnt = ?inter_cnt )
# }
From entailed
From default
Slice(offset=0, limit=1000) [#1.0K]
`─ Projection(?s, ?inter) [#7531.9M]
`─ Filter(?instance_cnt = ?inter_cnt) [#7531.9M]
`─ HashJoin(?inter) [#15063.9M]
+─ Projection(?s, ?inter, ?instance_cnt) [#11518.7M]
│ `─ Group(by=[?inter, ?s] aggregates=[(COUNT(DISTINCT ?c) AS ?instance_cnt)]) [#11518.7M]
│ `─ MergeJoin(?c) [#28796.8M]
│ +─ Scan[POSC](?s, rdf:type, ?c) [#2.2M]
│ `─ Sort(?c) [#641K]
│ `─ MergeJoin(?ozpgzmze) [#641K]
│ +─ Scan[PSOC](?ozpgzmze, rdf:first, ?c) [#891K]
│ `─ Sort(?ozpgzmze) [#853K]
│ `─ MergeJoin(?iielhfjt) [#853K]
│ +─ PropertyPath(?iielhfjt -> ?ozpgzmze, minLength=0, sortedBy=?iielhfjt) [#868K]
│ │ +─ Distinct [#332K]
│ │ │ `─ Projection(?iielhfjt) [#332K]
│ │ │ `─ Scan[POSC](?inter, owl:intersectionOf, ?iielhfjt) [#332K]
│ │ `─ Scan[PSOC](?iielhfjt, rdf:rest, ?ozpgzmze) [#891K]
│ `─ Scan[POSC](?inter, owl:intersectionOf, ?iielhfjt) [#332K]
`─ Projection(?inter, ?inter_cnt) [#641K]
`─ Group(by=[?inter] aggregates=[(COUNT(DISTINCT ?c) AS ?inter_cnt)]) [#641K]
`─ MergeJoin(?bqvrwwep) [#641K]
+─ Scan[PSOC](?bqvrwwep, rdf:first, ?c) [#891K]
`─ Sort(?bqvrwwep) [#853K]
`─ MergeJoin(?hjfbpnht) [#853K]
+─ PropertyPath(?hjfbpnht -> ?bqvrwwep, minLength=0, sortedBy=?hjfbpnht) [#868K]
│ +─ Distinct [#332K]
│ │ `─ Projection(?hjfbpnht) [#332K]
│ │ `─ Scan[POSC](?inter, owl:intersectionOf, ?hjfbpnht) [#332K]
│ `─ Scan[PSOC](?hjfbpnht, rdf:rest, ?bqvrwwep) [#891K]
`─ Scan[POSC](?inter, owl:intersectionOf, ?hjfbpnht) [#332K]
# select ?x ?i
# from <tag:stardog:api:context:default>
# from :entailed
# where { ?i owl:intersectionOf ?l .
# ?l rdf:rest*/rdf:first ?c .
# ?x a ?c
# MINUS {
# ?l rdf:rest*/rdf:first ?d .
# ?l rdf:rest*/rdf:first ?d2 .
# FILTER ( ?d != ?d2 )
# ?x a ?d MINUS { ?x a ?d2 }
# } }
# reused
From entailed
From default
Slice(offset=0, limit=1000) [#1.0K]
`─ Projection(?x, ?i) [#28796.8M]
`─ Minus(HashLookup) [#28796.8M]
+─ MergeJoin(?c) [#28796.8M]
│ +─ Scan[POSC](?x, rdf:type, ?c) [#2.2M]
│ `─ Sort(?c) [#641K]
│ `─ MergeJoin(?tddiphpw) [#641K]
│ +─ Scan[PSOC](?tddiphpw, rdf:first, ?c) [#891K]
│ `─ Sort(?tddiphpw) [#853K]
│ `─ MergeJoin(?l) [#853K]
│ +─ PropertyPath(?l -> ?tddiphpw, minLength=0, sortedBy=?l) [#868K]
│ │ +─ Distinct [#332K]
│ │ │ `─ Projection(?l) [#332K]
│ │ │ `─ Scan[POSC](?i, owl:intersectionOf, ?l) [#332K]
│ │ `─ Scan[POSC](?l, rdf:rest, ?tddiphpw) [#891K]
│ `─ Scan[POSC](?i, owl:intersectionOf, ?l) [#332K]
`─ Minus(HashLookup) [#53277.7M]
+─ MergeJoin(?d) [#53277.7M]
│ +─ Scan[POSC](?x, rdf:type, ?d) [#2.2M]
│ `─ Filter(?d != ?d2) [#1.8M]
│ `─ HashJoin(?lvdvlmvc) [#3.6M]
│ +─ Scan[POSC](?lvdvlmvc, rdf:first, ?d) [#891K]
│ `─ HashJoin(?l) [#3.6M]
│ +─ MergeJoin(?gsdohjpd) [#1.8M]
│ │ +─ PropertyPath(?l -> ?gsdohjpd, minLength=0, sortedBy=?gsdohjpd, reversed) [#2.3M]
│ │ │ +─ Distinct [#891K]
│ │ │ │ `─ Projection(?gsdohjpd) [#891K]
│ │ │ │ `─ Scan[PSOC](?gsdohjpd, rdf:first, ?d2) [#891K]
│ │ │ `─ Scan[PSOC](?l, rdf:rest, ?gsdohjpd) [#891K]
│ │ `─ Scan[PSOC](?gsdohjpd, rdf:first, ?d2) [#891K]
│ `─ PropertyPath(?l -> ?lvdvlmvc, minLength=0, sortedBy=?lvdvlmvc, reversed) [#2.3M]
│ +─ Distinct [#891K]
│ │ `─ Projection(?lvdvlmvc) [#891K]
│ │ `─ Scan[PSOC](?lvdvlmvc, rdf:first, ?d) [#891K]
│ `─ Scan[POSC](?l, rdf:rest, ?lvdvlmvc) [#891K]
`─ Scan[PSOC](?x, rdf:type, ?d2) [#2.2M]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment