40
1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

  • View
    222

  • Download
    1

Embed Size (px)

Citation preview

Page 1: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

1

Indexing and Querying XML Data for Regular Path Expressions

A Paper by Quanzhong Li and Bongki Moon

Presented by Amnon Shochot

Page 2: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

2

Our Objective

• Developing a system that will enable us to perform XML data queries efficiently.

Page 3: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

3

XML Queries Languages

• Used for retrieving data from XML files.

• Use a regular path expression syntax.

• e.g. XPath, XQuery.

Page 4: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

4

Queries Today - Inefficient

• Usually XML tree traversals – Inefficient.– Top-Down Approach– Bottom-Up Approach– An example:

the query:

/chapter/_*/figure

(finding all figures in all chapters.)

Page 5: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

5

Our Objective - Refined

• Developing a system that will enable us to perform XML data queries efficiently

• Developing such a system consists of:– Developing a way to efficiently store XML data.– Developing efficient algorithms for processing

regular path expressions (e.g. XQuery expressions).

Page 6: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

6

Storing XML Documents

• Question: What would we need from a data structure to be able to perform an efficient query?

• Answer: A mechanism for:– Efficiently finding all elements/attributes with a

given name.– Efficiently finding all values with a given name.– Efficiently resolving ancestor-descendant

relationship.

Page 7: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

7

Storing XML Documents - XISS

• XISS - XML Indexing and Storage System.

• Provides us with ways to:– efficiently find all elements or attributes with the

same name string grouped by document which they belong to.

– quickly determine the ancestor-descendant relationship between elements and/or attributes in the hierarchy of XML data hierarchy.

Page 8: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

8

Determining Ancestor-Descendent Relationship

• According to Dietz’s: for two given nodes x and y of a tree T, x is an ancestor of y iff x occurs before y in the preorder traversal and after y in the postorder traversal.

• Example:

Page 9: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

9

Determining Ancestor-Descendent Relationship – cont.

• Advantage: the ancestor-descendent relationship can be determined in constant time.

• Disadvantage: a lack of flexibility.– e.g. inserting a new node requires recomputation

of many tree nodes.

Page 10: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

10

• A new numbering scheme:– Each node is associated with a <order, size> pair:

• For a tree node y and its parent x:

[order(y), order(y) + size(y)] (order(x), order(x) + size(x)]

• For two sibling nodes x and y, if x is the predecessor of y in preorder traversal holds:

order(x) + size(x) < order(y).

Determining Ancestor-Descendent Relationship – cont.

exclusive

Page 11: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

11

Determining Ancestor-Descendent Relationship – cont.

• Fact: for two given nodes x and y of a tree T, x is an ancestor of y iff:

order(x) < order(y) order(x) + size(x)

Page 12: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

12

Determining Ancestor-Descendent Relationship – cont.

• Properties:– the ancestor-descendent relationship can be

determined in constant time.– flexibility – node insertion usually doesn’t require

recomputation of tree nodes.– an element can be uniquely identified in a

document by its order value.

Page 13: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

13

XISS System Overview

Page 14: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

14

XISS System Overview

• How the system works:– XML documents are loaded into the XISS system.– These documents are added to the XISS data

structures.• Each document is assigned a document id (did).

• Index structures are organized as paged files for efficient disk IO.

– When a query is performed the query processor interacts with XISS in order to obtain the information required for the query.

Page 15: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

15

XISS - cont.

• XISS consists of 5 components:– Name Index– Value Table– Element Index– Attribute Index– Structure Index

Page 16: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

16

Name Index and Value Table

• Objective: minimizing the storage and computation overhead by eliminating replicated strings and string comparisons.

• Name Index - mapping distinct name strings into unique name identifiers (nid).

• Value Table - mapping distinct value strings (i.e. attribute value and text value) into unique value identifiers (vid).

• Both implemented as a B+-tree.

Page 17: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

17

The Element Index

• Objective: quickly finding all elements with the same name string.

• Structure:

Page 18: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

18

The Element Index – cont.

• Structure:– B+-tree using nid as a key.– Leaf nodes: pointers to a set of records for elements

(or attributes) having an identical name string, grouped by the document they belong to.

– Element Record = {<order,size>, Depth, Parent ID}• where Depth is the depth of the element in the XML tree.

– Element Records are ordered by <order,size>.

Page 19: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

19

The Attribute Index

• Objective: quickly finding all elements with the same name string.

• Structure:– Same structure as the Element Index except that the

record in attribute index has a value identifier vid which is a key used to obtain the attribute from the value table.

Page 20: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

20

The Structure Index

• Objectives:– Finding the parent element and child elements (or

attributes) for a given element.– Finding the parent element for a given attribute.

• Structure:

Page 21: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

21

The Structure Index – cont.

• Structure:– B+-tree using document identifier (did) as a key.– Leaf nodes: linear arrays with records for all

elements and attributes from an XML document.– Each record: {nid, <order,size>, Parent order, Child

order, Sibling order, Attribute order}.– Records are ordered by order value.

Page 22: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

22

Querying Method

• Decomposing path expressions into simple path expressions.

• Applying algorithms on simple path expressions and their intermediate results.

Page 23: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

23

Decomposition of Path Expressions

• The main idea: – A complex path expression is decomposed into

several simple path expressions.– Each simple path expression produces an

