Semantics is an indispensable aspect of a query language Semantics - - PowerPoint PPT Presentation

semantics is an indispensable aspect of a query language
SMART_READER_LITE
LIVE PREVIEW

Semantics is an indispensable aspect of a query language Semantics - - PowerPoint PPT Presentation

Semantics is an indispensable aspect of a query language Semantics is an indispensable aspect of a query language SELECT Name, Salary FROM Employees WHERE Salary >= 500000 Semantics is an indispensable aspect of a query language SELECT


slide-1
SLIDE 1

Semantics is an indispensable aspect

  • f a query language
slide-2
SLIDE 2

Semantics is an indispensable aspect

  • f a query language

SELECT Name, Salary FROM Employees WHERE Salary >= 500000

slide-3
SLIDE 3

Semantics is an indispensable aspect

  • f a query language

SELECT Name, Salary FROM Employees WHERE Salary >= 500000 πName,Salary

  • σSalary≥500000(Employees)
slide-4
SLIDE 4

RDF data model for the Semantic Web SPARQL query language for RDF (W3C initiatives)

slide-5
SLIDE 5

RDF data model for the Semantic Web SPARQL query language for RDF (W3C initiatives)

RDF Graph:

:name Federico Meza 35-446928 Ricardo Baeza URI 2 :email rbaeza@utalca.cl URI 1 fmeza@utalca.cl :name :email :phone :knows

slide-6
SLIDE 6

RDF data model for the Semantic Web SPARQL query language for RDF (W3C initiatives)

RDF Graph:

:name Federico Meza 35-446928 Ricardo Baeza URI 2 :email rbaeza@utalca.cl URI 1 fmeza@utalca.cl :name :email :phone :knows

SPARQL Query:

SELECT ?N WHERE { ?X :name ?N . }

slide-7
SLIDE 7

RDF data model for the Semantic Web SPARQL query language for RDF (W3C initiatives)

RDF Graph:

:name Federico Meza 35-446928 Ricardo Baeza URI 2 :email rbaeza@utalca.cl URI 1 fmeza@utalca.cl :name :email :phone :knows

SPARQL Query:

SELECT ?N ?E WHERE { ?X :name ?N . ?X :email ?E . }

slide-8
SLIDE 8

RDF data model for the Semantic Web SPARQL query language for RDF (W3C initiatives)

RDF Graph:

:name Federico Meza 35-446928 Ricardo Baeza URI 2 :email rbaeza@utalca.cl URI 1 fmeza@utalca.cl :name :email :phone :knows

SPARQL Query:

SELECT ?N ?E WHERE { ?X :name ?N . ?X :email ?E . ?X :knows ?Y . ?Y :name "Ricardo Baeza" }

slide-9
SLIDE 9

But things can become more complex...

Interesting features of pattern matching on graphs

SELECT ?X1 ?X2 ... WHERE { P1 . P2 }

slide-10
SLIDE 10

But things can become more complex...

Interesting features of pattern matching on graphs

◮ Grouping

SELECT ?X1 ?X2 ... WHERE { { P1 . P2 } { P3 . P4 } }

slide-11
SLIDE 11

But things can become more complex...

Interesting features of pattern matching on graphs

◮ Grouping ◮ Optional parts

SELECT ?X1 ?X2 ... WHERE { { P1 . P2 OPTIONAL { P5 } } { P3 . P4 OPTIONAL { P7 } } }

slide-12
SLIDE 12

But things can become more complex...

Interesting features of pattern matching on graphs

◮ Grouping ◮ Optional parts ◮ Nesting

SELECT ?X1 ?X2 ... WHERE { { P1 . P2 OPTIONAL { P5 } } { P3 . P4 OPTIONAL { P7 OPTIONAL { P8 } } } }

slide-13
SLIDE 13

But things can become more complex...

Interesting features of pattern matching on graphs

◮ Grouping ◮ Optional parts ◮ Nesting ◮ Union of patterns

SELECT ?X1 ?X2 ... WHERE { { P1 . P2 OPTIONAL { P5 } } { P3 . P4 OPTIONAL { P7 OPTIONAL { P8 } } } } UNION { P9 }

