2. composition (kompozīcija) - web viewcalculation of composition is not simple like the other...

55
Datu bāzes sistēmu matemātiskie pamati Relāciju algebra Relāciju datu bāzes sistēma Objektu algebra Objektu datu bāzes sistēma Relāciju algebra + Objektu algebra Relāciju objektu datu bāzes sistēma ? Temporālā (laika) datu bāzes sistēma 1

Upload: tranxuyen

Post on 05-Feb-2018

218 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Datu bāzes sistēmu matemātiskie pamati

Relāciju algebra Relāciju datu bāzes sistēma

Objektu algebra Objektu datu bāzes sistēma

Relāciju algebra + Objektu algebra Relāciju objektu datu bāzes

sistēma

? Temporālā (laika) datu bāzes sistēma

1

Page 2: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Algebra un loģika

Algebra (no arābu valodas "al-jabr" nozīmē "salauzto detaļu atkalapvienošanās") ir viena no matemātikas sadaļām, kopā ar skaitļu teoriju, ģeometriju un analīzi. Vispārīgi definējot algebra, ir mācība par matemātiskiem simboliem un to manipulēšanas likumiem. Tā ir vienojošs pavediens gandrīz visai matemātikai. Ir:

1) elementārā algebra;2) abstraktā (specializētā) algebra.

Daudz agrīno darbu algebrā, pirms arābu zinātniekiem, izdarīja Tuvajos Austrumos. Piemēram, matemātiķi al-Khvārizmī (780 – 850) un Omars Haijāms.

Loģika (grieķu: λογική, logiké - pareizi domāt) ir zinātne par intelektuālās izziņas formām, metodēm un to savstarpējām likumsakarībām. Loģika ir zinātne par domāšanu, kura nodarbojas ar domāšanas veidu un likumu pētīšanu. Loģika ļauj pamatot savu viedokli un nenonākt pretrunās pašam ar sevi. Viens no loģikas svarīgākajiem uzdevumiem ir iemācīt apzināti izmantot loģikas likumus un domāšanas formas. Tā ļauj izprast jēdzienus un izdarīt spriedumus un secinājumus. Tiek lietotas vērtības: patiess, nepatiess.

Temporal logic is any system of rules and symbolism for representing, and reasoning about, propositions (priekšlikumi) qualified in terms of time.Temporal logic has two kinds of operators:1) logical operators. Operators are usual truth-functional operators.2) modal operators. It is an operator which forms propositions from propositions.The term “Modal operators” might sound weird. This refers to your mode of operating. They are words like must, should, can’t, have to, mustn’t, can, will and indicate possibility or necessity. There is a big difference between doing something because you feel you have to and because you want to.

2

Page 3: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Allena laika intervālu (pareizi būtu laika periodu) algebra1

In 1983 James F. Allen published a paper in which he proposed thirteen basic relations between time periods that are

1) distinct (atšķirīgs, noteikts, skaidrs), because no pair of definite intervals can be related by more than one of the relationships;

2) exhaustive (izsmeļošs, vairāk nav nepieciešams) because any pair of definite intervals are described by one of the relations;

3) qualitative  rather than quantitative because no numeric time spans (atstarpes) are considered.

These relations and the operations on them form Allen's interval algebra. 

Six pairs of the relations are converses (pretēji, apgriezti).  For example, the converse of "a precedes b" is "b preceded by a"; whenever the first relation is true, its converse is true also.  Table 2 lists the relations with each one beside its converse.  The thirteenth, "equals", is its own converse.  Each pair of converse relation symbols consists of the lowercase and uppercase of the same letter (e.g. p and P; the uppercase letters represent the relations Allen defined as converses). 

1 https://www.ics.uci.edu/~alspaugh/cls/shr/allen.html

3

Page 4: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Vienkāršas periodu attiecības

4

Page 5: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Periodu atiiecību vektori2

V1 = (BEFORE MEETS OVERLAPS) A un BV2 = (OVERLAPS STARTS DURING)V1 + V2 = (OVERLAPS)

