Presentation is loading. Please wait.

Presentation is loading. Please wait.

Database Techniques for Linked Data Management SIGMOD 2012 Andreas Harth 1, Katja Hose 2, Ralf Schenkel 2,3 1 Karlsruhe Instititute of Technology 2 Max.

Similar presentations


Presentation on theme: "Database Techniques for Linked Data Management SIGMOD 2012 Andreas Harth 1, Katja Hose 2, Ralf Schenkel 2,3 1 Karlsruhe Instititute of Technology 2 Max."— Presentation transcript:

1 Database Techniques for Linked Data Management SIGMOD 2012 Andreas Harth 1, Katja Hose 2, Ralf Schenkel 2,3 1 Karlsruhe Instititute of Technology 2 Max Planck Institute for Informatics, Saarbrücken 3 Saarland University, Saarbrücken

2 Outline for Part II Part II.1: Foundations –A short overview of SPARQL Part II.2: Rowstore Solutions Part II.3: Columnstore Solutions Part II.4: Other Solutions and Outlook

3 SPARQL Query language for RDF from the W3C Main component: –select-project-join combination of triple patterns graph pattern queries on the knowledge base

4 SPARQL – Example Example query: Find all actors from Ontario (that are in the knowledge base) vegetarian Albert_Einstein physicist Jim_Carrey actor Ontario Canada Ulm Germany scientist chemist Otto_Hahn Frankfurt Mike_Myers NewmarketScarborough Europe isA bornIn locatedIn isA

5 Semantic Knowledge Bases from Web Sources 5 SPARQL – Example Example query: Find all actors from Ontario (that are in the knowledge base) vegetarian Albert_Einstein physicist Jim_Carrey actor Ontario Canada Ulm Germany scientist chemist Otto_Hahn Frankfurt Mike_Myers NewmarketScarborough Europe isA bornIn locatedIn isA actor Ontario ?person ?loc bornIn locatedIn isA Find subgraphs of this form: variables constants SELECT ?person WHERE ?person isA actor. ?person bornIn ?loc. ?loc locatedIn Ontario.

6 Eliminate duplicates in results Return results in some order with optional LIMIT n clause Optional matches and filters on bounded vars More operators: ASK, DESCRIBE, CONSTRUCT SPARQL – More Features SELECT DISTINCT ?c WHERE {?person isA actor. ?person bornIn ?loc. ?loc locatedIn ?c} SELECT ?person WHERE {?person isA actor. ?person bornIn ?loc. ?loc locatedIn Ontario} ORDER BY DESC(?person) SELECT ?person WHERE {?person isA actor. OPTIONAL{?person bornIn ?loc}. FILTER (!BOUND(?loc))}

7 SPARQL: Extensions from W3C W3C SPARQL 1.1 draft: Aggregations (COUNT, AVG, …) Subqueries Negation: syntactic sugar for OPTIONAL {?x … } FILTER(!BOUND(?x)) Regular path expressions Updates

8 Why care about scalability? Rapid growth of available semantic data > 31 billion triples in the LOD cloud, 325 sources DBPedia: 3.6 million entities, 1.2 billion triples

9 … and growing Billion triple challenge 2008: 1B triples Billion triple challenge 2010: 3B triples http://km.aifb.kit.edu/projects/btc-2010/ http://km.aifb.kit.edu/projects/btc-2010/ Billion triple challenge 2011: 2B triples http://km.aifb.kit.edu/projects/btc-2011/ http://km.aifb.kit.edu/projects/btc-2011/ War stories from http://www.w3.org/wiki/LargeTripleStores: http://www.w3.org/wiki/LargeTripleStores –BigOWLIM: 12B triples in Jun 2009 –Garlik 4store: 15B triples in Oct 2009 –OpenLink Virtuoso: 15.4B+ triples –AllegroGraph: 1+ Trillion triples