slide-14
SLIDE 14

But things can become more complex...

Interesting features of pattern matching on graphs

◮ Grouping ◮ Optional parts ◮ Nesting ◮ Union of patterns ◮ Filtering

SELECT ?X1 ?X2 ... WHERE { { P1 . P2 OPTIONAL { P5 } } { P3 . P4 OPTIONAL { P7 OPTIONAL { P8 } } } } UNION { P9 FILTER ( R ) }

slide-15
SLIDE 15

But things can become more complex...

Interesting features of pattern matching on graphs

◮ Grouping ◮ Optional parts ◮ Nesting ◮ Union of patterns ◮ Filtering ◮ ...

SELECT ?X1 ?X2 ... WHERE { { P1 . P2 OPTIONAL { P5 } } { P3 . P4 OPTIONAL { P7 OPTIONAL { P8 } } } } UNION { P9 FILTER ( R ) }

slide-16
SLIDE 16

But things can become more complex...

Interesting features of pattern matching on graphs

◮ Grouping ◮ Optional parts ◮ Nesting ◮ Union of patterns ◮ Filtering ◮ ...

SELECT ?X1 ?X2 ... WHERE { { P1 . P2 OPTIONAL { P5 } } { P3 . P4 OPTIONAL { P7 OPTIONAL { P8 } } } } UNION { P9 FILTER ( R ) }

What is the meaning of a general SPARQL query?

slide-17
SLIDE 17

The SPARQL W3C specification had no formal semantics!

◮ Specification primarily based on use cases and examples ◮ Semantics given in natural language

slide-18
SLIDE 18

The SPARQL W3C specification had no formal semantics!

◮ Specification primarily based on use cases and examples ◮ Semantics given in natural language ◮ 6 Working Drafts from Feb-2004 to Feb-2006 ◮ Candidate Recommendation in Apr-2006

but still no formal semantics!

slide-19
SLIDE 19

The SPARQL W3C specification had no formal semantics!

◮ Specification primarily based on use cases and examples ◮ Semantics given in natural language ◮ 6 Working Drafts from Feb-2004 to Feb-2006 ◮ Candidate Recommendation in Apr-2006

but still no formal semantics! A formal approach is beneficial to:

◮ Clarify corner cases ◮ Help in the implementation process ◮ Provide sound database foundations

slide-20
SLIDE 20

Semantics and Complexity of SPARQL

Jorge P´ erez

PhD Student Computer Science Department, PUC – Chile Work presented at the International Semantic Web Conference 2006

slide-21
SLIDE 21

W3C SPARQL specification is currently based on our work

W3C document:

◮ Oct-2006 back to working draft ◮ Finally, a recommendation in Jan-2008

incorporating our fomalization

slide-22
SLIDE 22

W3C SPARQL specification is currently based on our work

W3C document:

◮ Oct-2006 back to working draft ◮ Finally, a recommendation in Jan-2008

incorporating our fomalization In our work:

◮ A formal compositional semantics (for graph patterns) ◮ Complexity bounds ◮ Normalization and optimization procedures

slide-23
SLIDE 23

Outline

Motivation Our contributions Syntax and semantics of SPARQL graph patterns Syntax Semantics Complexity results Well–designed graph patterns Complexity Normalization and optimization

slide-24
SLIDE 24

Outline

Motivation Our contributions Syntax and semantics of SPARQL graph patterns Syntax Semantics Complexity results Well–designed graph patterns Complexity Normalization and optimization

slide-25
SLIDE 25

A standard algebraic syntax

◮ Triple patterns: just triples + variables (V )

?X :name "john" (?X, name, john)

◮ Graph patterns: full parenthesized algebra

{ P1 P2 } ( P1 AND P2 ) { P1 OPTIONAL { P2 }} ( P1 OPT P2 ) { P1 } UNION { P2 } ( P1 UNION P2 ) { P1 FILTER ( R ) } ( P1 FILTER R )

  • riginal SPARQL syntax

