K.Subieta. SBA and SBQL, appendix, slide 1 Sept. 2006 Appendix: how the ENVS and QRES stacks work...

36
K.Subieta. SBA and SBQL, appendix, slide 1 Sept. 2006 Appendix: how the ENVS and QRES stacks work (M0 example) Presentation prepared for OMG Object Database Technology Working Group OMG TECHNICAL MEETING, Anaheim, CA USA September 25-29, 2006 by Prof. Kazimierz Subieta Polish-Japanese Institute of Information Technology, Warsaw, Poland [email protected] http:// www.ipipan.waw.pl/~subieta SBA/SBQL pages: http:// www.sbql.pl

Transcript of K.Subieta. SBA and SBQL, appendix, slide 1 Sept. 2006 Appendix: how the ENVS and QRES stacks work...

K.Subieta. SBA and SBQL, appendix, slide 1 Sept. 2006

Appendix: how the ENVS and QRES stacks work (M0 example)

Presentation prepared for OMG Object Database Technology Working Group

OMG TECHNICAL MEETING, Anaheim, CA USASeptember 25-29,  2006

by

Prof. Kazimierz Subieta

Polish-Japanese Institute of Information Technology, Warsaw, Poland [email protected]://www.ipipan.waw.pl/~subietaSBA/SBQL pages: http://www.sbql.pl

K.Subieta. SBA and SBQL, appendix, slide 2 Sept. 2006

Query addressing a tiny database

• Query: For each department get its reference and the average sal of its employees.

• SBQL: Dept join avg((employs.Emp).sal)

• Tiny database:

• Expected result: bag{ struct{i17, 2500}, struct{i22, 1450} }

K.Subieta. SBA and SBQL, appendix, slide 3 Sept. 2006

Query syntax tree and execution scenarioDept join avg( ( employs . Emp ) . sal )

join

Dept avg

.

. sal

employs Emp

2nd dot

1st dot

join 1st dot 2nd dot avg

1st Dept

2nd Dept

1st employs

2nd employs

1st Emp

2nd Emp

3rd Emp3rd employs

K.Subieta. SBA and SBQL, appendix, slide 4 Sept. 2006

0Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

empty

Start

K.Subieta. SBA and SBQL, appendix, slide 5 Sept. 2006

1Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

bag{ i17 , i22 }

After binding Dept

K.Subieta. SBA and SBQL, appendix, slide 6 Sept. 2006

2Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

bag{ i17 , i22 }

join starts 1st loop of the iteration over top of QRES

dname(i18) loc(i19) loc(i20) employs(i21)

nested

K.Subieta. SBA and SBQL, appendix, slide 7 Sept. 2006

3Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

bag{ i17 , i22 }

dname(i18) loc(i19) loc(i20) employs(i21)

After binding employs

i21

K.Subieta. SBA and SBQL, appendix, slide 8 Sept. 2006

4Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

bag{ i17 , i22 }

dname(i18) loc(i19) loc(i20) employs(i21)

i21

dot starts iteration on top of QRES

Emp(i1)nested

K.Subieta. SBA and SBQL, appendix, slide 9 Sept. 2006

5Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

bag{ i17 , i22 }

dname(i18) loc(i19) loc(i20) employs(i21)

i21

Emp(i1)

After binding Emp

i1

K.Subieta. SBA and SBQL, appendix, slide 10 Sept. 2006

6Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

bag{ i17 , i22 }

dname(i18) loc(i19) loc(i20) employs(i21)

Closing the iteration by the first dot

i1

K.Subieta. SBA and SBQL, appendix, slide 11 Sept. 2006

7Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

bag{ i17 , i22 }

dname(i18) loc(i19) loc(i20) employs(i21)

i1

Second dot starts iteration over top of QRES

name(i2) sal(i3) worksIn(i4)

nested

K.Subieta. SBA and SBQL, appendix, slide 12 Sept. 2006

8Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

bag{ i17 , i22 }

dname(i18) loc(i19) loc(i20) employs(i21)

i1

