rĪgas tehniskĀ universitĀte - web viewthis interface is well documented and provides access to...

49
Datu bāzes vadības sistēmas arhitektūra

Upload: duongtu

Post on 06-Mar-2018

216 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

Datu bāzes vadības sistēmas arhitektūra

Page 2: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

2

Page 3: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

3

Oracle DBVS kodola slāņi (layers)

The Oracle call interface (OCI)The Oracle call interface is the lowest level at which client programs are intended to interact with Oracle. This interface is well documented and provides access to most of the functionality of Oracle, including advanced features such as object navigation, and sophisticated transaction and session control. Applications with advanced requirements have to use OCI directly, in order to access the features that are not available in Oracle’s other development tools.The user program interface (UPI)OCI is based on the user program interface. There are some UPI facilities that are not yet available via OCI, and so some of the Oracle tools actually call this interface directly. Precompiler programs also call the user program interface, but indirectly via the SQLLIB library, which is an undocumented alternative to OCI.The Oracle program interface (OPI)The user program interface is the lowest layer of the client-side call stack, and the Oracle program interface is the highest layer of the server-side call stack. In most configurations, Net8 bridges the gap between UPI and OPI. However, in single-task executables there is no gap, and the UPI calls correspond directly to OPI calls.The compilation layer (KK)This is the top layer of the Oracle kernel proper. This layer is responsible for the parsing and optimization of SQL statements and for the compilation of PL/SQL program units.The execution layer (KX)This layer handles the binding and execution of SQL statements and PL/SQL program units. It is also responsible for the execution of recursive calls for trigger execution, and for the execution of SQL statements within PL/SQL program units.The distributed execution layer (K2)

Page 4: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

4

The distributed execution layer establishes the transaction branches for distributed transactions, and handles the management of the two-phase commit protocol.The network program interface (NPI)When remote objects are referenced in a SQL statement, the network program interface sends the decomposed statement components to the remote database instances and receives the data in return.The security layer (KZ)This layer is called by the compilation and execution layers to validate the required object and system privileges.The query layer (KQ)This layer provides rows to the higher layers. In particular, the query layer is responsible for caching rows from the data dictionary, for use by the security and compilation layers.The recursive program interface (RPI)The recursive program interface is used to populate the dictionary cache from the data dictionary. Row cache recursive SQL statements are executed in a separate call context, but are not parsed and optimized in the compilation layer.The access layer (KA)The access layer is responsible for access to database segments. This is the first layer of the lower half of the kernel.The data layer (KD)This layer is responsible for the management and interpretation of data within the blocks of database segments such as tables, clusters, and indexes.The transaction layer (KT)This layer is responsible for the allocation of transactions to rollback segments, interested transaction list changes within data blocks, changes to rollback segment blocks for undo generation, transaction control facilities such as savepoints, and read consistency. The transaction layer is also responsible for space management, both at the level of segment free lists and at the level of tablespace extent allocation.The cache layer (KC)The cache layer manages the database buffer cache. It uses operating system dependent facilities for data file I/O, provides concurrency control facilities for local access to the cache buffers, and provides parallel cache management (PCM) instance locking facilities for Oracle parallel server. The other main responsibility of the cache layer is the control of redo generation into the log buffer, and the writing of redo to the log files. The cache layer also caches control file information.The services layer (KS)The services layer provides low-level services that are used by all the higher layers, such as error handling, debugging, and tracing facilities, as well as parameter control and memory services. In particular, the service layer is responsible for generic concurrency control facilities such as latches, event waits, enqueue locks, and instance locks. This layer is also responsible for the management of the data structures for background and user processes and sessions, as well as state objects, inter-process messages, and system statistics.The lock management layer (KJ)This layer is responsible for the locking used for synchronization and communication between the instances of a parallel server database.The generic layer (KG)The generic layer provides management for the generic data structures that are used by the higher layers, such as linked lists. Of particular interest are the library cache and the memory allocation heaps used for the shared pool and session memory.The operating system dependencies (S)Oracle uses operating system facilities for I/O, process scheduling, memory management, and other operations. The implementation details are operating system dependent, and so these details are isolated into a separate layer.