algebraic syntax

slide-26
SLIDE 26

A standard algebraic syntax (cont.)

◮ Explicit precedence/association

Example

{ t1 t2 OPTIONAL { t3 } OPTIONAL { t4 } t5 }

( ( ( ( t1 AND t2 ) OPT t3 ) OPT t4 ) AND t5 )

slide-27
SLIDE 27

Mappings: building block for the semantics

Definition

A mapping is a partial function from variables to RDF terms. µ : Variables → RDF Terms

slide-28
SLIDE 28

Mappings: building block for the semantics

Definition

A mapping is a partial function from variables to RDF terms. µ : Variables → RDF Terms The evaluation of a pattern results in a set of mappings.

slide-29
SLIDE 29

The semantics of triple patterns

Given an RDF graph G and a triple pattern t

Definition

The evaluation of t over G is the set of mappings µ that:

slide-30
SLIDE 30

The semantics of triple patterns

Given an RDF graph G and a triple pattern t

Definition

The evaluation of t over G is the set of mappings µ that:

◮ make t to match the graph: µ(t) ∈ G

slide-31
SLIDE 31

The semantics of triple patterns

Given an RDF graph G and a triple pattern t

Definition

The evaluation of t over G is the set of mappings µ that:

◮ make t to match the graph: µ(t) ∈ G ◮ have as domain the variables in t: dom(µ) = var(t)

slide-32
SLIDE 32

The semantics of triple patterns

Given an RDF graph G and a triple pattern t

Definition

The evaluation of t over G is the set of mappings µ that:

◮ make t to match the graph: µ(t) ∈ G ◮ have as domain the variables in t: dom(µ) = var(t)

Example

graph triple evaluation (R1, name, john) (R1, email, J@ed.ex) (R2, name, paul) (?X, name, ?Y ) ?X ?Y µ1: R1 john µ2: R2 paul

slide-33
SLIDE 33

The semantics of triple patterns

Given an RDF graph G and a triple pattern t

Definition

The evaluation of t over G is the set of mappings µ that:

◮ make t to match the graph: µ(t) ∈ G ◮ have as domain the variables in t: dom(µ) = var(t)

Example

graph triple evaluation (R1, name, john) (R1, email, J@ed.ex) (R2, name, paul) (?X, name, ?Y ) ?X ?Y µ1: R1 john µ2: R2 paul

slide-34
SLIDE 34

The semantics of triple patterns

Given an RDF graph G and a triple pattern t

Definition

The evaluation of t over G is the set of mappings µ that:

◮ make t to match the graph: µ(t) ∈ G ◮ have as domain the variables in t: dom(µ) = var(t)

Example

graph triple evaluation (R1, name, john) (R1, email, J@ed.ex) (R2, name, paul) (?X, name, ?Y ) ?X ?Y µ1: R1 john µ2: R2 paul

slide-35
SLIDE 35

Compatible mappings: mappings that can be merged.

Definition

Mappings are compatibles if they agree in their common variables.

Example

?X ?Y ?Z ?V µ1 : R1 john µ2 : R1 J@edu.ex µ3 : P@edu.ex R2

slide-36
SLIDE 36

Compatible mappings: mappings that can be merged.

Definition

Mappings are compatibles if they agree in their common variables.

Example

?X ?Y ?Z ?V µ1 : R1 john µ2 : R1 J@edu.ex µ3 : P@edu.ex R2

slide-37
SLIDE 37

Compatible mappings: mappings that can be merged.

Definition

Mappings are compatibles if they agree in their common variables.

Example

?X ?Y ?Z ?V µ1 : R1 john µ2 : R1 J@edu.ex µ3 : P@edu.ex R2 µ1 ∪ µ2 : R1 john J@edu.ex

slide-38
SLIDE 38

Compatible mappings: mappings that can be merged.

Definition

Mappings are compatibles if they agree in their common variables.

Example

?X ?Y ?Z ?V µ1 : R1 john µ2 : R1 J@edu.ex µ3 : P@edu.ex R2 µ1 ∪ µ2 : R1 john J@edu.ex