10 Queries can be complex, too SELECT DISTINCT ?a ?b ?lat ?long WHERE { ?a dbpedia:spouse ?b. ?a dbpedia:wikilink dbpediares:actor. ?b dbpedia:wikilink dbpediares:actor. ?a dbpedia:placeOfBirth ?c. ?b dbpedia:placeOfBirth ?c. ?c owl:sameAs ?c2. ?c2 pos:lat ?lat. ?c2 pos:long ?long. } Q7 on BTC2008 in [Neumann & Weikum, 2009]

11 Outline for Part II Part II.1: Foundations –A short overview of SPARQL Part II.2: Rowstore Solutions Part II.3: Columnstore Solutions Part II.4: Other Solutions and Outlook

12 RDF in Row Stores Rowstore: general relational database storing relations as complete rows (MySQL, PostgreSQL, Oracle, DB2, SQLServer, …) General principles: –store triples in one giant three-attribute table (subject, predicate, object) –convert SPARQL to equivalent SQL –The database will do the rest Strings often mapped to unique integer IDs Used by many TripleStores, including 3Store, Jena, HexaStore, RDF-3X, … Simple extension to quadruples (with graphid): (graph,subject,predicate,object) We consider only triples for simplicity!

13 Example: Triple Table ex:Katjaex:teaches ex:Databases; ex:works_for ex:MPI_Informatics; ex:PhD_from ex:TU_Ilmenau. ex:Andreas ex:teaches ex:Databases; ex:works_for ex:KIT; ex:PhD_from ex:DERI. ex:Ralf ex:teaches ex:Information_Retrieval; ex:PhD_from ex:Saarland_University; ex:works_for ex:Saarland_University, ex:MPI_Informatics. subject predicate object ex:Katjaex:teaches ex:Databases ex:Katjaex:works_for ex:MPI_Informatics ex:Katja ex:PhD_from ex:TU_Ilmenau ex:Andreas ex:teaches ex:Databases ex:Andreas ex:works_for ex:KIT ex:Andreas ex:PhD_from ex:DERI ex:Ralf ex:teaches ex:Information_Retrieval ex:Ralf ex:PhD_from ex:Saarland_University ex:Ralf ex:works_for ex:Saarland_University ex:Ralf ex:works_for ex:MPI_Informatics

14 Conversion of SPARQL to SQL General approach: One copy of the triple table for each triple pattern Constants in patterns create constraints Common variables across patterns create joins FILTER conditions create constraints OPTIONAL clauses create outer joins UNION clauses create union expressions

15 SELECT FROM Triples P1, Triples P2, Triples P3 Example: Conversion to SQL Query SELECT ?a ?b ?t WHERE {?a works_for ?u. ?b works_for ?u. ?a phd_from ?u. } OPTIONAL {?a teaches ?t} FILTER (regex(?u,“Saar“)) SELECT FROM Triples P1, Triples P2, Triples P3 WHERE P1.predicate=„works_for“ AND P2.predicate=„works_for“ AND P3.predicate=„phd_from“ SELECT FROM Triples P1, Triples P2, Triples P3 WHERE P1.predicate=„works_for“ AND P2.predicate=„works_for“ AND P3.predicate=„phd_from“ AND P1.object=P2.object AND P1.subject=P3.subject AND P1.object=P3.object SELECT FROM Triples P1, Triples P2, Triples P3 WHERE P1.predicate=„works_for“ AND P2.predicate=„works_for“ AND P3.predicate=„phd_from“ AND P1.object=P2.object AND P1.subject=P3.subject AND P1.object=P3.object AND REGEXP_LIKE(P1.object,“%Saar%“) SELECT P1.subject as A, P2.subject as B FROM Triples P1, Triples P2, Triples P3 WHERE P1.predicate=„works_for“ AND P2.predicate=„works_for“ AND P3.predicate=„phd_from“ AND P1.object=P2.object AND P1.subject=P3.subject AND P1.object=P3.object AND REGEXP_LIKE(P1.object,“%Saar%“) SELECT R1.A, R1.B, R2.T FROM ( SELECT P1.subject as A, P2.subject as B FROM Triples P1, Triples P2, Triples P3 WHERE P1.predicate=„works_for“ AND P2.predicate=„works_for“ AND P3.predicate=„phd_from“ AND P1.object=P2.object AND P1.subject=P3.subject AND P1.object=P3.object AND REGEXP_LIKE(P1.object,“%Saar%“) ) R1 LEFT OUTER JOIN ( SELECT P4.subject as A, P4.object as T FROM Triples P4 WHERE P4.predicate=„teaches“) AS R2 ) ON (R1.A=R2.A)  P1 P2 P3 P4   Filter Projection ?u ?a,?u ?a