Page 5: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

5

Dati

Datu tips Raksturojums

Vienkārši

strukturēti dati

Dati, kas var tikt organizēti vienkāršās tabulās, kas ir

strukturētas, balstoties uz noteiktiem biznesa likumiem.

Sarežģīti

strukturēti dati

Dati, kas pēc būtības ir komplicēti, un to aprakstīšanai

praktiski neiztikt bez objektu – relāciju DBVS

iespējām, starp kurām ir lietotāju definētie datu tipi,

kolekcijas, atsauces u.c.

Daļēji

strukturēti dati

Dati, kuriem ir noteikta loģiska struktūra, un kurus

parasti datu bāzes nespēj interpretēt – tādi var būt

specifiska formāta dokumenti.

Nestrukturēti

dati

Dati, kas netiek sadalīti mazākās loģiskās struktūrās, un

tos parasti neinterpretē nedz lietojums, nedz arī datu

bāzes vadības sistēma – par piemēru var kalpot attēls,

kas ir saglabāts binārā formātā; taču pat tādi dati bieži

vien satur noteiktu papildinformāciju (attēla gadījumā

tas varētu būt tā paplašinājums, krāsu skaits u.c.)

Page 6: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

6

DBVS kodols un tā paplašināšana

Oracle nodrošina lietotāju ar plašu interfeisu klāstu visdažādāko DBVS kodola paplašināšanas iespēju realizācijai. Noteiktā veidā realizējot iespējamos interfeisus, lietotājs var definēt visdažādākās funkcijas, kuras izpildīs serveris, apstrādājot problēmsfēras datus. Programmēšanas gaitā ir pieejams noteikts datu bāzes servisu klāsts, kas dod iespēju mijiedarboties ar datu bāzes kodolu (darboties ar paplašināmo tipu sistēmu, konstruēt un izpildīt vaicājumus, mijiedarbība starp dažādām programmēšanas valodām u.c.) Kodola paplašinājumu vienkāršoti var uztvert kā neatkarīgi izstrādājamu programmu (bieži vien arī dažādās valodās), kas, pateicoties Oracle paplašināšanas arhitektūrai, tiek cieši integrēta ar kodolu un paplašina to.

Page 7: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

7

Internet Computing arhitektūras

Page 8: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

8

Data cartridges

Data cartridges extend the capabilities of the Oracle server by taking advantage of Oracle Extensibility Architecture framework. This framework lets you capture business logic and processes associated with specialized or domain-specific data in user-defined datatypes. You can customize the indexing and query optimization mechanisms of an extensible database management system and provide specialized services or more efficient processing for user-defined business objects and rich types. When you register your implementations with the server through extensibility interfaces, you direct the server to implement your customized processing instructions instead of its own default processes.The extensibility interfaces consist of functions that the server calls to execute the custom indexing or optimizing behavior implemented for a data cartridge. The interfaces are defined by Oracle; as a cartridge developer, you must implement the functions or interfaces that have the specialized behavior you require in your application. In general, you implement the functions as static methods of an object type. An object type that implements the extensible indexing interface is called an indextype; an object type that implements the extensible optimizing interface is called a statistics type.Data cartridges have the following key characteristics: Data cartridges are server-based. Their constituents reside on the server or are accessed from the server. The server runs all data cartridge processes, or dispatches these processes as external procedures. Data cartridges extend the server. They define new types and behavior, enabling the server to perform processes that were are otherwise unavailable to it, in component form. Data cartridges can use these new types and behaviors in their applications. Data cartridges are integrated with the server. The Oracle Extensibility Framework defines a set of interfaces that integrate data cartridges with the components of the server engine, allowing for domain-specific indexing, domain-specific optimized access to the the CPU resources, and domain-specific optimization of I/O access to cartridge data.

Page 9: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

9

Data cartridges are packaged. A data cartridge is installed as a unit. Once installed, the data cartridge handles all access issues for each user, including verification of schemas and privileges.Extensibility Interfaces