slide-39
SLIDE 39

Compatible mappings: mappings that can be merged.

Definition

Mappings are compatibles if they agree in their common variables.

Example

?X ?Y ?Z ?V µ1 : R1 john µ2 : R1 J@edu.ex µ3 : P@edu.ex R2 µ1 ∪ µ2 : R1 john J@edu.ex µ1 ∪ µ3 : R1 john P@edu.ex R2

slide-40
SLIDE 40

Compatible mappings: mappings that can be merged.

Definition

Mappings are compatibles if they agree in their common variables.

Example

?X ?Y ?Z ?V µ1 : R1 john µ2 : R1 J@edu.ex µ3 : P@edu.ex R2 µ1 ∪ µ2 : R1 john J@edu.ex µ1 ∪ µ3 : R1 john P@edu.ex R2

◮ µ2 and µ3 are not compatible

slide-41
SLIDE 41

Sets of mappings and operations

Let M1 and M2 be sets of mappings:

Definition

slide-42
SLIDE 42

Sets of mappings and operations

Let M1 and M2 be sets of mappings:

Definition

Join: extends mappings in M1 with compatible mappings in M2

slide-43
SLIDE 43

Sets of mappings and operations

Let M1 and M2 be sets of mappings:

Definition

Join: extends mappings in M1 with compatible mappings in M2

◮ M1 ⋊

⋉ M2 = {µ1 ∪ µ2 | µ1 ∈ M1, µ2 ∈ M2, and µ1, µ2 are compatible}

slide-44
SLIDE 44

Sets of mappings and operations

Let M1 and M2 be sets of mappings:

Definition

Join: extends mappings in M1 with compatible mappings in M2

◮ M1 ⋊

⋉ M2 = {µ1 ∪ µ2 | µ1 ∈ M1, µ2 ∈ M2, and µ1, µ2 are compatible} Difference: selects mappings in M1 that cannot be extended with mappings in M2

slide-45
SLIDE 45

Sets of mappings and operations

Let M1 and M2 be sets of mappings:

Definition

Join: extends mappings in M1 with compatible mappings in M2

◮ M1 ⋊

⋉ M2 = {µ1 ∪ µ2 | µ1 ∈ M1, µ2 ∈ M2, and µ1, µ2 are compatible} Difference: selects mappings in M1 that cannot be extended with mappings in M2

◮ M1 M2 = {µ1 ∈ M1 | there is no mapping µ2 ∈ M2

compatible with µ1}

slide-46
SLIDE 46

Sets of mappings and operations

Let M1 and M2 be sets of mappings:

Definition

slide-47
SLIDE 47

Sets of mappings and operations

Let M1 and M2 be sets of mappings:

Definition

Union: includes mappings in M1 plus mappings in M2 (set union)

◮ M1 ∪ M2 = {µ | µ ∈ M1 or µ ∈ M2}

slide-48
SLIDE 48

Sets of mappings and operations

Let M1 and M2 be sets of mappings:

Definition

Union: includes mappings in M1 plus mappings in M2 (set union)

◮ M1 ∪ M2 = {µ | µ ∈ M1 or µ ∈ M2}

Left Outer Join: considers mappings in M1 extending them with compatible mappings in M2 whenever it is possible

◮ M1

M2 = (M1 ⋊ ⋉ M2) ∪ (M1 M2)

slide-49
SLIDE 49

Semantics in terms of operations between evaluations

Let M1 and M2 be the evaluation of P1 and P2.

Definition

The evaluation of: (P1 AND P2) → (P1 UNION P2) → (P1 OPT P2) →

slide-50
SLIDE 50

Semantics in terms of operations between evaluations

Let M1 and M2 be the evaluation of P1 and P2.

Definition

The evaluation of: (P1 AND P2) → M1 ⋊ ⋉ M2 (P1 UNION P2) → (P1 OPT P2) →

slide-51
SLIDE 51

Semantics in terms of operations between evaluations

Let M1 and M2 be the evaluation of P1 and P2.