16 Is that all? No. Which indexes should be built? (to support evaluation of triple patterns) How can we reduce storage space? How can we find the best execution plan? Existing databases need modifications: flexible, extensible, generic storage not needed here cannot deal with multiple self-joins of a single table often generate bad execution plans

17 Dictionary for Strings Map all strings to unique integers (e.g., hashing) Regular size, much easier to handle & compress Map small, can be kept in main memory 194760 679375 4634 This breaks natural sorting order  FILTER conditions may be more expensive!

18 Indexes for commonly used triple patterns Patterns with a single variable are frequent Example: Albert_Einstein invented ?x  Build clustered index over (s,p,o) Can also be used for pattern like Albert_Einstein ?p ?x Build similar clustered indexes for all six combinations: SPO, POS, OSP to cover all possible patterns SOP, OPS, PSO to have all sort orders for patterns with two vars (16,19,5356) (16,24,567) (16,24,876) (27,19,643) (27,48,10486) (50,10,10456) … All triples in (s,p,o) order B+ tree for easy access 1.Lookup ids for constants: Albert_Einstein=16, invented=24 2.Lookup known prefix in index: (16,24,0) 3.Read results while prefix matches: (16,24,567), (16,24,876) come already sorted! Triple table no longer needed, all triples in each index

19 Why sort order matters for joins  (16,19,5356) (16,24,567) (16,24,876) (27,19,643) (27,48,10486) (50,10,10456) (16,33,46578) (16,56,1345) (24,16,1353) (27,18,133) (47,37,20495) (50,134,1056) MJ When inputs sorted by join attribute, use Merge Join: sequentially scan both inputs immediately join matching triples skip over parts without matches allows pipelining When inputs are unsorted/sorted by wrong attribute, use Hash Join: build hash table from one input scan other input, probe hash table needs to touch every input triple breaks pipelining  (16,19,5356) (16,24,567) (16,24,876) (27,19,643) (27,48,10486) (50,10,10456) (27,18,133) (50,134,1056) (16,56,1345) (24,16,1353) (47,37,20495) (16,33,46578) HJ In general, Merge Joins are more preferrable: small memory footprint, pipelining

20 Even More Indexes SPARQL considers duplicates (unless removed with DISTINCT) and does not (yet) support aggregates/counting  often queries with many duplicates like SELECT ?x WHERE ?x ?y Germany. to retrieve entities related to Germany (but counts may be important in the application!)  this materializes many identical intermediate results Solution: Precompute aggregated indexes SP,SO,PO,PS,OP,OS,S,P,O Ex: SO contains, for each pair (s,o), the number of triples with subject s and object o Do not materialize identical bindings, but keep counts Ex: ?x=Albert_Einstein:4; ?x=Angela_Merkel:10

21 Compression to Reduce Storage Space Compress sequences of triples in lexicographic order (v1;v2;v3); for SPO, v1=S, v2=P, v3=O Step 1: compute per-attribute deltas Step 2: encode each delta triple separately in 1-13 bytes (16,19,5356) (16,24,567) (16,24,676) (27,19,643) (27,48,10486) (50,10,10456) (16,19,5356) (0,5,-4798) (0,0,109) (11,-5,-34) (0,29,9843) (23,-38,-30)  gap bit header (7 bits) Delta of value 2 (0-4 bytes) Delta of value 3 (0-4 bytes) When gap=1, the delta of value3 is included in header, all others are 0 Otherwise, header contains length of encoding for each of the three deltas (5*5*5=125 combinations)