name(i2) sal(i3) worksIn(i4)

After binding sal

i3

K.Subieta. SBA and SBQL, appendix, slide 13 Sept. 2006

9Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

bag{ i17 , i22 }

dname(i18) loc(i19) loc(i20) employs(i21)

i3

Closing the iteration by the second dot

K.Subieta. SBA and SBQL, appendix, slide 14 Sept. 2006

10Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

bag{ i17 , i22 }

dname(i18) loc(i19) loc(i20) employs(i21)

2500

After performing avg on top of QRES

K.Subieta. SBA and SBQL, appendix, slide 15 Sept. 2006

11Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

bag{ i17 , i22 }

dname(i18) loc(i19) loc(i20) employs(i21)

2500

join forms the first partial result

struct{ i17, 2500 }Partial result of join:

K.Subieta. SBA and SBQL, appendix, slide 16 Sept. 2006

After ending the 1st loop by join

12Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

bag{ i17 , i22 }

struct{ i17, 2500 }Partial result of join:

K.Subieta. SBA and SBQL, appendix, slide 17 Sept. 2006

13Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

bag{ i17 , i22 }

join starts 2nd loop of the iteration over top of QRES

dname(i23) loc(i24) employs(i25) employs(i26)

nested

struct{ i17, 2500 }Partial result of join:

K.Subieta. SBA and SBQL, appendix, slide 18 Sept. 2006

After binding employs

14Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

bag{ i17 , i22 }

dname(i23) loc(i24) employs(i25) employs(i26)

bag{ i25 , i26 }

struct{ i17, 2500 }Partial result of join:

K.Subieta. SBA and SBQL, appendix, slide 19 Sept. 2006

15Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

bag{ i17 , i22 }

dname(i23) loc(i24) employs(i25) employs(i26)

bag{ i25 , i26 }

First dot starts 1st loop of iteration on top of QRES

nestedEmp(i5)

struct{ i17, 2500 }Partial result of join:

K.Subieta. SBA and SBQL, appendix, slide 20 Sept. 2006

After binding Emp

16Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

bag{ i17 , i22 }

dname(i23) loc(i24) employs(i25) employs(i26)

bag{ i25 , i26 }

Emp(i5)

struct{ i17, 2500 }Partial result of join:

i5

K.Subieta. SBA and SBQL, appendix, slide 21 Sept. 2006

Forming 1st partial result of the first dot

17Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

bag{ i17 , i22 }

dname(i23) loc(i24) employs(i25) employs(i26)

bag{ i25 , i26 }

struct{ i17, 2500 }Partial result of join:

i5Partial result of dot:

K.Subieta. SBA and SBQL, appendix, slide 22 Sept. 2006

18Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

bag{ i17 , i22 }

dname(i23) loc(i24) employs(i25) employs(i26)

bag{ i25 , i26 }

struct{ i17, 2500 }Partial result of join:

i5Partial result of dot:

First dot starts 2nd loop of iteration on top of QRES

nestedEmp(i9)

K.Subieta. SBA and SBQL, appendix, slide 23 Sept. 2006

19Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

bag{ i17 , i22 }

dname(i23) loc(i24) employs(i25) employs(i26)

bag{ i25 , i26 }

struct{ i17, 2500 }Partial result of join:

i5Partial result of dot:

Emp(i9)

After binding Emp

i9

K.Subieta. SBA and SBQL, appendix, slide 24 Sept. 2006

20Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

bag{ i17 , i22 }

dname(i23) loc(i24) employs(i25) employs(i26)

bag{ i25 , i26 }

struct{ i17, 2500 }Partial result of join:

i5Partial results of dot: i9

Forming 2nd partial result of the first dot

K.Subieta. SBA and SBQL, appendix, slide 25 Sept. 2006

21Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

bag{ i17 , i22 }

dname(i23) loc(i24) employs(i25) employs(i26)

bag{ i5 , i9 }

struct{ i17, 2500 }Partial result of join:

Closing iteration by the first dot, forming its result

K.Subieta. SBA and SBQL, appendix, slide 26 Sept. 2006

22Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

bag{ i17 , i22 }

dname(i23) loc(i24) employs(i25) employs(i26)

bag{ i5 , i9 }

struct{ i17, 2500 }Partial result of join:

Second dot starts 1st loop of iteration on top of QRES

nested

name(i6) sal(i7) worksIn(i8)

K.Subieta. SBA and SBQL, appendix, slide 27 Sept. 2006

23Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

bag{ i17 , i22 }

dname(i23) loc(i24) employs(i25) employs(i26)

bag{ i5 , i9 }

struct{ i17, 2500 }Partial result of join:

name(i6) sal(i7) worksIn(i8)

After binding sal

i7

K.Subieta. SBA and SBQL, appendix, slide 28 Sept. 2006

24Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

bag{ i17 , i22 }

dname(i23) loc(i24) employs(i25) employs(i26)

bag{ i5 , i9 }

struct{ i17, 2500 }Partial result of join:

Forming 1st partial result of the second dot

i7Partial result of dot:

K.Subieta. SBA and SBQL, appendix, slide 29 Sept. 2006

25Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

bag{ i17 , i22 }

dname(i23) loc(i24) employs(i25) employs(i26)

bag{ i5 , i9 }

struct{ i17, 2500 }Partial result of join:

i7Partial result of dot:

Second dot starts 2nd loop of iteration on top of QRES

nested

name(i10) sal(i11) address(i12) worksIn(i16)

K.Subieta. SBA and SBQL, appendix, slide 30 Sept. 2006

26Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

bag{ i17 , i22 }

dname(i23) loc(i24) employs(i25) employs(i26)

bag{ i5 , i9 }

struct{ i17, 2500 }Partial result of join:

i7Partial result of dot:

name(i10) sal(i11) address(i12) worksIn(i16)

After binding sal

i11

K.Subieta. SBA and SBQL, appendix, slide 31 Sept. 2006

27Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

bag{ i17 , i22 }

dname(i23) loc(i24) employs(i25) employs(i26)

bag{ i5 , i9 }

struct{ i17, 2500 }Partial result of join:

i7Partial result of dot: i11

Forming 2nd partial result of the second dot

K.Subieta. SBA and SBQL, appendix, slide 32 Sept. 2006

28Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

bag{ i17 , i22 }

dname(i23) loc(i24) employs(i25) employs(i26)

bag{ i7 , i11 }

struct{ i17, 2500 }Partial result of join:

Closing iteration by the second dot, forming its result

K.Subieta. SBA and SBQL, appendix, slide 33 Sept. 2006

29Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

bag{ i17 , i22 }

dname(i23) loc(i24) employs(i25) employs(i26)

1450

struct{ i17, 2500 }Partial result of join:

After performing avg on top of QRES

K.Subieta. SBA and SBQL, appendix, slide 34 Sept. 2006

30Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

bag{ i17 , i22 }

dname(i23) loc(i24) employs(i25) employs(i26)

1450

struct{ i17, 2500 }Partial results of join:

join forms 2nd partial result

struct{ i22, 1450 }

K.Subieta. SBA and SBQL, appendix, slide 35 Sept. 2006

31Dept join avg( ( employs . Emp ) . sal )

Emp(i1) Emp(i5) Emp(i9) Dept(i17) Dept(i22)

ENVS QRES

bag{ struct{ i17, 2500}, struct{ i22 , 1450} }

Closing the iteration by join, forming the final result

K.Subieta. SBA and SBQL, appendix, slide 36 Sept. 2006

In closing …

• Please note that this evaluation scenario concerns the formal semantics executed by the abstract machine.– Our goal is clear, universal and free of ambiguities semantic

specification rather than performance.

• In real implementation there are many obvious optimizations.

• The evaluation process is also the subject of many sophisticated optimizations (rewriting, indices, caching,…) .

• The entire process is executed in the main memory, hence the computations are not critical.– Critical computations concern the access to external storage and

network, and avoiding unnecessary (redundant) computations.

– This is the subject of major SBA optimization methods.