Definition

The evaluation of: (P1 AND P2) → M1 ⋊ ⋉ M2 (P1 UNION P2) → M1 ∪ M2 (P1 OPT P2) →

slide-52
SLIDE 52

Semantics in terms of operations between evaluations

Let M1 and M2 be the evaluation of P1 and P2.

Definition

The evaluation of: (P1 AND P2) → M1 ⋊ ⋉ M2 (P1 UNION P2) → M1 ∪ M2 (P1 OPT P2) → M1 M2

slide-53
SLIDE 53

Simple example

Example

(R1, name, john) (R1, email, J@ed.ex) (R2, name, paul) ( (?X, name, ?Y ) OPT (?X, email, ?E) )

slide-54
SLIDE 54

Simple example

Example

(R1, name, john) (R1, email, J@ed.ex) (R2, name, paul) ( (?X, name, ?Y ) OPT (?X, email, ?E) )

slide-55
SLIDE 55

Simple example

Example

(R1, name, john) (R1, email, J@ed.ex) (R2, name, paul) ( (?X, name, ?Y ) OPT (?X, email, ?E) ) ?X ?Y R1 john R2 paul

slide-56
SLIDE 56

Simple example

Example

(R1, name, john) (R1, email, J@ed.ex) (R2, name, paul) ( (?X, name, ?Y ) OPT (?X, email, ?E) ) ?X ?Y R1 john R2 paul

slide-57
SLIDE 57

Simple example

Example

(R1, name, john) (R1, email, J@ed.ex) (R2, name, paul) ( (?X, name, ?Y ) OPT (?X, email, ?E) ) ?X ?Y R1 john R2 paul ?X ?E R1 J@ed.ex

slide-58
SLIDE 58

Simple example

Example

(R1, name, john) (R1, email, J@ed.ex) (R2, name, paul) ( (?X, name, ?Y ) OPT (?X, email, ?E) ) ?X ?Y R1 john R2 paul ?X ?E R1 J@ed.ex

slide-59
SLIDE 59

Simple example

Example

(R1, name, john) (R1, email, J@ed.ex) (R2, name, paul) ( (?X, name, ?Y ) OPT (?X, email, ?E) ) ?X ?Y R1 john R2 paul ?X ?Y ?E R1 john J@ed.ex R2 paul ?X ?E R1 J@ed.ex

slide-60
SLIDE 60

Simple example

Example

(R1, name, john) (R1, email, J@ed.ex) (R2, name, paul) ( (?X, name, ?Y ) OPT (?X, email, ?E) ) ?X ?Y R1 john R2 paul ?X ?Y ?E R1 john J@ed.ex R2 paul ?X ?E R1 J@ed.ex

◮ from the Join

slide-61
SLIDE 61

Simple example

Example

(R1, name, john) (R1, email, J@ed.ex) (R2, name, paul) ( (?X, name, ?Y ) OPT (?X, email, ?E) ) ?X ?Y R1 john R2 paul ?X ?Y ?E R1 john J@ed.ex R2 paul ?X ?E R1 J@ed.ex

◮ from the Join ◮ from the Difference

slide-62
SLIDE 62

Simple example

Example

(R1, name, john) (R1, email, J@ed.ex) (R2, name, paul) ( (?X, name, ?Y ) OPT (?X, email, ?E) ) ?X ?Y R1 john R2 paul ?X ?Y ?E R1 john J@ed.ex R2 paul ?X ?E R1 J@ed.ex

◮ from the Join ◮ from the Difference ◮ from the Union

slide-63
SLIDE 63

Boolean filter expressions (value constraints)

In filter expressions we consider

◮ equality (=) among variables and RDF terms ◮ unary predicate bound ◮ boolean combinations (∧, ∨, ¬)

slide-64
SLIDE 64

Satisfaction of value constraints

A mapping satisfies

◮ ?X = c if it gives the value c to variable ?X ◮ ?X =?Y if it gives the same value to ?X and ?Y ◮ bound(?X) if it is defined for ?X

slide-65
SLIDE 65