22 Compression Effectiveness and Efficiency Byte-level encoding almost as effectiv as bit-level encoding techniques (Gamma, Delta, Golomb) Much faster (10x) for decompressing Example for Barton dataset (Neumann & Weikum 2010): –Raw data 51 million triples, 7GB uncompressed (as N-Triples) –All 6 main indexes: 1.1GB size, 3.2s decompression with byte-level encoding 1.06GB size, 42.5s decompression with Delta encoding Additional compression with LZ77 2x more compact, but much slower to decompress Compression always on page level

23  POS(works_for,?u,?a) POS(pdh_from,?u,?a) PSO(works_for,?u,?b)   Filter Projection ?u,?a ?u ?a MJ Back to the Example Query SELECT ?a ?b ?t WHERE {?a works_for ?u. ?b works_for ?u. ?a phd_from ?u. } OPTIONAL {?a teaches ?t} FILTER (regex(?u,“Saar“))  POS(works_for,?u,?a) POS(works_for,?u,?b) PSO(phd_from,?a,?u) POS(teaches,?a,?t)   Filter Projection ?u ?a,?u ?a MJ HJ POS(teaches,?a,?t) Which of the two plans is better? How many intermediate results? 1000 100 50 5 2500 250 Core ingredients of a good query optimizer are selectivity estimators for triple patterns and joins

24 Selectivity Estimation for Triple Patterns How many results will a triple pattern have? Standard databases: per-attribute histograms Assume independence of attributes  Use aggregated indexes for exact count Additional join statistics for blocks of triples: too simplistic and inexact … (16,19,5356) (16,24,567) (16,24,876) (27,19,643) (27,48,10486) (50,10,10456) … Assume independence between triple patterns; additionally precompute exact statistics for frequent paths in the data

25 Outline for Part II Part II.1: Foundations –A short overview of SPARQL Part II.2: Rowstore Solutions Part II.3: Columnstore Solutions Part II.4: Other Solutions and Outlook

26 Principles Observations and Assumptions: Not too many different predicates Triple patterns usually have fixed predicate Need to access all triples with one predicate Design consequence: Use one two-attribute table for each predicate Example Systems: SWStore, MonetDB

27 Example: Column Stores ex:Katjaex:teaches ex:Databases; ex:works_for ex:MPI_Informatics; ex:PhD_from ex:TU_Ilmenau. ex:Andreas ex:teaches ex:Databases; ex:works_for ex:KIT; ex:PhD_from ex:DERI. ex:Ralf ex:teaches ex:Information_Retrieval; ex:PhD_from ex:Saarland_University; ex:works_for ex:Saarland_University, ex:MPI_Informatics. subject object ex:Katjaex:TU_Ilmenau ex:Andreas ex:DERI ex:Ralf ex:Saarland_University PhD_from subject object ex:Katjaex:MPI_Informatics ex:Andreas ex:DERI ex:Ralf ex:Saarland_University ex:Ralfex:MPI_Informatics works_for subject object ex:Katjaex:Databases ex:Andreas ex:Databases ex:Ralf ex:Information_Retrieval teaches

28 Simplified Example: Query Conversion SELECT ?a ?b ?t WHERE {?a works_for ?u. ?b works_for ?u. ?a phd_from ?u. } SELECT W1.subject as A, W2.subject as B FROM works_for W1, works_for W2, phd_from P3 WHERE W1.object=W2.object AND W1.subject=P3.subject AND W1.object=P3.object So far, this is yet another relational representation of RDF. Now what are Column-Stores?

29 Column-Stores and RDF Columnstores store columns of a table separately. subject object ex:Katjaex:TU_Ilmenau ex:Andreas ex:DERI ex:Ralf ex:Saarland_University PhD_from PhD_from:subject ex:Katja ex:Andreas ex:Ralf PhD_from:object ex:TU_Ilmenau ex:DERI ex:Saarland_University Advantages: Fast if only subject or object are accessed, not both Allows for a very compact representation Problems: Need to recombine columns if subject and object are accessed Inefficient for triple patterns with predicate variable

