Download presentation
Presentation is loading. Please wait.
Published bySharlene Jackson Modified over 9 years ago
1
K.Subieta. Introduction to SBA and SBQL, Slide 1 3rd Country Conference, Feb.2007 SBA (Stack-Based Approach) and SBQL (Stack-Based Query Language) by Prof. Kazimierz Subieta subieta@pjwstk.edu.pl http://www.ipipan.waw.pl/~subieta SBA/SBQL pages: http://www.sbql.plhttp://www.sbql.pl 3rd Country Conference, February 2007
2
K.Subieta. Introduction to SBA and SBQL, Slide 2 3rd Country Conference, Feb.2007 What is SBA and SBQL? SBA is a conceptual frame for developing O-O database query/programming languages –Query languages are programming languages. SBQL is a model query language according to SBA. –It has the same role and meaning as object algebras, but it is formally sound and much more universal. SBA/SBQL deal with various data models and all imaginable and reasonable query constructs. Abstract implementation is the basic paradigm of formal specification of semantics.
3
K.Subieta. Introduction to SBA and SBQL, Slide 3 3rd Country Conference, Feb.2007 General architecture of query processing Actually, we do not fix the architecture –It can be similar to SQL or ODMG architectures (server- side query processing, ODBC, ADO or JDBC style, queries embedded in popular programming languages) –It can be similar to Oracle PL/SQL (programs integrated with queries, client-side query processing) Shifting query processing and optimization to the client side –Lower workload for the server better overall performance. –More flexible for query optimization.
4
K.Subieta. Introduction to SBA and SBQL, Slide 4 3rd Country Conference, Feb.2007 Detailed client-server architecture Parser of queries and programs Software development environment (editor, debugger, etc.) Client Syntactic tree of a query/program Volatile (non-shared) objects ENVS QRES Static ENVS Static QRES Persistent (shared) objects Object manager Processing persistent abstractions (views, stored procedures, triggers) Register of indices Server Local metabase Metabase of persistent objects Optimization by rewriting Optimization by indices Interpreter of queries & programs Strong type checker Network Register of views Administration Transactions
5
K.Subieta. Introduction to SBA and SBQL, Slide 5 3rd Country Conference, Feb.2007 Object model and database schema … are inevitable parts of a query language. –The application programmer must be aware what the database contains and how it is organized. Usually, an object model and a database schema language are presented at the beginning of the given specification, c.f. ODMG The model involves such concepts as types, classes, interfaces, joined into a coherent whole as a schema language, c.f. ODL. –However, the concepts are difficult, especially types. –Introducing them at the beginning usually results in inconsistencies. Hence, we must first understand the semantics of a query language on the ground of an abstract object store model. –First, realize what is the semantics of a query language, then define the corresponding type system.
6
K.Subieta. Introduction to SBA and SBQL, Slide 6 3rd Country Conference, Feb.2007 SBA semantics of QL-s – general point of view Query - all syntactically correct queries State - all states (not only database states) Result - all possible query results. Semantics of any query is a function that maps State → Result Closure property assumes that a state and a result are sets of objects In SBA a state contains objects (but not only objects) and a result never contains objects Closure property is conceptual nonsense.
7
K.Subieta. Introduction to SBA and SBQL, Slide 7 3rd Country Conference, Feb.2007 What is State? State includes all data or programming features that can influence the result of some query, in particular: –Database state –Local objects used in queries on the client side –Computer and software environment (e.g. date, time) –Libraries, procedures, functions, classes, views, etc. State also includes structures that determine the run- time environment of computations. In SBA there is one such structure: environment stack (ENVS) - an extended and modified call stack. state = object store + ENVS
8
K.Subieta. Introduction to SBA and SBQL, Slide 8 3rd Country Conference, Feb.2007 Is ENVS purely implementation notion? No. The environment stack is a conceptual notion. –ENVS makes it possible to specify precisely the semantics of query languages, … –… the mechanisms of classes, roles, static and dynamic inheritance,... –… (recursive) procedures, parameter passing, database views,... –… etc. In SBA we deal with ENVS on an abstract level. We are not interested in its physical implementation. –Implementation can be different, introducing many optimizations. –Usually ENVS is a client-side data structure stored in main memory. The main roles of ENVS: determining scopes for names and binding names occurring in queries.
9
K.Subieta. Introduction to SBA and SBQL, Slide 9 3rd Country Conference, Feb.2007 What is Result? Query can return any stored or computed value. –For instance, query 2+2 returns 4. Query can return references (OID, file name, memory address, etc.). –For instance, query Person returns references to person objects. Queries can return nested complex values consisting of atomic values, references, names, structure constructors and collection constructors. –SBQL queries never return objects. –Objects are stored within the object store only.
10
K.Subieta. Introduction to SBA and SBQL, Slide 10 3rd Country Conference, Feb.2007 Query result stack, QRES Temporary and final query results are accumulated on the query result stack, QRES. –QRES is a client-side structure stored in main memory. QRES must be prepared to store in a single section any complex query result. QRES is not a component of State –… because the result of a new query does not depend on the previous QRES state. In SBA precise specification of the QRES mechanism is fundamental.
11
K.Subieta. Introduction to SBA and SBQL, Slide 11 3rd Country Conference, Feb.2007 Example of QRES state 15 i 17 struct{ x(i 61 ), y(i 93 ) } bag{ struct{ n( " Doe"), s(i 9 )}, struct{ n( " Poe"), s(i 14 )}, struct{ n( " Lee" ), s(i 18 )}} bottom the only visible stack section invisible stack sections top
12
K.Subieta. Introduction to SBA and SBQL, Slide 12 3rd Country Conference, Feb.2007 Total internal identification Each database or program entity, which could be separately retrieved, updated, inserted, deleted, authorized, indexed, protected, locked, should possess a unique internal identifier. –We are not interested in the form and meaning of internal identifiers. –Unique internal identifiers should be assigned to all components of objects, including atomic ones. –The principle makes it possible to make references and pointers to all possible entities, thus to avoid conceptual problems with binding, scoping, updating, deleting, parameter passing, and other functionalities that require references as query primitives. ODMG does not follow the idea. –ODMG „literals” (components of objects) have no identifiers. –I consider this a fundamental conceptual flaw.
13
K.Subieta. Introduction to SBA and SBQL, Slide 13 3rd Country Conference, Feb.2007 Object relativism If some object O 1 can be defined, then object O 2 having O 1 as a component can also be defined. –No limitations concerning the number of hierarchy levels of objects. –Objects on any hierarchy level should be treated uniformly. –An atomic object (having no attributes) should be allowed as a regular data structure. Object relativism implies the relativism of corresponding query capabilities. –There is no need for attributes, sub-attributes, etc. - all are objects too. The idea radically reduces a database model, cuts the size of specification of query languages, the size of implementation, and the size of documentation. –It much supports query optimization and strong typing.
14
K.Subieta. Introduction to SBA and SBQL, Slide 14 3rd Country Conference, Feb.2007 Abstract Object Store Models A component of State is an object store. –To define the semantics of a query language we have to define an object store precisely, but on the abstract level. Because various object models introduce a lot of incompatible notions, SBA assumes some family of object store models which are enumerated M0, M1, M2 and M3. –M0 covers relational, nested-relational and XML-oriented databases. M0 assumes hierarchical objects and binary links between objects. –Advanced store models introduce classes and static inheritance (M1), object roles and dynamic inheritance (M2), and encapsulation (M3). –All the models are served by SBQL. These store models are pivots - they can be extended and modified, depending on features that one would like to cover.
15
K.Subieta. Introduction to SBA and SBQL, Slide 15 3rd Country Conference, Feb.2007 Notions common to store models 1.Internal object identifier (OID) –Uniquely identifies an object in the store. –Assigned automatically, no external meaning. –Used as a reference or a pointer to an object. 2.External object name –Usually bears some external semantics of an object, e.g. Person, Customer. –Explicitly assigned by a database designer, programmer, etc. –It is usually not unique, e.g. many objects named Person. 3.Atomic object value –Cannot be subdivided into smaller parts –E.g. 2, 3.14, “Doe”, “Hello, World!”. –The size is not constrained – from 1 bit to gigabytes. –So far we neglect types (we deal with types later).
16
K.Subieta. Introduction to SBA and SBQL, Slide 16 3rd Country Conference, Feb.2007 M0 : Complex Objects and Pointer Links No record, tuple, array, set, etc. constructors in the model: essentially all of them are collections of objects. External names are not unique: modeling collections (bags). Uniform treatment of relational, nested relational, etc. databases. I - a set of internal identifiers N - a set of external names V - a set of atomic values - atomic object - pointer object - complex object, T is a set of objects R I – start identifiers object object ID object name object value
17
K.Subieta. Introduction to SBA and SBQL, Slide 17 3rd Country Conference, Feb.2007 M0 object store - example Objects, } >, } >, } >, } >, } >, } > Start identifiers i 1, i 5, i 9, i 17, i 22
18
K.Subieta. Introduction to SBA and SBQL, Slide 18 3rd Country Conference, Feb.2007 M0 object store – graphical view i 5 Emp i 6 name ”Poe” i 7 sal 2000 i 8 worksIn i 1 Emp i 2 name ”Doe” i 3 sal 2500 i 4 worksIn i 22 Dept i 23 dname ”Ads” i 24 loc ”Rome” i 25 employs i 26 employs i 17 Dept i 18 dname ”Trade” i 19 loc ”Paris” i 20 loc ”Rome” i 21 employs i 9 Emp i 10 name ”Lee” i 16 worksIn i 11 sal 900 i 12 address i 13 city ”Rome” i 14 street ”Boogie” i 15 house# 13
19
K.Subieta. Introduction to SBA and SBQL, Slide 19 3rd Country Conference, Feb.2007 A relational database in M0 A similar mapping can be applied to hierarchical DB, nested relational DB, XML, RDF, … Relational schema: Emp( name, sal, worksIn ) name Doe Poe Lee sal 2500 2000 worksIn Production Sales Relation: Emp Model M0: Objects:, } >,, } >,, } > Start identifiers: i 1, i 5, i 9
20
K.Subieta. Introduction to SBA and SBQL, Slide 20 3rd Country Conference, Feb.2007 Environment Stack, ENVS ENVS is also known as call stack. For query processing we modified and generalized it: –ENVS is used to binding objects that are stored at a server, hence ENVS contains references to objects rather than object values. –The same object can be referenced from different stack sections. –For collections the binding is macroscopic, for instance, if Emp is bound, the binding returns many references. In PLs the stack has usually two incarnations: static (compile time) and dynamic (run-time). Because database objects are always dynamically bound, some properties of a static stack must be shifted to a dynamic stack. –We deal with the static stack when we consider strong typing. Besides classical roles of the stack, SBA provides many new roles of it, in particular, processing non-algebraic operators.
21
K.Subieta. Introduction to SBA and SBQL, Slide 21 3rd Country Conference, Feb.2007 Naming, scoping, binding SBA is based on the naming, scoping and binding paradigm: Every name occurring in a query is bound to run time program or database entities, according to the actual scope for the name. Binding is substituting a name occurring in a query by a run- time program entity (or entities). This concerns all names, in particular: –Names of persistent or volatile objects, subobjects (attributes), pointers, procedures, functions, methods, views, parameters. –Names of entities from the computer or software environment –Any auxiliary names that are defined and used in queries ENVS presents a universal scoping and binding mechanism. –No name occurring in a query can be bound otherwise. ENVS stores binders, i.e. pairs n(r), where n N, r Result.
22
K.Subieta. Introduction to SBA and SBQL, Slide 22 3rd Country Conference, Feb.2007 Opening a new section of ENVS (1) In PLs opening a new scope on ENVS is caused by entering a new procedure (function, method) or entering a new block. –Respectively, removing the scope is performed when the control leaves the body of the procedure/block. To these classical situations we add a new one. –It is the essence of SBA. The idea is that some query operators (called non-algebraic) behave on the stack similarly to program blocks. –In the SBQL query: Emp where ( name = “Poe” and sal > 1000 ) the part ( name = “Poe” and sal > 1000 ) behaves as a program block executed in an environment consisting of the interior of an Emp object. Binding concerns also names name and sal. –Hence, we push on ENVS a section with the interior of the currently processed Emp object (next slide).
23
K.Subieta. Introduction to SBA and SBQL, Slide 23 3rd Country Conference, Feb.2007 Emp where (name = ”Poe” and sal > 1000) Emp(i 1 ) Emp(i 5 ) Emp(i 9 ) Dept(i 17 ) Dept(i 22 ) name(i 10 ) sal(i 11 ) address(i 12 ) worksIn(i 16 ) Emp(i 1 ) Emp(i 5 ) Emp(i 9 ) Dept(i 17 ) Dept(i 22 ) Initial ENVS state. bind( Emp ) = {i 1, i 5, i 9 } ENVS during evaluation of the condition for the third object Emp. bind( name ) = i 10 ; bind( sal ) = i 11 binding Interior of the 3-rd object Emp condition Opening a new section of ENVS (2)
24
K.Subieta. Introduction to SBA and SBQL, Slide 24 3rd Country Conference, Feb.2007 Function nested – computing object’s interior Function nested acts on an object reference and returns its interior as a set of binders. For instance: The result of nested is then pushed at ENVS. i 9 Emp i 10 name ”Lee” i 16 worksIn i 11 sal 900 i 12 address i 13 city ”Rome” i 14 street ”Boogie” i 15 house# 13 nested( i 9 ) = { name( i 10 ), sal( i 11 ), address( i 12 ), worksIn( i 16 ) }
25
K.Subieta. Introduction to SBA and SBQL, Slide 25 3rd Country Conference, Feb.2007 Generalization of function nested In general, it can be applied to any element of Result. –For a complex object,,..., }> it holds: nested( i ) = { n 1 (i 1 ), n 2 (i 2 ),..., n k (i k ) } The case is illustrated on the previous slide. –If i is an identifier of a pointer object, and the object store contains the object, then nested( i ) = { n 1 (i 1 ) } This accomplishes navigation according to a pointer. –For a binder n(x) holds: nested( n(x) ) = { n(x) } According to understanding of auxiliary names introduced in queries. –For a structure nested returns the union of the results of the nested function applied for elements of the structure: nested( struct{ x 1, x 2,... } ) = nested(x 1 ) nested(x 2 ) ... For other arguments nested returns the empty set.
26
K.Subieta. Introduction to SBA and SBQL, Slide 26 3rd Country Conference, Feb.2007 Definition of Result for SBQL Any atomic value belongs to Result. Any reference (OID) belongs to Result. If x belongs to Result, then any binder n(x) belongs to Result. If x 1, x 2, x 3,... belong to Result, then the structure struct{ x 1, x 2, x 3,... } belongs to Result. –In contrast to typical structures, we do not assume that all elements of a structure must be named. –Empty structures are not allowed. If x 1, x 2, x 3,... belong to Result, then bag bag{x 1, x 2, x 3,... } and sequence sequence{x 1, x 2, x 3,... } belong to Result. –bag and sequence are collection constructors. –Other collection constructors are possible.
27
K.Subieta. Introduction to SBA and SBQL, Slide 27 3rd Country Conference, Feb.2007 Summing up: what we have defined so far? We know precisely what is an object store, atomic object, complex object, pointer object and collection. We know precisely what is the construction of an environment stack ENVS, what it is for, what is binding, and how a new section on the stack is constructed (binders, function nested). We know precisely what is a query result and a query result stack QRES. Abstract implementation of a query language has the form of the recursive procedure eval (evaluation of a query). This is all the semantic equipment to define SBQL and its abstract implementation for the M0 store model. For details see http://www.sbql.pl
28
K.Subieta. Introduction to SBA and SBQL, Slide 28 3rd Country Conference, Feb.2007 Examples of SBQL queries for M0 –Get references of departments for employee named Doe: (Emp where name = “Doe”).worksIn.Dept –Get names of departments together with their average salaries: (Dept join avg(employs.Emp.sal) as avgsal). (dname, avgsal) –Names and cities for employees working in the department managed by Kim: (Dept where (boss.Emp.name) = “Kim”).employs.Emp. (name, if exists(Address) then Address.city else “No address”) –Get departments employing a professional for any job in the company. Dept where distinct(Emp.job) as j ( employs.Emp (j = job)) –Names and salaries of employees earning more than their bosses. (Emp where sal > (worksIn.Dept.boss.Emp.sal)).(name, sal)
29
K.Subieta. Introduction to SBA and SBQL, Slide 29 3rd Country Conference, Feb.2007 M1 : Classes and static inheritance Classes, methods and inheritance require extension of M0. Classes have two incarnations: as pieces of a source code and as run-time database entities. –Usually programming languages deal with classes as second-class citizens, i.e. in the source code only. –In our model we are (so far) not interested in this point of view. We deal with them when we consider static binding and strong typing. –In the M1 store model classes are first class entities storing invariant properties of their objects, i.e. methods (but not only). Hence in our model classes are objects too, connected with their member objects by a special relationship. Classes are also connected with classes by another relationship know as inheritance.
30
K.Subieta. Introduction to SBA and SBQL, Slide 30 3rd Country Conference, Feb.2007 Classes as objects in M1 i 1 Person i 2 name ”Doe”... i 9 Emp i 10 name ”Lee” i 16 worksIn i 11 sal 900... i 5 Emp i 6 name ”Poe” i 7 sal 2000 i 8 worksIn... i 40 PersonClass i 41 age (...code...)... i 51 changeSal (...code...)... i 50 EmpClass i 52 netSal (...code...) inherits from member of i 22 i 33 member of
31
K.Subieta. Introduction to SBA and SBQL, Slide 31 3rd Country Conference, Feb.2007 SBQL semantics for M1 Changes concern only ENVS and non-algebraic operators –When a non-algebraic operator processes an object, which is a member of a class, which inherits from a class, etc. then the ENVS is augmented (starting from the top) by nested(i), nested(i C1 ), nested(i C2 ), …up to the most general class. –When a non-algebraic operator finishes processing the object, all these sections are removed from ENVS. Previous ENVS state nested( i ) nested(i C1 ) nested (i C2 ) ….. Before processing the object After processing the object During processing the object
32
K.Subieta. Introduction to SBA and SBQL, Slide 32 3rd Country Conference, Feb.2007 Example: Processing an object in M1 name(i 6 ) sal(i 7 ) worksIn(i 8 ) … changeSal(i 51 ) netSal(i 52 )... age(i 41 )... … Person(i 1 )... Emp(i 5 ) Emp(i 9 )..... nested(i 5 ) - internals of the currently processed Poe’s object nested (i 50 ) – internals of EmpClass nested (i 40 ) – internals of PersonClass Binders to database objects Sections pushed by the dot (Emp where name = “Poe”). (name, netSal, age) ENVS during processing the subquery after the dot:
33
K.Subieta. Introduction to SBA and SBQL, Slide 33 3rd Country Conference, Feb.2007 Some peculiarities of M1 Binding and processing methods: –Invocation of a method means that a new section (activation record) is additionally pushed at top of ENVS. –The section contains parameters of the method (evaluated previously), its local environment and a return track. –Some peculiarities connected with encapsulation. A problem - multiple inheritance: –M1 allows for multiple inheritance, but in case of name conflict there is no solution. This is a general problem, not specific to M1. Another problem - collections: –They violate object-oriented principles such as substitutability and open-close (reuse, conceptual continuation). –Possible solutions require specific extensions of M1.
34
K.Subieta. Introduction to SBA and SBQL, Slide 34 3rd Country Conference, Feb.2007 Examples of SBQL queries for M1 - schema UML-like, but: Cardinalities assigned to all database entities Nested classes Pointers rather than association roles Emp[0..*] e# job[1..*] sal[0..1] changeSal(newSal) netSal( ) Dept[0..*] d# dname loc[1..*] budget() employs[1..*]worksIn Person[0..*] name birthYear age() Address [0..1] city street house# manages[0..1] boss
35
K.Subieta. Introduction to SBA and SBQL, Slide 35 3rd Country Conference, Feb.2007 Examples of SBQL queries for M1 –Get names of departments and the average age of their employees (inheritance of the method age). Dept. (dname, avg(employs.Emp.age)) –Get employees that for sure live in the cities where their departments are located (inheritance of Address). Emp where Address as a ( (worksIn.Dept.loc) as l (a.city = l)) –For each employee get name and the percent of the annual budget of his/her department that is consumed by his/her sal. Emp. (name, (((if exists(sal) then sal else 0) as s). ((s * 12 * 100)/(worksIn.Dept.budget))) –For each person having no salary give the minimal salary in his/her department. for each (Emp where not exists(sal)) as e do e.changeSal( min(e.works_in.Dept.employs.Emp.sal) );
36
K.Subieta. Introduction to SBA and SBQL, Slide 36 3rd Country Conference, Feb.2007 M2: Dynamic roles and dynamic inheritance The object model with dynamic object roles removes essential conceptual drawbacks of the classical static inheritance. –The idea is that an object during its life can acquire and lose its roles without changing its identity. –Object’s business semantics depends on a currently considered role. SBQL is the first (and only) QL dealing with dynamic roles. –Dynamic object roles and dynamic inheritance require extension of M1 and extension of the semantics of non-algebraic operators. Student Employee Club-member Student Tax-payer Dog-owner Person Patient
37
K.Subieta. Introduction to SBA and SBQL, Slide 37 3rd Country Conference, Feb.2007 Example of the M2 store model i 40 PersonClass i 41 age (...code...)............. i 1 Person i 2 name ”Doe” i 3 born 1948 i 60 StudentClass i 61 avgScore (...code...)............. i 50 EmpClass i 51 changeSal (...code...) i 52 netSal (...code...)............. is member of inherits from dynamically inherits from i 4 Person i 5 name ”Poe” i 6 born 1975 i 127 i 13 Emp i 14 sal 2500 i 15 worksIn i 7 Person i 8 name ”Lee” i 9 born 1951 i 128 i 16 Emp i 17 sal 1500 i 18 worksIn i 19 Student i 20 studentNo 223344 i 21 faculty ”Physics”
38
K.Subieta. Introduction to SBA and SBQL, Slide 38 3rd Country Conference, Feb.2007 SBQL semantics for M2 Changes concern only ENVS and non-algebraic operators –The order of sections of roles and classes on ENVS is determined by a simple rule (c.f. full description of SBA/SBQL). –Some new operators dealing with roles (dynamic cast, has role). (Emp where name = ”Lee”). (sal, born, age) Properties of the currently processed Emp role Properties of the EmpClass Properties of the Person super-role of the Emp role Properties of the PersonClass Database section sal(i 17 ) worksIn(i 18 ) changeSal(i 51 ) netSal(i 52 )... name(i 8 ) born(i 9 ) age(i 41 )............ Person(i 1 ) Person(i 4 ) Person(i 7 ) Emp(i 13 ) Emp(i 16 ) Student(i 19 )............ Sections pushed by the dot
39
K.Subieta. Introduction to SBA and SBQL, Slide 39 3rd Country Conference, Feb.2007 Examples of SBQL queries for M2 - schema
40
K.Subieta. Introduction to SBA and SBQL, Slide 40 3rd Country Conference, Feb.2007 Examples of SBQL queries for M2 –Get employees older than 60 who live in Warsaw (dynamic inheritance of the attribute Address and static inheritance of the method age ). Emp where age > 60 and Address (city = “Warsaw”) –For each person get name and the sum of all the incomings (salary and scholarships). (Person as p). (p.name, sum(bag(0, ((Student)p).scholarship, ((Emp)p).sal))) –Get students who live in the same city as the city of their school. Student where Address (city = (studiesAt.School.city)) –Get name, faculty and school name for each person studying at two or more faculties. (((Person as p) join ((((Student)p) group as s))) where count(s) ≥ 2). (p.name, s.(faculty, (studiesAt.School.name)))
41
K.Subieta. Introduction to SBA and SBQL, Slide 41 3rd Country Conference, Feb.2007 Conclusions To make a high quality standard for object-oriented databases, the specification of semantics is the must, … –…to avoid the fate of SQL-99 and ODMG standards, perceived as loose recommendations rather than technical specifications. SBA offers the unique method of query languages’ construction and semantic specification. –SBA is a holistic database theory, it doesn’t give up any (even the most advanced) feature of current practical O-O database QL/PL. –Efficiency has been proven by several implementations. The new standardization activity should not trust the currently well-known concepts concerning O-O query languages. –IMO: limited, imprecise, immature, inconsistent. –Following them standard’s qualities will be among nice wishes. So far SBA has no serious competitive approach.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.