Satisfaction of value constraints

A mapping satisfies

◮ ?X = c if it gives the value c to variable ?X ◮ ?X =?Y if it gives the same value to ?X and ?Y ◮ bound(?X) if it is defined for ?X

Definition

The evaluation of (P FILTER R):

◮ mappings in the evaluation of P that satisfy R.

slide-66
SLIDE 66

It was not that difficult to define a formal semantics for SPARQL

slide-67
SLIDE 67

It was not that difficult to define a formal semantics for SPARQL

Key aspects:

◮ use partial mappings for individual solutions ◮ adapt classical operators to deal with partial mappings

slide-68
SLIDE 68

Outline

Motivation Our contributions Syntax and semantics of SPARQL graph patterns Syntax Semantics Complexity results Well–designed graph patterns Complexity Normalization and optimization

slide-69
SLIDE 69

The evaluation decision problem

INPUT:

A mapping, a graph pattern, and an RDF graph.

OUTPUT:

Is the mapping in the evaluation of the pattern over the graph?

slide-70
SLIDE 70

Evaluation of simple patterns is polynomial.

Theorem

For patterns using only AND and FILTER operators, the evaluation problem is polynomial: O(size of the pattern × size of the graph).

slide-71
SLIDE 71

Evaluation of simple patterns is polynomial.

Theorem

For patterns using only AND and FILTER operators, the evaluation problem is polynomial: O(size of the pattern × size of the graph).

Proof idea

◮ Check that the mapping makes every triple to match. ◮ Then check that the mapping satisfies the FILTERs.

slide-72
SLIDE 72

Evaluation including UNION is NP-complete.

Theorem

For patterns using AND, FILTER and UNION operators, the evaluation problem is NP-complete.

slide-73
SLIDE 73

Evaluation including UNION is NP-complete.

Theorem

For patterns using AND, FILTER and UNION operators, the evaluation problem is NP-complete.

Proof idea

◮ Reduction from propositional SAT ◮ The pattern codifies a propositional formula.

slide-74
SLIDE 74

Evaluation including UNION is NP-complete.

Theorem

For patterns using AND, FILTER and UNION operators, the evaluation problem is NP-complete.

Proof idea

◮ Reduction from propositional SAT ◮ The pattern codifies a propositional formula. ◮ Using ¬ bound to codify negation.

slide-75
SLIDE 75

A simple normal from

Theorem (UNION Normal Form)

Every graph pattern is equivalent to one of the form P1 UNION P2 UNION · · · UNION Pn with Pi UNION–free.

slide-76
SLIDE 76

A simple normal from

Theorem (UNION Normal Form)

Every graph pattern is equivalent to one of the form P1 UNION P2 UNION · · · UNION Pn with Pi UNION–free.

Theorem

The evaluation problem for AND-FILTER-UNION patterns in UNION normal form, is polynomial.

slide-77
SLIDE 77

Evaluation in general is PSPACE-complete.

Theorem

For general patterns that include OPT operator, the evaluation problem is PSPACE-complete.

slide-78
SLIDE 78

Evaluation in general is PSPACE-complete.

Theorem

For general patterns that include OPT operator, the evaluation problem is PSPACE-complete.

◮ still PSPACE-complete for AND-FILTER-OPT patterns

slide-79
SLIDE 79

Evaluation in general is PSPACE-complete.

Theorem

For general patterns that include OPT operator, the evaluation problem is PSPACE-complete.

◮ still PSPACE-complete for AND-FILTER-OPT patterns

Proof idea

◮ Reduction from propositional quantified SAT ◮ The pattern codifies a quantified formula

∀x1∃x2∀x3 · · · ϕ.

slide-80
SLIDE 80

Evaluation in general is PSPACE-complete.

Theorem

For general patterns that include OPT operator, the evaluation problem is PSPACE-complete.

◮ still PSPACE-complete for AND-FILTER-OPT patterns

Proof idea

◮ Reduction from propositional quantified SAT ◮ The pattern codifies a quantified formula

∀x1∃x2∀x3 · · · ϕ.