DBMS InterfacesThe DBMS interfaces offer the simplest kind of extensibility services. They can be used through extensions to SQL or to the Oracle Call Interface (OCI). For example, the extensible type manager uses the CREATE TYPE syntax in SQL. Similarly, extensible indexing uses DDL and DML support for specifying and manipulating indexes.

Cartridge Basic Service InterfacesCartridge basic interfaces provide generic services like memory management, context management, internationalization, and cartridge-specific management. They implement behavior for new datatypes in the context of the server's execution environment and provide routines that help developers to implement portable and robust server-side methods.

Data Cartridge InterfacesWhen processing user-defined indextypes, Oracle calls data cartridge functions to perform index search or fetch operations. For user-defined query optimization, the query optimizer calls functions implemented by the data cartridge to compute the cost of user-defined operators or functions.

Page 10: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

10

Page 11: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

11

Lielo objektu tipi

Lielā objekta tips Pielietojums

BLOB (Binary Large

Object – binārais

lielais objekts)

Paredzēts jebkura tipa datu glabāšanai binārajā

formātā. Tipiski pielietojams nestrukturētu datu

glabāšanai (piem., attēls, audioieraksts u.c.)

CLOB (Character

Large Object –

simbolu lielais objekts)

Saglabā teksta datus datu bāzē kā simbolus. Tiek

pielietots liela izmēra tekstu glabāšanai (tiek

pielietots datu bāzes simbolu formāts).

NCLOB (National

Character Lage Object

– nacionālo simbolu

lielais objekts)

Teksta glabāšana nacionālo simbolu formātā.

Tiek pielietots liela izmēra tekstu glabāšanai,

kuros tiek izmantots datu bāzē nokonfigurētais

nacionālo simbolu formāts.

BFILE (External

Binary File – ārējais

binārais fails)

Piekļuve binārajiem failiem, kas glabājas ārpus

datu bāzes un satur noteiktu informāciju. Šī

informācija var tikt tikai nolasīta, bet tas

nenoliedz tālāko manipulāciju ar šiem datiem vai

arī to interpretāciju un saglabāšanu citu veidu

lielajos objektos.

Page 12: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

12

Page 13: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

13

Valodu mijiedarbība

Par šo drošību atbild extproc (external procedure) – speciāls izdalīts ārējās procedūras aģents, kas nodrošina ārējo procedūru izpildi. Neapšaubāmi, šajā shēmā parādās arī Listener process, kurš atbild uz lietotāja procesu prasībām pieslēgties datu bāzei, un līdz ar to darbojas kā starpposms starp lietojumu un datu bāzi. Izmantojot tīkla pieslēgumu, kuru nodibināja Listener process, lietojums nodod ārējās procedūras aģentam bibliotēkas vārdu, ārējās procedūras nosaukumu un visus nepieciešamos parametrus.

Page 14: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

14

Kodola paplašināšanas process

Problēmu vides analīze

Nepieciešamo objektu noteikšana

Objektu tipu definēšana ar SQL un PL/SQL

Nepieciešamās metodes problēmu vidē

IndekssEksistējošs

indekssJauna indeksa tipa definēšana

multi-domain

Indeksa definēšana

Eksistējošā optimizatora lietošana

Optimizatora paplašināšana

Testēšana

Scenāriju komandu izpilde

Izmaksas

Page 15: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

15

The database components that make up each cartridge must be installed in a schema that has the same name as the cartridge. If a cartridge uses multiple schemas, the first 10 characters of each schema name must be the same as the cartridge name. Note that the length of schema names in Oracle is limited to 30 bytes, or 30 characters in a single-byte language.

The database components of a data cartridge that must be placed in the cartridge schema include names for types, tables, views, directories, libraries and packages. Because the schema name and username are always the same in Oracle, the choice of a schema name determines the username.

Page 16: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

16

Data cartridge komponenšu veidošana

