Algorth for reducton of Eleent Calculus to Eleent Algebra Introducton M. Manukyan, V. Harutunyan The XML databases currently act defnte nterest aong researchers of databases for the followng reasons: 1. DTD s a coprose between the strct-schea odels such as the relatonal or object odels and the copletely schealess world of se-structured data, 2. In contrast to se-structured data odel, the concept of database schea n the sense of conventonal data odels s supported, 3. In contrast to conventonal data odels strct-scheas, there s possblty to defne ore flexble database scheas (DTD s often allow optonal felds or ssng felds, for nstance) [4]. It s coon n database theory to translate a query language nto an algebra. The XML algebra s used to: 1. Defne seantcs of a query language, 2. Analyze power of ts expressons, 3. Perfor optzaton of queres. There are any approaches n lterature to solve the query proble over XML DB [for exaple, 1,3,5,8,9]. In ths paper we consder an algorth for reducton of eleent calculus [6] to eleent algebra [7]. Prelnares Eleent Calculus: Eleent calculus forulas (sply forulas) are used to gve assertons (e.g., consstency constrants of xd-database to support vrtual eleents and trggers, to express declaratve queres to xd-database. To specfy forulas a varant of the ultsorted frst order predcate logc language s used. Notce that eleent calculus s developed n the style of object calculus. If e s a path expresson (e) s the result of ths path expresson converted to ultset. The atos are defned accordng to the followng rules: ( e )( x1, x2,..., x k ) s an ato, where k ] x s eleent calculus varable. y1θ y2, where y 1, y 2 are ters, θ { =,, >,, <, }. Assung that ψ, ψ 1 and ψ 2 are forulas, the followng expressons wll be forulas: ψ, ψ 1 ψ 2, ψ 1 ψ 2, ψ 1 ψ 2, x( ψ x( ψ ( ψ ) x : = e, ( groupby( x1, x2,..., xk, ψ ( x), dstnct( ψ ) orderby( x ord x ord,..., xk ord, ψ ψ wth dentfcatonlst 1, 2 Algebrac Model: To drectly apply the standard algebrac operatons to xd-eleents we need: foralze the xd-eleent n coplance wth the theory of relatonal databases, defne the nference rules of the resultng scheas of algebrac expressons, prove equvalence of eleent calculus to eleent algebra.
Defnton 1: We say that S s an xd-eleent schea, f S = nae, atoctype, f, where f {?,*, +, }, or S = nae typeop( S, S,..., S n ), f, typeop { sequence, choce, all}, S s an xd-eleent schea, 1 n. Defnton 2: The xd-eleent s of schea S s a fnte collecton of S doan frstcop S doan sec ondcop S ; appngs ( ( ( ( f ondcop ( S ) typeop( S, S,..., ) and sec = S n the followng constrant should be hold for all e s : e[ S ] doan( S 1 n. The frstcop, sec ondcop, doan functons have an obvous seantcs n the prevous defnton. Notce that doan ( sec ondcop( S = ( f sec ondcop( S ) = atoctype valset n = 1 ( atoctype) else doan ( ) S. Defnton 3: Let R and Q be xd-eleents scheas. We say that R and Q are slar, f sec ondcop ( R) atoctype1,sec ondcop( Q) = atoctype2, = and atoctype 1 = atoctype2, or ondcop ( R) typeop( R, R,..., R sec ondcop( Q) = typeop( Q, Q,..., Q sec = n n and R, Q are slar, 1 n. att book2 book1 slar sequence att att sequence app OneorMor ttle type strng author type strng ttle2 type strng author type strng Defnton 4: Let R and Q be xd-eleents scheas. We say that R s subschea of Q ( R Q), f frstcop ( R) = nae1,sec ondcop( R) = atoctype1, frstcop( Q) = nae 2, sec ondcop ( Q) = atoctype 2, and nae 1 = nae 2, atoctype1 = atoctype 2, or frstcop( R) = nae1,sec ondcop( R) = typeop( R1, R2,..., Rk frstcop( Q) = nae 2, ondcop ( Q) = typeop( Q, Q,..., Q and nae 1 = nae 2, and k] j ] sec 2 that R Q. j 1
book subschea book type app sequence app sequen att OneorMore ttle type strng ttle type strng author type strng author type strng Defnton 5: Let r and q be xd-eleents wth R and Q slar scheas correspondngly. Let us say that r and q are equal, f sec ondcop ( R) sec ondcop( Q) = atoctype, content ( r) = content( q or sec ondcop ( R) = typeop( R1, R2,..., Rn sec ondcop ( Q) = typeop( Q1, Q2,..., Qn ): a) typeop = sequance n] frstcop( R ) = frstcop( ) = and, Q, and xd-eleents wth slar scheas R and Q correspondngly, b) typeop = all, n] j n] frstcop( R ) = frstcop( Q j and equal xd-eleents wth slar scheas R and c) typeop = choce, there s a unque [ 1, n] unque j [ 1, n] R frstcop frstcop = Q j, and : ( ) ( ) wth slar scheas Algorth Descrpton R and Q j correspondngly. Algorth: ECToEA (ec, ea) Input: ec - a forula of eleent calculus. Output: ea - an equvalent expresson of eleent algebra for ec. Method: Step1. Create prefx representaton for ec. Step2. Create Eleent Calculus tree. Step3. Create Eleent Algebra tree. Q j correspondngly, r and q are equal r and q j are such that the followng holds for soe r and Create the prefx representaton for an expresson of Eleent Calculus. Eleent Calculus tree creaton. Algorth: CreateECTree (eprefx, ECTree) Input: eprefx - a prefx expresson of eleent calculus forula. q j are equal xd-eleents
Output: ECTree - an equvalent eleent calculus tree. Step1. [Tree creaton] (a) If current token s and, or, plcaton, create correspondng node based on recursvely created left and rght subtrees. (b) If current token s ether wth, forall, exst, negaton, dstnct, groupby or orderby, create correspondng node and recursvely create ts subtree (operand (s) of operaton). (c) If current token s predcate, assgnent, xpath, create correspondng node and coplete recurson for ths subtree (operand (s) of operaton). Step2. [Tree traversal] (a) For each assgent node ove to the root untl a subtree whch set of free varables contans the varables set of consdered assgnent wll be found. (b) For each predcate node ove to the root untl a subtree whch set of free varables contans the varables set of consdered predcate wll be found. Step3. [Elnaton of the negaton nodes fro eleent calculus tree] For each negaton do For each node apply the negaton operaton. For the xpath nodes do: If there s a predcate n xpath negate the predcate, else ove to the root fro the current leaf untl the frst or node wll be reached, delete the subtree contanng the consdered leave, delete or node and lnk t wth the other subtree of ts parent. Creaton of Eleent Algebra tree. Algorth: Algebra (ECTree, EATree) Input: ECTree - an Eleent Calculus tree. Output: EATree - an Eleent Algebra tree. [Tree traversal] (a) If ( pe )( x1, x2,..., xk ( pe) = [/ //] Step0 [/ //] Step1... [/ //] Stepn Step = ( f condton not gve π L ( Step else +1 ( ) f condton s sple predcate π σ ( ) else σ γ ( Step ) L ρ Step = 0,1,..., n 1, Step0 = ntal xd eleent. (b) If ω( y 1, y2,..., y ) = ω1( u1, un ) ω2( v1, vl ) 1. If { u 1,,..., un} { v1,,..., vl } = A lg ebra( ω 1( u1,,..., un Alg ebra( ω2 ( v1,,..., v l 2. If { u 1,,..., u n } = { v1,,..., v l } A lg ebra( ω1( u1,,..., un Alg ebra( ω2 ( v1,,..., v l 3. If { u 1, u n } { v1, v l }, { v1, v l } { u1, u n } { u 1,,..., un} { v1,,..., vl } = v l 4. If { u 1, u n } { v1, v l } v l 5. If { v 1, v l } { u1, u n } v l (c) If ω( y y,..., y ) = ω ( u, u,..., u ) ( v, v,..., v ) and 1, 2 1 n ω2 l L ( ( ) π ρ, L
π y, y,..., y ( Alg ebra( ω ( u, u,..., un ) y y y ( Alg ebra( ( v, v,..., vl ) 1 π 1, 2,..., ω 2 (d) If ω ( y1, y2,..., y ) = ( y+ 1) ω( y1, y2,..., y, y+ 1) π y,,..., ( lg ( ( 1, 2,...,, 1) 1 y2 y A ebra ω y y y y + (e) If ω ( y1, y2,..., y ) = ( y+ 1) ω( y1, y2,..., y, y+ 1) Alg ebra( ω ( y1, y2,..., y, y+ 1) ) π y ( Alg ebra( ω( y1, y2,..., y, 1) +1 y + (f) If groupby( y1, y2,..., y, ω ( y1, y2,..., y, u1,,..., un ( x) γ x x x ( Alg ebra( ( y, y,..., y, u, u,..., un ) 1, 2,..., ω k (g) If orderby( y order, y order,..., y order, ω ( y, y,..., y 1 2 l τ y y y ( A ebra( ( y y y ), lg,,...,,..., ω l (h) If dstnct ( ω ( y y,..., δ ( A ebra( ω( y, y,..., ) () If 1, 2 y dentfca tonlst ρ (j) If predcate (k) If assgnent Algorth Correctness σ predcate π assgnentattrbutes lg The correctness of the suggested algorth s proved n the sae way as correctness of Codd s algorth [2] for reducton the relaton calculus to relatonal algebra as: Op ψ = Op ψ, Op wth, dstnct, groupby, orderby, assgnent. ( ) ( ) { } References 1. D. Beech, A. Malhotra & M. Rys (eds.) A foral data odel and algebra for XML. Councaton W3C, 1999. 2. E. F. Codd. Relatonal Copleteness of Data Base Sublanguages, Data Base Systes, R. Rustn (ed. Prentce Hall, 1972. 3. F. Frasncar, Geert-Jan Houben, C. Pau. XAL: an Algebra for XML Query Optzaton. In Proc. of 13th Australasan Database Conference, 2002. 4. H. Garca-Molna, J. Ullan, J. Wdo, Database Systes: The Coplete Book, Prentce Hall, 2002. 5. H. V. Jagadsh, et. al. TAX: A Tree Algebra for XML, In Proc. DBLP Conference Italy, 2001. 6. M.G.Manukyan, Extensble Data Model, In Proc. of ADBIS 08 Conference, pp. 42-57, 2008. 7. Manukyan M. G., Eleent Algebra. In Proc. of ADBIS'09, LNCS 5968, Sprnger, pp. 113-120, 2009.. 8. J. Shanugasundara, K. Tufte, G. He, C. Zhang, D. DeWtt, and J. Naughton, Relatonal Databases for Querng XML Docuents: Ltatons and Opportuntes. In Proc. VLDB Conference, pp. 47-52, 2000. 9. S. D. Vglas, et. al. Puttng XML Query Algebras nto Context, 2002, http://www.cs.wsc.edu/nagara/publcatons.htl. 10. M. Zhang, J. T. Yao. XML Algebra for Data Mnng, In Proc. SPIE'04, 2004. y