◮ Using nested OPTs to codify quantifier alternations.

slide-81
SLIDE 81

Outline

Motivation Our contributions Syntax and semantics of SPARQL graph patterns Syntax Semantics Complexity results Well–designed graph patterns Complexity Normalization and optimization

slide-82
SLIDE 82

Well–designed patterns

Definition

An AND-FILTER-OPT pattern is well–designed iff for every OPT in the pattern

( · · · · · · · · · · · · ( A OPT B ) · · · · · · · · · · · · )

if a variable occurs

slide-83
SLIDE 83

Well–designed patterns

Definition

An AND-FILTER-OPT pattern is well–designed iff for every OPT in the pattern

( · · · · · · · · · · · · ( A OPT B ) · · · · · · · · · · · · ) ↑

if a variable occurs inside B

slide-84
SLIDE 84

Well–designed patterns

Definition

An AND-FILTER-OPT pattern is well–designed iff for every OPT in the pattern

( · · · · · · · · · · · · ( A OPT B ) · · · · · · · · · · · · ) ↑ ↑ ↑

if a variable occurs inside B and anywhere outside the OPT,

slide-85
SLIDE 85

Well–designed patterns

Definition

An AND-FILTER-OPT pattern is well–designed iff for every OPT in the pattern

( · · · · · · · · · · · · ( A OPT B ) · · · · · · · · · · · · ) ↑ ⇑ ↑ ↑

if a variable occurs inside B and anywhere outside the OPT, then the variable must also occur inside A.

slide-86
SLIDE 86

Well–designed patterns

Definition

An AND-FILTER-OPT pattern is well–designed iff for every OPT in the pattern

( · · · · · · · · · · · · ( A OPT B ) · · · · · · · · · · · · ) ↑ ⇑ ↑ ↑

if a variable occurs inside B and anywhere outside the OPT, then the variable must also occur inside A.

Example

(?Y , name, paul) OPT (?X, email, ?Z)

  • AND

(?X, name, john)

slide-87
SLIDE 87

Well–designed patterns

Definition

An AND-FILTER-OPT pattern is well–designed iff for every OPT in the pattern

( · · · · · · · · · · · · ( A OPT B ) · · · · · · · · · · · · ) ↑ ⇑ ↑ ↑

if a variable occurs inside B and anywhere outside the OPT, then the variable must also occur inside A.

Example

(?Y , name, paul) OPT (?X, email, ?Z)

  • AND

(?X, name, john)

slide-88
SLIDE 88

Well–designed patterns

Definition

An AND-FILTER-OPT pattern is well–designed iff for every OPT in the pattern

( · · · · · · · · · · · · ( A OPT B ) · · · · · · · · · · · · ) ↑ ⇑ ↑ ↑

if a variable occurs inside B and anywhere outside the OPT, then the variable must also occur inside A.

Example

(?Y , name, paul) OPT (?X, email, ?Z)

  • AND

(?X, name, john)

slide-89
SLIDE 89

Well–designed patterns

Definition

An AND-FILTER-OPT pattern is well–designed iff for every OPT in the pattern

( · · · · · · · · · · · · ( A OPT B ) · · · · · · · · · · · · ) ↑ ⇑ ↑ ↑

if a variable occurs inside B and anywhere outside the OPT, then the variable must also occur inside A.

Example

(?Y , name, paul) OPT (?X, email, ?Z)

  • AND

(?X, name, john)

slide-90
SLIDE 90

Well–designed patterns

Definition

An AND-FILTER-OPT pattern is well–designed iff for every OPT in the pattern

( · · · · · · · · · · · · ( A OPT B ) · · · · · · · · · · · · ) ↑ ⇑ ↑ ↑

if a variable occurs inside B and anywhere outside the OPT, then the variable must also occur inside A.

Example

(?Y , name, paul) OPT (?X, email, ?Z)

  • AND

(?X, name, john)

◮ Well-designed patterns initially proposed to show equivalence

with a procedural semantics (by W3C)

slide-91
SLIDE 91

Evaluation of well-designed patterns is in coNP-complete