30 Compression in Column-Stores General ideas: Store subject only once Use same order of subjects for all columns, including NULL values when necessary Additional compression to get rid of NULL values subject ex:Katja ex:Andreas ex:Ralf PhD_from ex:TU_Ilmenau ex:DERI ex:Saarland_University NULL works_for ex:MPI_Informatics ex:KIT ex:Saarland_University ex:MPI_Informatics teaches ex:Databases ex:Databases ex:Information_Retrieval NULL PhD_from: bit[1110] ex:TU_Ilmenau ex:DERI ex:Saarland_University Teaches: range[1-3] ex:Databases ex:Databases ex:Information_Retrieval

31 Outline for Part II Part II.1: Foundations –A short overview of SPARQL Part II.2: Rowstore Solutions Part II.3: Columnstore Solutions Part II.4: Other Solutions and Outlook

32 Property Tables Group entities with similar predicates in a relational table (for example using types or a clustering algorithm) ex:Katjaex:teaches ex:Databases; ex:works_for ex:MPI_Informatics; ex:PhD_from ex:TU_Ilmenau. ex:Andreas ex:teaches ex:Databases; ex:works_for ex:KIT; ex:PhD_from ex:DERI. ex:Ralf ex:teaches ex:Information_Retrieval; ex:PhD_from ex:Saarland_University; ex:works_for ex:Saarland_University, ex:MPI_Informatics. subject teaches PhD_from ex:Katjaex:Databasesex:TU_Ilmenau ex:Andreas ex:Databasesex:DERI ex:Ralf ex:IRex:Saarland_University subject teaches PhD_from ex:Katjaex:Databasesex:TU_Ilmenau ex:Andreas ex:Databasesex:DERI ex:Ralf ex:IRex:Saarland_University ex:AxelNULLex:TU_Vienna subject predicate object ex:Katjaex:works_for ex:MPI_Informatics ex:Andreas ex:works_for ex:KIT ex:Ralf ex:works_for ex:Saarland_University ex:Ralf ex:works_for ex:MPI_Informatics „Leftover triples“

33 Property Tables: Pros and Cons Advantages: More in the spirit of existing relational systems Saves many self-joins over triple tables etc. Disadvantages: Potentially many NULL values Multi-value attributes problematic Query mapping depends on schema Schema changes very expensive

34 Even More Systems… Store RDF data as matrix with bit-vector compression Convert RDF into XML and use XML methods (XPath, XQuery, …) Store RDF data in graph databases … See proceedings for pointers See also our tutorial at Reasoning Web 2011

35 Which technique is best? Performance depends a lot on precomputation, optimization, implementation Comparative results on BTC 2008 (from [Neumann & Weikum, 2009]): RDF-3X RDF-3X (2008) COLSTORE ROWSTORE RDF-3X RDF-3X (2008) COLSTORE ROWSTORE

36 Challenges and Opportunities SPARQL with different entailment regimes („query-time inference“) Upcoming SPARQL 1.1 features (grouping, aggregation, updates) Ranking of results –Efficient top-k operators –Effective scoring methods for structured queries Dealing with uncertain information – what is the most likely answer? –triples with probabilities Where is the limit for a centralized RDF store?

37 Backup Slides

38 Handling Updates What should we do when our data changes? (SPARQL 1.1 will have updates!) Assumptions: Queries far more frequent than updates Updates mostly insertions, hardly any deletions Different applications may update concurrently Solution: Differential Indexing

39 Differential Updates Workspace A: Triples inserted by application A Workspace B: Triples inserted by application B on-demand indexes at query time kept in main memory Staging architecture for updates in RDF-3X Query by A completion of A completion of B Deletions: Insert the same tuple again with „deleted“ flag Modify scan/join operators


Download ppt "Database Techniques for Linked Data Management SIGMOD 2012 Andreas Harth 1, Katja Hose 2, Ralf Schenkel 2,3 1 Karlsruhe Instititute of Technology 2 Max."

Similar presentations


Ads by Google