1. Objektu tipu definēšana.2. Implementing Data Cartridges in PL/SQL3. Implementing Data Cartridges in C, C++ and Java4. Working with Multimedia Datatypes5. Using Extensible Indexing6. Building Domain Indexes7. Defining Operators8. Using Extensible Optimizer9. User-Defined Aggregate Functions10. Using Cartridge Services11.Using Pipelined and Parallel Table Functions12. Designing Data Cartridges

Page 17: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

17

1. Objekta tipu definēšana.

Page 18: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

18

2. Implementing Data Cartridges in PL/SQLMetodes

Problēmsfēras operatoru izteiksmju piemēri

Operatora izteiksme Patiesumvērtība

ENERGO_VIENADS(paraugs,

1, 5) = 1

Patiess, jo 1. reģiona vērtība ir 5

ENERGO_LIELAKS(paraugs,

2, 8) = 0

Patiess, jo 2. reģiona vērtība nav lielāka par 8

ENERGO_VIENADS_JEBK

(paraugs, 3) = 1

Aplams, jo neviena no vērtībām nav vienāda ar 3

ENERGO_LIELAKS_JEKB

(paraugs, 13) = 1

Patiess, jo 12. reģiona vērtība tik tiešām ir lielāka

par 13

ENERGO_MAZAKS_JEBK

(paraugs, 6) = 0

Aplams, jo vairākas vērtības ir mazākas par 6

Oracle operatori tiek piesaistīti konkrētajām funkcijām. Līdz ar to sākumā ir jāizveido attiecīgās

funkcijas, un pēc tam ar noteiktu komandu palīdzību jāpiesaista operatoriem.

Page 19: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

19

3. Implementing Data Cartridges in C, C++ and Java

To support such special-purpose processing, PL/SQL provides an interface for calling routines written in other languages. This makes the strengths and capabilities of 3GLs like C available through calls from a database server. Such a 3GL routine, called an external procedure, is stored in a shared library, registered with PL/SQL, and called from PL/SQL at runtime to perform special-purpose processing.

External ProceduresUsing Shared LibrariesRegistering an External ProcedureHow PL/SQL Calls an External ProcedureConfiguration Files for External ProceduresDoing CallbacksCommon Potential ErrorsDebugging External ProceduresGuidelines for Using External Procedures with Data CartridgesJava Methods

Page 21: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

21

5. Paplašināmās indeksēšanas mehānisms

B-koka indeks

Hash indekss

Tā kā indeksēšana dažādiem datu tipiem var krasi atšķirties, Oracle piedāvā universālu paplašināmās indeksācijas mehānismu, ar kura palīdzību ir iespējams: definēt problēmsfēras indeksu kā jaunu indeksa tipu; glabāt indeksa datus vai nu Oracle DB (tabulu veidā), vai arī ārpus tās; kontrolēt, izgūt un izmantot indeksu datus, lai optimālāk realizētu lietotāja vaicājumus.

Page 22: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

22

Objektu kolonnas indeksēšanas princips

Attēlā redzams, kā pirmās trīs kolekcijas vērtības nonāk indeksa tabulā. Katrai vērtībai tiek norādīta attiecīga pozīcija kolekcijā, un visām trim vērtībām ir viens un tas pats attiecīgās rindiņas identifikācijas numurs.

Page 23: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

23

Indeksa interfeisa metožu raksturojums

Indkesa metode Apraksts

ODCIGetInterfaces Atgriež interfeisa versiju realizējamajam indeksam („ODCIINDEX2” gadījumā, ja izmanto jaunākas Oracle 9i iespējas, pretējā gadījumā „ODCIINDEX1”).

ODCIIndexCreate Izveido tabulu, kur tiek glabāti indeksējamie dati, tiek izsaukta indeksa izveides laikā. Jāparedz gadījumi, kad pamattabula nav tukša.

ODCIIndexDrop Izdzēš tabulu ar indeksējamajiem datiem. Tiek izsaukta DROP INDEX vai pamattabulas dzēšanas gadījumā.

ODCIIndexAlter Atjauno indeksa tabulu, balstoties uz izmainītajiem indeksa parametriem. Tiek izsaukta ALTER INDEX gadījumā.