V1 = (Before Meets Overlaps) A un BV3 = (Before Meets) B un CV1 x V3 = (Before)

2 http://www.cs.rochester.edu/users/faculty/kautz/papers/vilain-kautz-book.pdf

5

Page 6: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Laika periodu attiecības (relations)

Relation Illustration Interpretation

X takes place before Y

X meets Y (i stands for inverse)X overlaps with Y

X starts Y

X during Y

X finishes Y

X is equal to Y

allenintervalrelationships3 This Java-library implements Allen's proposed path consistency algorithm for reasoning on temporal interval relationships.

3 https://code.google.com/archive/p/allenintervalrelationships/downloads

6

Page 7: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Noteiktie un nenoteiktie periodi

The basic relations describe relations between definite periods. 

Indefinite periods, whose exact relation may be uncertain, are described by a set of all the basic relations that may apply. 

We call such a set of basic relations a general Allen relation, or just an Allen relation. 

7

Page 8: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Periodu attiecības. Piemērs "Gaismas ieslēgšana"

Jānis nebija istabā, kad es nospiedu slēdzi, lai ieslēgtu gaismu.

Pieņemam: a - laiks, kad Jānis bija istabā b - laiks, kad es nospiedu slēdzic – laiks, kad ir ieslēgta gaisma  Then we can say a(pmMP)b, that is, a precedes, meets, is met by, or is preceded by b; and b(mo)c, that is, b meets or overlaps c. 

a (pmMP) blaiks, kad Jānis bija

istabā

precedes laiks, kad es nospiedu slēdzi

meets

is Met by

is Procede by

b (mo) claiks, kad es

nospiedu slēdzi

meets laiks, kad ir ieslēgta gaisma 

overlaps

There is a general relation for every combination of the thirteen basic relations:  213 or 8192 of them.  Each of the basic relations is a relation, of course, as are all their combinations.  The full relation (pmoFDseSdfOMP) holds between two intervals about whom nothing is known. 

a b

a

a

a

b

b

b

b c

b c

8

Page 9: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Inference of relations Attiecību izvedums, secinājums

9

Page 10: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Darbības ar attiecībām (operations on relations)

1. Complement (papildinājums)The complement ~r of a relation r is the relation consisting of all basic relations not in r. ~(p) = (moFDseSdfOMP) ; ~(pmoFD) = (seSdfOMP)