intermediate result that can be used in the subsequent stage of processing.

– The results of the simple path expressions are than combined or joined together to obtain the final result of the given query.

Page 24: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

24

Basic Subexpressions - Example

Decomposition of

(E1/E2)*/ E3 / ((E4[@a=V]) | (E5/_*/E6)):

(1 )Single Element/Attribute

(2 )Element-Attribute

(3 )Element-Element

(4 )Kleene Closure

(5 )Union/

_/*/

* |

] [/

/

(4)

(2)

(3)

(5)

(3)

(3)

(3)

(1) (1) (1)(1) (1) (1)(1)

Page 25: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

25

Basic Subexpressions

5 basic subexpressions:

(1) A subexpression with a single element or a single attribute.

(2) A subexpression with an element and an attribute.

• e.g. figure[@caption = “Tree Frogs”]

(3) A subexpression with two elements• e.g. chapter/_*/figure where ‘_’ denotes any kind of

node.

Page 26: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

26

Basic Subexpressions - cont.

5 basic subexpressions - cont.:

(4) A subexpression that is a Kleene closure (+,*) of another subexpression.

(5) A subexpression that is a union of two other subexpressions.

Page 27: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

27

3 Algorithms

• 3 Algorithms:– EA-Join: Element and Attribute Join.– EE-Join: Element and Element Join– Kleene Closure

Page 28: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

28

EA-Join: Element and Attribute Join

Input:

{E1,…,Em}: Ei is a set of elements having a common document identifier (did);

{A1,…,An}: Aj is a set of elements having a common document identifier (did);

Output:

A set of (e,a) pairs such that the element e is the parent of the attribute a.

Page 29: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

29

EA-Join: Element and Attribute Join

The Algorithm:

// Sort-merge {Ei} and {Aj} by did.

(1) foreach Ei and Aj with the same did do:

// Sort-merge Ei and Aj by

// PARENT-CHILD relationship

(2) foreach e Ei and a Aj do

(3) if (e is a parent of a) then output (e,a)

end

end

Page 30: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

30

EA-Join – Example

• Consider the XML document:

<Ele Att=“A1”>

<Ele Att=“A2”> </Ele>

</Ele>

• And the query: /Ele[@Att=“A1”]

Ele <1,3>

Ele <3,1>

Att <4,0>

Att <2,0>

Page 31: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

31

<Ele Att=“A1”>

<Ele Att=“A2”> </Ele>

</Ele>

• Sort-merging “Ele”s and “Att”s by parent-child relation ship will give us the list:<1,3>, <2,0>, <3,1>, <4,0>

• Finding the elements “Ele”s with a child attribute “Att” with a value “A1” from the accepted list is easy using the information in the Element Record.

EA-Join – Querying /Ele[@Att=“A1”]

Ele <1,3>

Ele <3,1>

Att <4,0>

Att <2,0>

Page 32: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

32

EA-Join – Comments

• Only a two-stage sort-merge operation without additional cost of sorting:– First merge: by did.– Second merge: by examining parent-child relationship.

• This merge is based on the order values of the element and attribute as defined by the numbering scheme.

• Attributes should be placed before their sibling elements in the order of the numbering scheme.– guarantees that elements and attributes with the same did

can be merged in a single scan.

Page 33: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

33

EE-Join: Element and Element Join

Input:

{E1,…,Em} and {F1,…,Fm}: Ei or Fj is a set of elements having a common document identifier (did).

Output:

A set of (e,f) pairs such that element e is an ancestor of element f.

Page 34: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

34

EE-Join: Element and Element Join

The Algorithm:

// Sort-merge {Ei} and {Fj} by did.

(1) foreach Ei and Fj with the same did do:

// Sort-merge Ei and Fj by the

// ANCESTOR-DESCENDANT relationship.

(2) foreach e Ei and f Fj do

(3) if (e is an ancestor of f) then output (e,f);

end

end

Page 35: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

35

EE-Join – Comments

• Only two-stage sort-merge operation without the additional cost of sorting:– First merge: by did.– Second merge: by examining parent-child

relationship.

• The sets of elements with a matching did cannot be merged in a single scan.

Page 36: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

36

Kleene Closure

Input:

{E1,…,Em}, where Ei is a group of elements from an XML document.

Output:

A Kleene closure of {E1,…,Em}.

Page 37: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

37

The Algorithm:

(1) Set i 1;

(2) Set KiC {E1,…,Em};

(3) repeat

(4) set i i + 1;

(5) set KiC EE-Join(Ki-1

C, K1C);

until (KiC is empty);

(6) output the union of K1C,K2

C,…, KiC;

Kleene Closure

Page 38: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

38

Performance Experiments

• EE-Join:

• Results: – Real World: an order of magnitude faster.– Synthetic Data: 6 to 10 times faster.

Page 39: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

39

Performance Experiments

• EA-Join:

• Results:– Compared to Top-Down: a better performance.– Compared to Bottom-Up: no winner - close results.

Page 40: 1 Indexing and Querying XML Data for Regular Path Expressions A Paper by Quanzhong Li and Bongki Moon Presented by Amnon Shochot

40

Performance Results - Conclusions

• The proposed algorithms can achieve performance improvement over the conventional methods (top-down and bottom-up tree traversals) by up to an order of magnitude.