ODCIIndexStart Inicializē indeksa skenēšanu iepriekšdefinētam un ar indeksa tipu sasaistītam operatoram. Pēc būtības nodefinē kursoru vaicājumam, kas tiek konstruēts uz operatora bāzes (gadījumā, kad vaicājumā parādās operatori, kuri var tikt analizēti ar indeksa palīdzību).

ODCIIndexFetch Atgriež ROWID katrai rindiņai, kura apmierina operatora predikātu, t.i., ar indeksa palīdzību izgūstam nepieciešamās rindiņas.

ODCIIndexClose Beidz vaicājuma izpildi, aizver kursoru

ODCIIndexInsert Maina indeksa struktūru gadījumā, kad pamattabulā tiek ievietoti dati.

ODCIIndexDelete Maina indeksa struktūru gadījumā, kad no pamattabulas tiek izdzēsti dati.

ODCIIndexUpdate Maina indeksa struktūru gadījumā, kad pamattabulā tiek atjaunoti dati.

ODCIIndexGetMetadata

Dod iespēju eksportēt un importēt ar indeksu realizāciju saistītus metadatus.

Page 24: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

24

Indextypes: An indextype schema object specifies the routines that manage definition, maintenance, and scan operations for application-specific indexes. An indextype tells the Oracle server how to establish a user-defined index on a column of a table or attribute of an object.

Domain Indexes: An application-specific index created using an indextype is called a domain index because it indexes data in application-specific domains. A domain index is an instance of an index that is created, managed, and accessed by the routines specified by an indextype.

Operators: Queries and data manipulation statements can use application-specific operators, such as the Overlaps operator in the spatial domain. User-defined operators are bound to functions. They can also be evaluated using indexes. For instance, the equality operator can be evaluated using a hash index. An indextype provides an index-based implementation for the operators it defines. For detailed information on user-defined operator,

Index-Organized Tables: With index-organized tables, your application can define, build, maintain, and access indexes for complex objects using a table metaphor. To the application, an index is modeled as a table, where each row is an index entry. Index-organized tables handle duplicate index entries, which can be important with complex types of data.

Page 25: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

25

Example: A Text Indextype

Defining the IndextypeThe order in which you create the components of an indextype depends on whether or not you are creating an index-based functional implementation.

Non-Index-Based Functional ImplementationsTo define the Text indextype, the indextype designer must:1. Define and code the functional implementation for the supported operatorThe Text indextype supports an operator called Contains, which accepts a text value and a key, and returns a number indicating whether the text contains the key. The functional implementation of this operator is a regular function defined as:CREATE FUNCTION TextContains(Text IN VARCHAR2, Key IN VARCHAR2)RETURN NUMBER ASBEGIN.......END TextContains;

2. Create the new operator and bind it to the functional implementationCREATE OPERATOR ContainsBINDING (VARCHAR2, VARCHAR2) RETURN NUMBER USING TextContains;

3. Define a type that implements the index interface ODCIIndexThis involves implementing routines for index definition, index maintenance, and index scan operations. Oracle calls:o The index definition routines (ODCIIndexCreate, ODCIIndexAlter, ODCIIndexDrop, ODCIIndexTruncate) to perform the appropriate operations when the index is created, altered, or dropped, or the base table is truncatedo The index maintenance routines (ODCIIndexInsert, ODCIIndexDelete, ODCIIndexUpdate) to maintain the text index when table rows are inserted, deleted, or updatedo The index scan routines (ODCIIndexStart, ODCIIndexFetch, ODCIIndexClose) to scan the text index and retrieve rows of the base table that satisfy the operator predicateCREATE TYPE TextIndexMethods(STATIC FUNCTION ODCIIndexCreate(...)...);CREATE TYPE BODY TextIndexMethods(...);

4. Create the Text indextype schema objectThe indextype definition specifies the operators supported by the new indextype and the type that implements the index interface.CREATE INDEXTYPE TextIndexTypeFOR Contains(VARCHAR2, VARCHAR2)USING TextIndexMethods;

Page 26: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

26

Index-Based Functional Implementations