2. Composition (kompozīcija)The composition (r.s) of two relations (r) and (s) is the relation that holds between a and c if there is a b such that a(r)b and b(s)c; we then write a(r.s)c.  Calculation of composition is not simple like the other operations in this section.  It can be determined by going back to the definitions of the relations, and working from there; or by determining the composition of each basic relation from r with each basic relation from s, and taking the union of the results; or by using the "allen" command.  (m).(m) = (p) ; (pm).(pm) = (p) ; (oFD).(oFDseS) = (pmoFD

3. Converse (pretējs)The converse !r of a relation r is the relation consisting of the converses of all basic relations in r.  Converse operation is its own inverse; for every relation r, !(!r) = r !(p) = (P) ; !(pmoFD) = (dfOMP) ; !(mM) = (mM) ; !() = ()

4. Intersection (konjumkcija, un)The intersection (r^s) of two relations (r) and (s) is the set-theoretic intersection of the two relations; it is the relation composed of all basic relations that are in both (r) and (s).  Intersection is commutative and associative. (pmo)^(FDseS) = () ; (pFsSf)^(pmoFD) = (pF) ; (pmo)^(pmo) = (pmo)

5. Union (apvienojums)The intersection (r+s) of two relations (r) and (s) is the set-theoretic intersection of the two relations; it is the relation composed of all basic relations that are in either (r) and (s).  Union is commutative and associative. (pmo)+(FDseS) = (pmoFDseS) ; (pFsSf)+(pmoFD) = (pmoFDsSf) ; (pmo)+(pmo) = (pmo)

10

Page 11: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Basic relation diagrams for compositions of basic relations (n – biežums)

11

Page 12: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Temporal GIS algebra rastra un vektoru tipa grafikai4

The temporal part of the temporal GIS algebra is designed to be used as is in the temporal vector algebra and the temporal raster algebra. Hence it works with Space Time DataSets of any type (STRDS, STVDS). The algebra provides methods select maps from STDS based on their temporal relations. It is also possible to temporally shift maps, to create temporal buffer and to snap time instances to create a valid temporal topology. These operations can be assigned to space time datasets or to the results of operations between space time datasets.

4 http://trac.osgeo.org/grass/wiki/Grass7/TemporalGISAlgebra

12

Page 13: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Temporālās algebras sinonīmi

Historical algebras

Valid-time algebras

Transaction-Time algebras

Bitemporal algebras

Temporal algebra is a generic term for an algebra defined for a data model that

organizes temporal data. A temporal data model may support Valid-time (the time over

which a data value is valid), Transaction-time (time when a data value is recorded in

the database), or both (Bitemporal). So an algebra can be defined for each case, a

Valid-time relational algebra, a Transaction-time relational algebra, or a Bitemporal

relational algebra, respectively. Temporal algebras include the temporal versions of

relational algebra operations in addition to new operations for manipulating temporal

data like Time-slice, Rollback, Temporal Coalesce, temporal restructuring operations,

and others.

13

Page 14: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Temporal Relational Algebra

Conventional relational databases have basic constructs of the SQL query language that can be translated to relational algebra, which has strong semantics. Thus, the SQL language is well understood and consistent. Relational Algebra (RA) is the writing of logical expressions using set of relational operators that perform operations over relations and returns results as relations.

Temporal Relational Algebra (TRA) is the extension to RA. TRA is a set of operators that includes all the RA operators and with the addition of new temporal specific operators. The evaluation of a query in TRA using the information of just a snapshot of the historic database (a particular tick) would mean that the classical relational operators1 have their normal meaning, are consistent.

14

Page 15: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Relāciju algebras galvenās darbības (atgādinājums) Operations of relational algebra

1. Selekcija (selection).

2. Projekcija (projection).

3. Dekarta reizinājums (cartezian multiplication).

4. Savienojums (joining).

5. Dabiskais savienojums (natural joining).

6. Pārklājums (overlay).

7. Apvienošana (union).

8. Starpība (difference).

9. Dalīšana (division).

15

Page 16: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

SQL vaicājuma izpildes relāciju algebras darbības

select KD_NUM, IELA, RAJONSfrom Namipasumswhere RAJONS='Centra' and SUBSTR(KD_NUM,11,3)='001'

1. Selekcija – tiek veikta datu atlasīšana, pēc WHERE rindā uzdotajiem nosacījumiem 2. Projekcija – atlasa tikai vaicājumā uzdotās kolonnas

KD_NUM IELA M_NU KORP RAJONS1000100123001 Skolas 15   Centra1000302036001 Skolas 2a 1 Centra1001101223002 Dārzciema 100   Latgales1001272123003 Grīvas 11 19 Kurzems1001156163002 Valkas 12   Latgales1000100123002 Dzirciema 12 2 Kurzems1001202000007 Skolas 50 1 Centra 1001230001004 Vienības gatve 109   Vidzemes1000222222001 Ģertrūdes 20   Centra1000101256001 Elizabetes 65   Centra1001161259002 Bērzu 22 2 Zemgales1001281256006 Slokas 13   Kurzems1000100902003 Višķu 22   Latgales1000300995005 vaidelotes 60 2 Kurzems1001281299008 Dārzciema 100   Latgales

1000100123001 Skolas 15   Centra1000302036001 Skolas 2a 1 Centra1000222222001 Ģertrūdes 20   Centra1000101256001 Elizabetes 65   Centra

1000100123001 Skolas Centra 1000302036001 Skolas Centra 1000222222001 Ģertrūdes Centra1000101256001 Elizabetes Centra

Selekcijas rezultāts

Projekcijas rezultāts

Selekcija

Selekcija

16

Page 17: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Temporālās algebras pamatdarbības

1. Projekcija (kolonu atlase):

- ne temporāla projekcija;

- temporāla projekcija.

2. Atlase (rindu atlase);

3. Reizinājums (tabulu rakstu savienojums) (multiplication);

4. Apvienojums (apvieno laika periodus) (interval union);

5. Starpība (tabulu rakstu starpība) (difference);

6. Intervāla sadalīšana (unfold - atvērt)

7. Laika punktu (periodu) apvienošana periodā (fold – iesaiņot).

17

Page 18: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Periodu kanoniskās formas (canonical forms of periods)

Periodi :{ [d1, d2], [d3, d5], [d4, d7] } d1 d2 d3 d4 d5 d6 d7

{ [d1, d2], [d3, d5], [d4, d6], [d6, d7] }

1. Izvērstā (expanded) periodu kanoniskā forma { [d1, d2], [d3,d4], [d4,d5], [d5, d6], [d6, d7} }

d1 d2 d3 d4 d5 d6 d7

2. Sakļautā (consolidated) periodu kanoniskā forma { [d1, d2], [d3, d7] }

d1 d2 d3 d4 d5 d6 d7

18

Page 19: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Temporal Normal Form Tuples will have the following structure: (a1,….,an) [start, end] in a relation R, where start and end are the temporal time attributes (referring to ticks) and define the time period for when the tuple exists. This temporal structure is applied and stored in a relational database as R(a1,….,an,start,end), a set of attributes.

All periods that are stored in the relational database are and must be maximal.

That is to say, for any tuple R(a1,….,an,start,end) there must be no other matching tuple R(a1,….,an,start’,end’) where the non-temporal attributes a1,….,an are identical and the temporal attributes, the intervals overlap by confirming to start ≤ end’+1 and end ≥ start-1 (that overlap or touch each other). Thus, adding the constraint that all such intervals are maximal gives the temporal normal form (TNF). In order for an interval to be a valid interval in the bounded model, the fact 0 ≤ start ≤ end ≤ n (n is the last tick t of the historic database Dn) must be obeyed. The reasons for choosing the TNF (time interval associated with tuples): 1. Produces a compact database, making it efficient in storage, whereby overlapping intervals of two tuples are replaced by a single interval for a single tuple. 2. Without the normal form, the primary keys of relations would be seen to have duplicates at some time. For example, if we have a relation R with a single attribute that is also its primary key and have stored in the database R = { (a) [2, 5], (a) [5, 10] }, then at tick 5, the primary key x is seen to be duplicated. 3. Implementation of the query language would be complicated. For example, if we want to find if R(x) held for the interval, then in the TNF database we need only check once that R(a) is stored in the database as holding for some interval that encloses. However, for a non-TNF database, we must merge all overlapping tuples to see if together they enclose.

19

Page 20: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Example Relations League

Cup

Time

20

Page 21: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Projection πt

πt A, B, C R = coalesce (πA, B, C, start, end R)

coalesce - apvienošana

The following pseudo algorithm defines the coalesce function:

function coalesce(R)

R := R order by a1,….,an,startRc = emptySize = count(R) i = 1 repeat

Ri = (a1,….,an) [start, end]while Ri+1 = (a’1,….,a’n) [start’, end’] and a1= a’1,…., an= a’n and start’≤end+1

end := max(end, end’) i = i+1

end_while insert (a1,….,an) [start, end] into Rc i := i+1 while i ≤ size

return Rc

21

Page 22: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Selection σt

σt A,… R

League Where pos = 1 and team = ‘Arsenal’

Table

a1 Start_End

V1V2V3V4

22

Page 23: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Cartesian product (Dekarta reizinājums)R ×t S = πR, S, max(R.start, S.start), min(R.end, S.end) σ overlap(R,S) (R × S)

Product: League xt Cup

a1 Start_EndV1V2V3V4

a2 Start_EndVE1VE2VE3VE4ResultV3,VE2V3,VE3

23

Page 24: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Since product S×R S× S = coalesce ( πR,S,max(R.start, S.start)+1, R.end+1 σ overlap(R,S)

(R × S) )

Since Product ( League, Cup )

Until Product U×R U× S = coalesce ( πR,S, R.end-1, min(R.end, S.end)-1 σ overlap(R,S)

(R × S) )

Until Product ( League, Cup )

The since and until product results produce a temporal since and until product of the two tables respectively. Note that these two new operators are a temporal related operators and can only be applied to temporal databases. Both since and until product are similar to the temporal product except that when integrating time periods of each tuple being used by the since and until product, different time intervals are produced to those found when performing a temporal product.

24

Page 25: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Join

R t S = πR, S, max(R.start, S.start), min(R.end, S.end) AND R.common-attributes=S.common-attributes σ overlap(R,S) (R × S)

Join ( League, Cup )

This result illustrates when did a club win the F.A cup and what position did they finish in the league. The above table show that Arsenal have won the F.A cup twice and finished first in the year 2002 (time point 3) and second in the year 2003 (time point 4) .The result produces a natural temporal join of the two tables. Note that a temporal join is different from the non-temporal join that would bind only the tuples from the League relation with tuples from the FACup relation where joining on the common attributes (column names and types) shared by the two relations (in this query it is the attribute team) This is used to check if two tuples can be joined. A non-temporal join would therefore produce 3 tuples (as the team Arsenal exists in both relations – 3 tuples from League and 1 tuple from FACup respectively). For a temporal join, a tuple from the League table is joined to a tuple form the FACup table if their respective time periods overlap as well as obeying the existing conditions to perform a non-temporal join.

25

Page 26: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Difference

R −t S = difference (R, S)

X Y X - Y

Difference ( Coalesce Project team from League Where team = Arsenal, Coalesce Project team from League Where pos = 1 ) SubQuery A = Coalesce Project team from League Where team = Arsenal,

SubQuery B = Coalesce Project team from League Where pos = 1

Difference ( SubQuery A , SubQuery B ) - This result illustrates when did Arsenal not win the premier league competition.

The result performs the operation a minus b for tuples a from SubQuery A and tuples b from SubQuery B. Note that particular care must be taken of resulting tuples as new time intervals are created. Unlike a non-temporal difference, which just removes data from one relation that exists in the relation, which you are subtracting away, the temporal difference needs to subtract the data for the time periods that match in both relations. The data from SubQuery A exists for time interval 0 to 4 while the data in SubQuery B exists at only time period 3. Therefore, the result must remove the data existing at time period 3, which in effect forms two new time intervals with the data. This implies that in order to remove the time period 3 from the time interval 0 to 4, we create the time intervals 0 to 2 and 4 to 4, which ensures that the time point 3 is not in either time interval, as defined by and being the purpose of the difference operator.

26

Page 27: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Union

R ∪t S = coalesce (R ∪ S)

X

Y

X È Y

Union ( Coalesce Project team from League Where pos = 1, Cup ) SubQuery A = Coalesce Project team from League Where pos = 1

Union ( SubQuery A, Cup )

Coalesce ( Union ( SubQuery A, Cup ) ) - This result illustrates when did a club win either the premier league or the F.A cup competition.

The result performs the temporal operation union of SubQuery A with the relation FACup. A temporal union behaves in the same manner as a non-temporal union. However, the resulting output must be coalesced else it fails to obey the TNF. For the above query, performing a union without coalescing the results, means that we have both the tuple Arsenal [3, 4] and the tuple Arsenal [3, 3] in the output to the query. The time interval for the former tuple ([3, 4]) covers the time interval of the latter tuple ([3, 3]) and this implies that repeated data is present and hence violating the TNF. Thus,

a1 Start_EndV1V2

27

Page 28: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

a temporal union is equivalent to a non-temporal union with all results being coalesced.

28

Page 29: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Past

I S× R where I is the identity relation

The Past operator is useful for querying a temporal database when we are interested in finding all tuples that existed in the past, where past is all the ticks or time points before the current time point.Past ( League )

The result illustrates where have all the clubs finished in the past and when is the data true in the past.Past ( Cup )

The result illustrates which clubs won the F.A cup competition in the past and when in the past.

29

Page 30: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Piemēra temporālā datu bāze

Tabula Darbinieki

Vards_Uzvards Amats Laika_posmsKaspars Bērziņš Dekoratora palīgs [2002.06.25, 2005.12.12)Kaspars Bērziņš Mākslinieks [2005.12.12, ∞)

Alberts Sērmukslis Režisora otrais asistents [1996.12.03, 1999.10.23)Alberts Sērmukslis Režisora asistents [1999.10.23, 2000.07.12)Alberts Sērmukslis Režisors [1999.07.12, ∞)Elizabete Tirāne Režisora asistents [1995.10.23, 2000.07.12)Elizabete Tirāne Projekta vadītājs [2000.07.12, ∞)

Tabula Atalgojums

Amats Alga Laika_posmsDekoratora palīgs 350 [2002.04.01, 2003.07.01)Dekoratora palīgs 500 [2003.07.01, ∞)Mākslinieks 1000 [2000.04.02, 2004.07.04)Mākslinieks 1200 [2004.07.04, ∞)Režisora otrais asistents 500 [1995.07.04, 2000.12.14)Režisora otrais asistents 700 [2000.12.14, ∞)Režisora asistents 600 [1993.06.02, 1995.07.04)Režisora asistents 750 [1995.07.04, 1998.12.14)Režisora asistents 1000 [1998.12.14, ∞)Režisors 2300 [1998.11.11, 2001.03.24)Režisors 2500 [2001.03.24, ∞)Projekta vadītājs 1000 [1999.10.22, 2001.09.30)Projekta vadītājs 1300 [2001.09.30, 2003.01.02)Projekta vadītājs 2000 [2003.01.02, ∞)

30

Page 31: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Tabula ATALG_LIM

Amats Alga Laika_posmsProjekta vadītājs 1000 [1998.01.30, 2002.02.01)Projekta vadītājs 1300 [2002.02.01, 2004.03.31)Projekta vadītājs 2000 [2004.03.31, now)

31

Page 32: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Projekcija pProjekcija ir unāra operācija, kura izvēlas relācijas kolonnu apakškopu. Relācijas r

projekcija uz X ierakstu kopas ir pX(r). Operācijas rezultāts būs relācija r´(X), kura

iegūta, izņemot ārā attiecīgus atribūtus no relāciju shēmas R un izslēdzot dublējošos

ierakstus no palikušajiem. Temporāla projekcija ne vienmēr dod temporālo relāciju:

Projekcija ir unāra operācija, kura atlasa kolonnu apakškopu.

pAmats(Atalgojums) = Atalgojums´{ (Dekoratora palīgs),(Mākslinieks),(Režisora otrais asistents),(Režisora asistents),(Režisors),(Projekta vadītājs) }.

Temporāla projekcija ar temporālo relāciju:pAlga, Laika_posms(ATALG_LIM) = ATALG_LIM ´{(1000, [1998.01.30, 2002.02.01)),

(1300, [2002.02.01, 2004.03.31)), (2000, [2004.03.31, now))}

SELECT Alga, Laika_posmsFROM ATALG_LIM;Alga Laika_posms

1000 [1998.01.30, 2002.02.01)

1300 [2002.02.01, 2004.03.31)

2000 [2004.03.31, now)

32

Page 33: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Atlase s (selection)Atlase vienmēr atgriež temporālo relāciju, konkrētāk nemaina rezultāta relācijas shēmu.

Temporāla atlase dod iespēju lietot laika predikātus un līdz ar to paplašina datu

izgūšanas iespējas. Komplicētā nosacījumā pielieto laika predikātus ( {, , ,

vienāds, pirms, pēc, satiek, satika, pārklāj, ietver un citus).

Tabula

sLaika_posms ietver [1998.06.01, 1999.06.01)(DARBINIEKI) = DARBINIEKI{(Alberts Sērmukslis, Režisora otrais asistents, [1996.12.03, 1999.10.23)),(Elizabete Tirāne, Režisora asistents, [1995.10.23, 2000.07.12))}

SELECT * FROM Darbinieki A

WHERE VALID(A) CONTAINS INTERVAL ‘(1998.06.01, 1999.06.01)’ DAY;

Vards_UzvardsAmats Laika_posms

Alberts Sērmukslis Režisora otrais asistents [1996.12.03, 1999.10.23)

Elizabete Tirāne Režisora asistents [1995.10.23, 2000.07.12)

Funkcija VALID atgriež reālo ieraksta laiku, tas notiek atbilstoši laika zīmogam, kurš

bija uzlikts uz dotā ieraksta.

a1 Start_End

V1V2V3V4

33

Page 34: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Reizinājums x (multiplication)Reizinājums savieno visus ierakstus no tabulām un ar atlases palīdzību var izvēlēties

vajadzīgos. Standarta reizinājuma algebriskais rezultāts:

DARBINIEKI ATALGOJUMS =

R{(Vards_Uzvards), (Amats), (Laika_posms), (Amats), (Alga), (Laika_posms)};

Temporālajām relācijām eksistē specifisks reizinājums. Darbības princips ir sekojošs:

izvēlas tikai tos kortežus, kuriem laika periodi pārklājas un liek rezultātā šo periodu

pārklājumu. Šis reizinājums sastopams arī zem nosaukuma „konkurējošais

reizinājums”.

SELECT * FROM Darbinieki A, Atalgojums B

WHERE A.Vards = ‘Elizabete Tirāne’ AND B.Amats = ‘Projekta vadītājs’

or B.Amats = A.Amats AND VALID(A) OVERLAPS VALID(B);

a1 Start_EndV1V2V3V4

a2 Start_EndVE1VE2VE3VE4RezultātsV3,VE2V3,VE3

34

Page 35: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Temporālā reizinājuma piemērs

A.AMATS = B.AMATS

a)

b)

