30.08.2014 Views

url - Universität zu Lübeck

url - Universität zu Lübeck

url - Universität zu Lübeck

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

5.2. INDEX CREATION ALGORITHM 83<br />

p has exactly one key path because it is a single-key query (see section 2.3.2).<br />

• Second, for each key node we navigate to the corresponding return value<br />

leading to a set of (key, return value) tuples. For each of these tuples we test<br />

whether the conditions expressed by the qualifiers are fulfilled. If we have<br />

no qualifiers this step can be omitted.<br />

• The last step stores the remaining tuples in a new search tree dedicated to<br />

executing queries of the shape of p.<br />

The creation procedure of a multi-key index is a little more complex because<br />

the keys of the different key paths are arranged in levels. Therefore, we use a<br />

recursive algorithm that nests search trees for the key paths in different levels.<br />

The (key, return value) tuples are stored in the last level. We present a Java<br />

derived pseudocode of the creation algorithm for single-key and multi-key indexes<br />

in Listing 5.1:<br />

1 void createIndex (XMLNode context ,<br />

2 SetOfKeyPaths Kp,<br />

3 SetOfQualifierPaths Qp,<br />

4 ReturnValuePath rp ,<br />

5 SearchTree tree ) {<br />

6 i f ( |Kp| == 1) { //Kp has only 1 key path<br />

7 keyP = Kp[ 1 ] ; //get path to this keys<br />

8 relKeyP = keyP−context ; // r e l a t i v e path to the keys from context node<br />

9 relValP = rp−keyP ; // r e l a t i v e path to the return value<br />

11 KEYS = eval ( context , relKeyP ) ; // r e t r i e v e the key elements<br />

12 f o r a l l ( k in KEYS) {<br />

13 val = eval ( k , relValPath ) ; // r e t r i e v e the return value<br />

14 i f ( testQualifier ( val , Qp) ) { //t e s t q u a l i f i e r<br />

15 int id = val . getId ( ) ; //get id of return node<br />

16 tree . add ( k . getText ( ) , id ) ; //add key−value tuple<br />

17 }<br />

18 }<br />

19 }<br />

20 else{ //build a multikey index<br />

21 keyP = Kp[ 1 ] ; //take f i r s t KeyPath<br />

22 Kp = Kp \ Kp[ 1 ] ; //and remove i t from Kp<br />

23 relKeyP = keyP−context ; // r e l a t i v e path to keys from context<br />

25 KEYS = eval ( context , relKeyP ) ; // r e t r i e v e the key elements<br />

26 f o r a l l ( k in KEYS)<br />

27 SearchTree tree2 = new SearchTree ( ) ; // create empty search tree<br />

29 createIndex ( k , Kp, Qp, rp , tree ) ; // recursive c a l l of method<br />

31 tree . add ( k. getText ( ) , tree2 ) ; //nest the second tree<br />

32 }<br />

33 }<br />

34 }<br />

Figure 5.1: Pseudocode to create a single-key or multi-key index<br />

The algorithm assumes that the path expressions to the keys, qualifiers, and the<br />

return value have been extracted from a given XPath query. These path expressions<br />

are extracted by the use of the functions key, qualifier, and value that are

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!