Theorem

For AND-FILTER-OPT well–designed graph patterns the evaluation problem is coNP-complete

slide-92
SLIDE 92

Evaluation of well-designed patterns is in coNP-complete

Theorem

For AND-FILTER-OPT well–designed graph patterns the evaluation problem is coNP-complete

Corollary

For patterns of the form P1 UNION P2 UNION · · · UNION Pk where every Pi is a UNION-free well-designed pattern, the evaluation problem is coNP-complete

slide-93
SLIDE 93

Classical optimization is not directly applicable.

◮ Classical optimization assumes null–rejection.

slide-94
SLIDE 94

Classical optimization is not directly applicable.

◮ Classical optimization assumes null–rejection.

◮ null–rejection: the join/outer–join condition must fail in the

presence of null.

slide-95
SLIDE 95

Classical optimization is not directly applicable.

◮ Classical optimization assumes null–rejection.

◮ null–rejection: the join/outer–join condition must fail in the

presence of null.

◮ SPARQL operations are never null–rejecting

◮ by definition of compatible mappings.

slide-96
SLIDE 96

Classical optimization is not directly applicable.

◮ Classical optimization assumes null–rejection.

◮ null–rejection: the join/outer–join condition must fail in the

presence of null.

◮ SPARQL operations are never null–rejecting

◮ by definition of compatible mappings.

◮ Can we use classical optimization in the context of SPARQL?

slide-97
SLIDE 97

Classical optimization is not directly applicable.

◮ Classical optimization assumes null–rejection.

◮ null–rejection: the join/outer–join condition must fail in the

presence of null.

◮ SPARQL operations are never null–rejecting

◮ by definition of compatible mappings.

◮ Can we use classical optimization in the context of SPARQL?

◮ Well-designed patterns are suitable for reordering, and then for

classical optimization.

slide-98
SLIDE 98

Well–designed graph patterns and optimization

Consider the following rules:

((P1 OPT P2) FILTER R) − → ((P1 FILTER R) OPT P2) (1) (P1 AND (P2 OPT P3)) − → ((P1 AND P2) OPT P3) (2) ((P1 OPT P2) AND P3) − → ((P1 AND P3) OPT P2) (3)

slide-99
SLIDE 99

Well–designed graph patterns and optimization

Consider the following rules:

((P1 OPT P2) FILTER R) − → ((P1 FILTER R) OPT P2) (1) (P1 AND (P2 OPT P3)) − → ((P1 AND P2) OPT P3) (2) ((P1 OPT P2) AND P3) − → ((P1 AND P3) OPT P2) (3)

Proposition

If P is a well-designed pattern and Q is obtained from P by applying either (1) or (2) or (3), then Q is a well-designed pattern equivalent to P.

slide-100
SLIDE 100

Well–designed graph patterns and optimization

Definition

A graph pattern P is in OPT normal form if there exist AND-FILTER patterns Q1, . . ., Qk such that: P is constructed from Q1, . . ., Qk by using only the OPT operator.

slide-101
SLIDE 101

Well–designed graph patterns and optimization

Definition

A graph pattern P is in OPT normal form if there exist AND-FILTER patterns Q1, . . ., Qk such that: P is constructed from Q1, . . ., Qk by using only the OPT operator.

Theorem

Every well-designed pattern is equivalent to a pattern in OPT normal form.

slide-102
SLIDE 102

Summary

◮ A formal compositional semantics for SPARQL ◮ Complexity bounds ◮ Normalization and initial optimizations procedures

slide-103
SLIDE 103

Summary

◮ A formal compositional semantics for SPARQL ◮ Complexity bounds ◮ Normalization and initial optimizations procedures

Impact:

◮ Official semantics for SPARQL by W3C based on our work ◮ Base of the theoretical studies around SPARQL ◮ Journal version published in ACM TODS 2009

slide-104
SLIDE 104

Semantics and Complexity of SPARQL

Jorge P´ erez

PhD Student Computer Science Department, PUC – Chile Work presented at the International Semantic Web Conference 2006