c)

d)

Darbinieki AUZVARDS AMATS D_NO D_LIDZKoks palīgs 11-03-2001 17-11-2002Koks strādnieks 18-11-2002 24-05-2005Koks meistars 25-05-2005Zars palīgs 10-01-2001 11-09-2001Zars strādnieks 12-09-2001 24-07-2003Zars meistars 25-07-2003

Atalgojums BAMATS ALGA A_NO A_LIDZpalīgs 200 02-03-2000 15-04-2002palīgs 250 16-04-2002strādnieks 350 02-03-2000 01-01-2003strādnieks 450 02-01-2003meistars 500 02-03-2000 09-07-2004meistars 600 10-07-2004

35

Page 36: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Ir periodu pārklājums [SAKUMS, BEIGAS], ja:

( D_NO >= A_NO un A_LIDZ >= D_NO ) vai

( D_NO < A_NO un D_LIDZ >=A_NO)

Pārklājuma periods [SAKUMS, BEIGAS]:

Ja D_NO >= A_NO, tad SAKUMS = D_NO

Ja D_NO < A_NO, tad SAKUMS = A_NO

Ja D_LIDZ >= A_LIDZ, tad BEIGAS = A_LIDZ

Ja D_LIDZ < A_LIDZ, tad BEIGAS = D_LIDZ