If you are creating an index-based functional implementation, you perform the same operations as for non-index-based functional implementations, but in a different order:1. Define the implementation type2. Define and code the functional implementation3. Create the operator4. Create the indextypeThis order is required because definition of an index-based functional implementation requires the implementation type as a parameter.

Using the IndextypeWhen the Text indextype presented in the previous section has been defined, users can define text indexes on text columns and use the Contains operator to query text data.Suppose the Employees table is defined by the statement:CREATE TABLE Employees(name VARCHAR2(64), id INTEGER, resume VARCHAR2(2000));

To build a text domain index on the resume column, a user issues the following statement:CREATE INDEX ResumeIndex ON Employees(resume) INDEXTYPE IS TextIndexType;

To query the text data in the resume column, users issue statements like:SELECT * FROM Employees WHERE Contains(resume, 'Oracle') =1;

The query execution uses the text index on resume to evaluate the Contains predicate.

Page 27: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

27

6. Building Domain Indexes

A domain index is an index designed for a specialized domain, such as spatial or image processing. Users can build a domain index of a given type after the designer creates the indextype.Indextypes encapsulate search and retrieval methods for complex domains such as text, spatial, and image processing. An indextype is similar to the indexes that are supplied with the Oracle server. The difference is that you provide the application software that implements the indextype.

An indextype has two major components:1) The methods that implement the behavior of the indextype, such as creating and scanning the index2) The operators that the indextype supports, such as Contains or Overlaps

To create an indextype:1) Define the supported operators and create the functions that implement them2) Create the methods that implement the ODCIIndex interface, and define the type that encapsulates them, called the implementation type3) Create the indextype, specifying the implementation type and listing the operators with their bindings

Page 28: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

28

7. Defining Operators

An operator binding associates the operator with the signature of a function that implements the operator. A signature consists of a list of the datatypes of the arguments of the function, in order of occurrence, and the function's return type. Operator bindings tell Oracle which function to execute when the operator is invoked. An operator can be bound to more than one function if each function has a different signature. To be considered different, functions must have different argument lists. Functions whose argument lists match, but whose return datatypes do not match, are not considered different and cannot be bound to the same operator.

create function SALIDZIN (a VARCHAR2, b VARCHAR2) RETURN NUMBER ASBEGIN IF a = b THEN RETURN 1; ELSE RETURN 0; END IF;END;

create operator SAL BINDING (VARCHAR2, VARCHAR2) RETURN NUMBER USING SALIDZIN;

Operators are often defined in connection with indextypes. After creating the operators with their functional implementations, you can create an indextype that supports evaluations of these operators using an index scan.

Page 29: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

29

8. Paplašināmais optimizators

Ar paplašināmā optimizatora palīdzību ir iespējams:1) sasaistīt izmaksu funkcijas ar problēmsfēru indeksiem, indeksu tipiem, pakotnēm, kā arī atsevišķām funkcijām; optimizators var novērtēt problēmsfēras indeksa skenēšanas izmaksas;2) asociēt selektivitātes funkcijas ar objektu tipu metodēm, pakotņu funkcijām vai arī atsevišķām funkcijām;3) asociēt statistikas kolekcionēšanas funkcijas ar problēmsfēras indeksiem un tabulu kolonnām;4) kārtot predikātus ar funkcijām, balstoties uz izmaksām;5) izvēlēties lietotāja definētu pieejas metodi (problēmsfēras indeksi) tabulai, balstoties uz piekļuves izmaksām;6) izmantot speciālu DBMS_STATS pakotni ar nolūku izsaukt lietotāja definētas statistikas kolekcionēšanas un dzēšanas funkcijas;7) izmantot jaunus datu vārdnīcas skatus, lai iekļautu informāciju par statistikas kolekcionēšanu, izmaksu, vai selektivitātes funkcijām, kas tiek asociētas ar kolonnām, problēmsfēras indeksiem, indeksu tipiem vai funkcijām;8) pievienot padomus (hints) ar nolūku ietekmēt funkciju predikātu izskaitļošanas kārtību.