UZVARDS AMATS D_NO D_LIDZ ALGA A_NO A_LIDZKoks palīgs 11-03-2001 17-11-2002 200 02-03-2000 15-04-2002Koks palīgs 11-03-2001 17-11-2002 250 16-04-2002

UZVARDS AMATS SAKUMS BEIGAS ALGAKoks palīgs 11-03-2001 15-04-2002 200Koks palīgs 16-04-2002 17-11-2002 250

36

Page 37: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Apvienojums È (union)Temporālajām relācijām eksistē specifisks reizinājums. Darbības princips ir sekojošs:

izvēlas tikai tos kortežus, kuriem laika periodi pārklājas un liek rezultātā šo periodu

pārklājumu. Šis reizinājums sastopams arī zem nosaukuma „konkurējošais

reizinājums”.

Apvienojums veido rakstus ar apvienotiem laika intervāliem. X

Y

X È Y

SELECT DISTINCT

FROM Atalgojums A, Atalg_Lim B

WHERE A.Amats = B.Amats AND A.Amats = ‘Projekta vadītājs’;

a1 Start_EndV1V2

37

Page 38: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Starpība - (difference)Temporālajā gadījumā starpība ir līdzīga apvienošanai. Starpība dod visus pirmā operanda ierakstus, kuru laika periodi nesakrīt ar otrā operanda relācijas ierakstu laika periodiem. Piemērs. Starpība starp ATALGOJUMS un ATALG_LIM relāciju shēmām:sAmats = ‘Projekta vadītājs’(Atalgojums – ATALG_LIM) = R´{(Projekta vadītājs, 1000, [1998.01.30, 2001.09.30), (Projekta vadītājs, 1300, [2001.09.30, 2003.01.02), (Projekta vadītājs, 2000, [2003.01.02, now)}

Starpība dod visus pirmā operanda rakstus, kuru laika intervāli nesakrīt ar otrā operanda rakstu laika intervāliem. X Y X - Y

a1 Start_EndV1V2

38

Page 39: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Starpība -Starpība dod visus pirmā operanda rakstus, kuru laika intervāli nesakrīt ar otrā operanda rakstu laika intervāliem. X Y X - Y

Atalgojums(AMATS, ALGA, A_LAIKS) -

- Darbinieki(UZV, AMATS, LAIKS) =

= REZULTĀTS(AMATS, ALGA, A_LAIKS)

Starpība starp ATALGOJUMS un ATALG_LIM relāciju shēmām:

sAmats = ‘Projekta vadītājs’(Atalgojums – ATALG_LIM) = R´{(Projekta vadītājs, 1000, [1998.01.30, 2001.09.30),

(Projekta vadītājs, 1300, [2001.09.30, 2003.01.02),

(Projekta vadītājs, 2000, [2003.01.02, now)}

Amats Alga Laika posms

Projekta vadītājs 1000 [1998.01.30, 2001.09.30

Projekta vadītājs 1300 [2001.09.30, 2003.01.02

Projekta vadītājs 2000 [2003.01.02, now)

39

Page 40: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Temporālās algebras operācija Unfold (sadalīt, atklāt)

1. Ar Unfold operāciju var sadalīt laika periodu:

a) laika punktos, atbilstoši dotajai granularitātei;

b) mazākos periodos, atbilstoši nosacījumiem.

Laika granula (punkts)

Periods

a) Granulas

b) Mazāki periodi

2. Ja ir relāciju shēma R(A, T), kurā r = {(a, [t1, tn)} un doto intervālu ir

nepieciešams sadalīt, tad Unfold operācija var būt definēta sekojoši:

Unfold(R) = R´(A, T) un r´ = {(a, [t1, t2)), ..., (a, [tn-1, tn))} vai

r´ = {(a, t1), ..., (a, tn)}, ja atribūta T vērtības ir

laika punkti.

3. Operācija Unfold virtuāli izveido tā saucamo laika sēriju, kura sastāv

no visiem esošiem laika punktiem konkrētajā relācijā.

40

Page 41: 2. Composition (kompozīcija) - Web viewCalculation of composition is not simple like the other operations in this section. ... rt,end), a. set of attributes. A. ll . periods. that

Temporālās algebras operācija Fold (apvienot, iesaiņot)

1. Fold operācija laika punktu kopu transformē laika periodā, atbilstoši

izvēlētai laika granularitātei.

Laika granula (punkts)

Laika punktu kopa

Periods

2. Starp operācijām Fold un Unfold pastāv sakarība:

Fold(Unfold(R)) = R

3. Ar operāciju Fold, izmantojot jaunus nosacījumus, var izveidot

jaunus vajadzīgus periodus.

41