Page 30: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

30

Paplašināmā optimizatora interfeisa metožu raksturojumiMetode Apraksts

ODCIStatsCollect Metode statistikas savākšanai kolonnai vai indeksa datiem.

ODCIStatsDelete Izdzēš statistiku par kolonnu vai indeksa datiem.

ODCIStatsSelectivity Novērtē lietotāja definētu funkcijas vai operatora predikāta

selektivitāti.

ODCIStatsFunctionCost Balstoties uz uzdotajiem funkcijas parametriem, izskaitļo

funkcijas izpildes izmaksas.

ODCIStatsIndexCost Balstoties uz uzdoto operatora predikātu, izskaitļo

problēmsfēras indeksa skenēšanas izmaksas.

Page 31: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

31

9. Lietotāja definētas agregātfunkcijas

Oracle nodrošina lietotāju ar noteiktām visiem labi zināmām agregātfunkcijām MAX, MIN, SUM u.c., kas veic operācijas ar rindiņu kopām. Šīs definētās agregātfunkcijas var tikt izmantotas tikai skalāriem datiem. Taču bieži rodas vajadzība definēt kādu jaunu funkciju datu analīzei, vai arī agregātfunkciju, kas darbotos ar sarežģītiem – lietotāja definētajiem datiem, līdz ar to realizējot ar problēmsfēru saistīto loģiku.

Lietotāju definētas agregātfunkcijas, analoģiski paplašināmās indeksācijas mehānismam un paplašināmajam optimizatoram, tiek reģistrētas serverī ar interfeisu palīdzību. Tas ir:

1) ODCIAggregateInititalize interfeiss, kurš ir paredzētas metodes agregācijas uzsākšanai;

2) agregācijas solim ODCIAggregateIterate;3) agregācijas nobeigšanai ODCIAggregateTerminate.

Lietotāja definētas agregātfunkcijas var piemērot jebkura tipa datiem, līdz ar to arī skalārajiem datiem tas varētu būt ļoti noderīgs rīks, piem., strādājot ar sarežģītiem finansiāliem vai zinātniskiem statistikas datiem.

Page 32: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

32

Agregātfunkciju interfeisa metožu raksturojumi

Metode Apraksts

ODCIAggregateInitialize Šo metodi Oracle izsauc, lai inicializētu lietotāja definētu

agregātfunkciju skaitļošanas procesu. Inicializēta agregāta

konteksts tiek nodots Oracle kā objektu tipa eksemplārs

(kas var saturēt agregātvērtības skaitļošanai nepieciešamos

atribūtus)

ODCIAggregateIterate Metode tiek atkārtoti izsaukta katrai agregātfunkcijā

pielietotajai vērtībai, kas tiek nodota funkcijai kā

arguments. Arī ar šo agregātvērtības skaitļošanas sesiju

saistītais objektu tips (konteksts) tiek nodots kā

arguments. Rezultātā funkcija apstrādā jauno vērtību(as),

un atgriež DBVS atjaunoto kontekstu. Jāpiebilst, ka

NULL vērtības netiek apstrādātas.

ODCIAggregateMerge Metodi Oracle izsauc paralēlās agregātfunkciju

skaitļošanas gadījumā. Tā kombinē divus agregāciju

kontekstus un atgriež galīgo rezultātu.

ODCIAggregateTerminat

e

Metode tiek izsaukta agregācijas pēdējā solī. Metode

atgriež rezultāta vērtību, balstoties uz agregācijas

kontekstu.

You create a user-defined aggregate function by implementing a set of routines collectively known as the ODCIAggregate routines. You can implement these routines as methods within an object type, so the implementation can be in any language that Oracle supports, PL/SQL, C, C++ or Java. Once the object type is defined and the routines are implemented in the type body, use the CREATE FUNCTION statement to create the aggregate function.

Page 33: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

33

Consider the aggregate function AVG() in the following statement:

SELECT AVG(T.Sales)FROM AnnualSales TGROUP BY T.State;To perform this computation, the aggregate function AVG() goes through steps like these:1. Initializes the computation by initializing the aggregation context—the rows over which aggregation is performed:runningSum = 0; runningCount = 0;2. Iteratively processes each successive input value and updates the context:runningSum += inputval; runningCount++;3. [Optional] Merge by combining the two aggregation contexts and return a single context. This operation combines the results of aggregation over subsets in order to obtain the aggregate over the entire set. This extra step can be required during either serial or parallel evaluation of an aggregate. If needed, it is performed before the Terminate step:runningSum = runningSum1 + runningSum2;runningCount = runningCount1 + runningCount24. Terminates by computing the result; uses the context to return the resultant aggregate value:return (runningSum/runningCount);

Page 34: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

34

10. Abstraktās tabulas un tabulu funkcijas

Kodola paplašinājuma izstrādātājam var rasties vajadzība piekļūt datiem,

kas ir ārpus datu bāzes vai arī atrodas lielo objektu eksemplāros. Tādos

gadījumos DBVS nezina neko par šo datu struktūru, pat ja tie ir noteiktā

veidā strukturēti. Šajā gadījumā ir iespējams rīkoties divos veidos:

1. izveidot abstrakto tabulu;

2. vaicājumos izmantot tabulu funkciju.

Abstraktā tabula tiek interpretēta kā parastā, taču par to saturu, kas pēc

būtības ir virtuāls, atbild noteikts objektu tips, kas realizē ODCITable

interfeisu. Tipisks gadījums varētu būt kāds fails failu sistēmā, piem.,

XML fails, kura struktūra nav zināma datu bāzei, bet tajā glabājas tabulāri

interpretējami dati.

Abstrakto tabulu interfeisa metožu raksturojumi

Metode Apraksts

ODCITableStart Uzsāk virtuālo tabulas izskatīšanu.

ODCITableFetch Atgriež rindiņu kopu kārtējā solī.

ODCITableClose Veic nobeigšanas procedūras, kad datu izgūšana ir

beigusies.

Page 35: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

35

Abstrakto tabulu darbības princips ir līdzīgs kursoriem – kamēr rezultāts

nav NULL, notiek izgūstamo datu apstrāde (t.i., tā tiek interpretēta kā

virtuāla tabula). Savukārt, kad šis process beidzas, ar ODCITableClose

metodes palīdzību tiek veikti nobeigšanas darbi (piem., aizvērti datu bāzes

kursori vai arī attīrītas temporālās struktūras vai arī tabulas).

ODCITable interfeisa metožu darbības shēma

Rezultātā lietotāja dati tiek interpretēti tabulas veidā, un tālākā darbība ar

tādu tabulu norit gluži kā ar parastu. Ja ir vajadzība datus papildināt vai

izdzēst (kas, protams, virtuālās tabulas gadījumā nav iespējams), tad var

veidot uz tādas tabulas balstītu skatu un realizēt INSTEAD OF trigeri, kas

imitēs datu ierakstīšanu šajā tabulā vai dzēšanu no tās (t.i., darbosies ar

datu avotu).

Kodola paplašinājuma izstrādātājam var parādīties vajadzība pēc dinamiskas, iteratīvas uzvedības pār virtuāli izveidotajām tabulām. Paplašināšanas arhitektūra tāpat nodrošina iteratīvas tabulu funkcijas kā papildinājumu abstraktām tabulām.

Page 36: RĪGAS TEHNISKĀ UNIVERSITĀTE - Web viewThis interface is well documented and provides access to most of the functionality of Oracle, ... and sophisticated transaction and session

36

11. Using Pipelined and Parallel Table Functions

Table functions are functions that produce a collection of rows (either a nested table or a varray) that can be queried like a physical database table. You use a table function like the name of a database table, in the FROM clause of a query.A table function can take a collection of rows as input. An input collection parameter can be either a collection type or a REF CURSOR.Execution of a table function can be parallelized, and returned rows can be streamed directly to the next process without intermediate staging. Rows from a collection returned by a table function can also be pipelined—that is, iteratively returned as they are produced instead of in a batch after all processing of the table function's input is completed.