English version of the materials are work in progress!
Expect bugs, typos, and other issues. The English version is expected to be completed during spring 2026.
Structure of a Database System
A database management system is generally software with which application programs or users can interact with a database. Generally, the following most essential features are expected from database management systems:
- Execution of basic, or CRUD operations on the database: creating data (Create), searching (Read), updating (Update), and deleting (Delete)
- Physical data independence: the application program does not need to be modified even if the physical structure of the database (database location, data storage formats, or auxiliary structures needed for database operation) is modified
- Logical data independence: the application program does not necessarily need to be modified (or only small modifications are needed) even if the database's logical data model is modified
- Enabling concurrent use of the database
- Enabling data consistency, i.e., integrity
- Minimizing data redundancy
- Compatibility with different systems and DBMSs
- Enabling effortless scalability according to hardware resources and usage
The list above is not a list of mandatory features, but different database management systems offer them variously. Different products have varying amounts of functionality, ranging from the most complex products like Oracle, DB/2, and SQL Server to simple products stripped of features like SQLite. Different versions of products (such as Oracle Express, Standard, and Enterprise) can also be offered, the price of which is determined by the version's features.
Furthermore, different products have additional components, usually for example:
- A graphical user interface for making queries and monitoring the database structure
- Monitoring tools to monitor DBMS performance and load
- Backup tools
- Tools for data reporting, analysis, and mining
- Batch processing function for importing large amounts of data into the database and exporting from the database
- Various middleware to connect the DBMS to other internal or external components of the database system
- Shared components with the operating system or operating system kernel, such as database encryption or compression or sharing user accounts
Flow of a Database Command
Controlling a database management system happens by sending database commands to it. Commands can be sent, for example, in a query language recognized by the database management system (e.g. SQL, see Chapter 4.1), by calling routines pre-stored in the database (e.g. PL/SQL, T/SQL; not covered in this material), or in a programming language recognized by the database management system. In addition to this, there are various tools with which, for example, application program code is converted into query language commands (e.g. ORM tools, see Chapter 6.3).
Let's next examine at a general level what happens to a database command when an application program or user sends it to the DBMS. A database command can be, for example, "Retrieve the price and discount percentage of all red shoes". Details vary from product to product, but the general idea applies to most database management systems.
The application program sends a request to the DBMS to establish a connection. The DBMS can deny the connection, e.g., if the database server memory is low or if the maximum number of users is already connected to the database. If the DBMS accepts the connection establishment, the application program can send the database command.
Command Component
The sent database command ends up next at the DBMS command component. The command component contains several subcomponents, the purpose of which is to interpret, optimize, form the actual plan for executing the command, and finally execute the command. Let's briefly examine the subcomponents:
The Parser checks the spelling of the database command. The parser also writes out possible references and abbreviations. If the command has syntax errors, the parser can correct them according to its tolerance. If errors cannot be corrected, an error message is returned to the application program. Otherwise, the parser creates a so-called parse tree from the query and sends it to the rewriter.
The Rewriter checks the rationality and execution rights of the database command. The rewriter checks from the database metadata whether the database structures contained in the command (e.g., tables, columns) exist and whether the user executing the command has the necessary rights to see or modify them. In addition, this component takes care of simplifyng possible calculations, logical expressions, and inference rules of the database command and opening artificial data structures. As a result, the rewriter produces a query tree, which is taken to the optimizer next.
The Optimizer decides what should be done to the data, how it should be done, and in what order it would be best to do it. Database management system query languages are usually so-called declarative languages, meaning they only describe the desired solution or result. For example, the command "retrieve the price and discount percentage of all red shoes" is a declarative command because it does not tell how the data is actually retrieved from the database. The optimizer's task is therefore to convert the declarative command into possible execution plans (i.e., algorithms) to achieve the requested goal. By examining database metadata, the optimization component decides which of the created execution plans is the fastest to implement in terms of time. The optimizer sends the execution plan it considers best forward to the command runner.
The Runner Component finally executes the execution plan using the storage component as help.
Storage Component
The storage component is a kind of assurer that data is processed correctly. When the runner component starts executing the execution plan, the storage component checks, among other things, the functionality of auxiliary physical data structures important for the command. At this stage, the log management component writes the command to the DBMS log, and if the command makes changes to the database structure, these changes are written to the DBMS metadata.
Next, the DBMS concurrency control component checks if there are other transactions running simultaneously that may interfere with the database command being processed. If everything is in order, the DBMS lock table is written to indicate that the records used by the database command are unavailable to other concurrent transactions (i.e., locked). Locking is returned to in more detail in Chapter 4.5.
Finally, the memory management component performs the actual queries on the data, taking into account the physical structure of the database and the system's memory architecture.
Tietokantajärjestelmän rakenne
Tietokannanhallintajärjestelmä on yleisesti ohjelmisto, jolla sovellusohjelmat tai käyttäjät voivat vuorovaikuttaa tietokannan kanssa. Yleisesti tietokannanhallintajärjestelmiltä odotetaan seuraavia olennaisimpia ominaisuuksia:
- Perus- eli ns. CRUD-operaatioiden suoritus tietokantaan: datan luominen (Create), etsiminen (Read), muokkaaminen (Update) ja poistaminen (Delete)
- Fyysinen tietoriippumattomuus: sovellusohjelmaa ei tarvitse muokata, vaikka tietokannan fyysinen rakenne (tietokannan sijainti, datan tallennusmuotoja tai tietokannan toimintaan tarvittavia apurakenteita) muokattaisiin
- Looginen tietoriippumattomuus: sovellusohjelmaa ei välttämättä tarvitse muokata (tai selvitään pienillä muokkauksilla) vaikka tietokannan looginen tietomalli muokattaisiin
- Tietokannan samanaikaisen käytön mahdollistaminen
- Tiedon ristiriidattomuuden eli eheyden mahdollistaminen
- Datan toisteisuuden minimointi
- Yhteensopivuus eri järjestelmien ja DBMSien kanssa
- Vaivattoman skaalautuvuuden mahdollistaminen laitteiston resurssien ja käytön mukaan
Yllä oleva lista ei ole pakollisten ominaisuuksien lista, vaan eri tietokannanhallintajärjestelmät tarjoavat niitä vaihtelevasti. Eri tuotteissa on vaihteleva määrä toiminnallisuutta aina monimutkaisimmista tuotteista kuten Oracle, DB/2 ja SQL Server yksinkertaisiin ja ominaisuuksiltaan riisuttuihin tuotteisiin kuten SQLite. Tuotteista voidaan myös tarjota erilaisia versioita (kuten Oracle Express, Standard ja Enterprise), joiden hinta määräytyy version ominaisuuksien mukaan.
Edelleen eri tuotteissa on lisäkomponentteja, tavallisesti esimerkiksi:
- Graafinen käyttöliittymä kyselyiden tekemiseen ja tietokannan rakenteen seuraamiseen
- Monitorointityökalut, joiden avulla DBMS:n suorituskykyä ja kuormitusta voidaan seurata
- Varmuuskopiointityökalut
- Työkalut datan raportointiin, analysointiin ja louhintaan
- Eräajotoiminto suurten datamäärien viemiseen tietokantaan ja tuomiseen tietokannasta
- Erilaiset väliohjelmistot DBMS:n liittämiseksi muihin tietokantajärjestelmän sisäisiin tai sen ulkopuolisiin komponentteihin
- Jaetut komponentit käyttöjärjestelmän tai käyttöjärjestelmäytimen kanssa, esimerkiksi tietokannan salaus tai pakkaaminen tai käyttäjätilien jakaminen
Tietokantakäskyn kulku
Tietokannanhallintajärjestelmän ohjaaminen tapahtuu lähettämällä sille tietokantakäskyjä. Käskyjä voidaan lähettää esimerkiksi tietokannanhallintajärjestelmän tunnistamalla kyselykielellä (esim. SQL, ks. Luku 4.1), kutsumalla tietokantaan valmiiksi tallennettuja rutiineja (esim. PL/SQL, T/SQL; ei käsitellä tässä materiaalissa) tai tietokannanhallintajärjestelmän tunnistamalla ohjelmointikielellä. Tämän lisäksi on olemassa erilaisia työkaluja, joilla esimerkiksi sovellusohjelman koodi muunnetaan kyselykielen käskyiksi (esim. ORM-työkalut, ks. Luku 6.3).
Tarkastellaan seuraavaksi yleisellä tasolla, mitä tietokantakäskylle tapahtuu, kun sovellusohjelma tai käyttäjä lähettää sen DBMS:lle. Tietokantakäsky voi olla esimerkiksi "Hae kaikkien punaisten kenkien hinta ja alennusprosentti". Yksityiskohdat riippuvat tuotteesta toiseen, mutta yleinen ajatus pätee useimmille tietokannanhallintajärjestelmille.
Sovellusohjelma lähettää pyynnön DBMS:lle yhteyden muodostamiseksi. DBMS voi evätä yhteyden esim. jos tietokantapalvelimen muisti on vähissä tai jos enimmäismäärä käyttäjiä on jo yhdistyneenä tietokantaan. Jos DBMS hyväksyy yhteyden muodostamisen, voi sovellusohjelma lähettää tietokantakäskyn.
Käskykomponentti
Lähetetty tietokantakäsky päätyy seuraavaksi DBMS:n käskykomponentille. Käskykomponentti sisältää useita alikomponentteja, joiden tarkoitus on tulkita, optimoida, muodostaa varsinaisen suunnitelman käskyn suorittamiselle ja lopuksi suorittaa käsky. Tarkastellaan lyhyesti alikomponentteja:
Parseri tarkastaa tietokantakäskyn oikeinkirjoituksen. Parseri myös kirjoittaa mahdolliset viitteet ja lyhenteet auki. Jos käskyssä on syntaksivirheitä, parseri voi sietokykynsä mukaan korjata niitä. Jos virheitä ei pystytä korjaamaan, sovellusohjelmalle palautetaan virheilmoitus. Muussa tapauksessa parseri luo kyselystä ns. jäsennyspuun (parse tree), ja lähettää sen uudelleenkirjoittajalle.
Uudelleenkirjoittaja tarkastaa tietokantakäskyn järkevyyttä ja suoritusoikeutta. Uudelleenkirjoittaja tarkastaa tietokannan metadatasta, onko käskyn sisältämiä tietokantarakenteita (esim. tauluja, sarakkeita) olemassa ja onko käskyn suorittavalla käyttäjällä tarvittavat oikeudet nähdä tai muokata niitä. Lisäksi tämä komponentti huolehtii mm. tietokantakäskyn mahdollisten laskutoimitusten, loogisten lausekkeiden ja päättelysääntöjen sievennyksestä ja keinotekoisten tietorakenteiden avaamisesta. Tuloksena uudelleenkirjoittaja tuottaa kyselypuun (query tree), joka viedään seuraavaksi optimoijalle.
Optimoija päättää, mitä datalle tulee tehdä, miten se tulee tehdä ja missä järjestyksessä se olisi parasta tehdä. Tietokannanhallintajärjestelmän kyselykielet ovat yleensä ns. deklaratiivisia kieliä, eli niillä kuvataan vain haluttu ratkaisu tai lopputulos. Esimerkiksi käsky "hae kaikkien punaisten kenkien hinta ja alennusprosentti" on deklaratiivinen käsky, sillä se ei kerro, miten varsinaisesti dataa haetaan tietokannasta. Optimoijan tehtävä onkin siis muuntaa deklaratiivinen käsky mahdollisiksi suoritussuunnitelmiksi (eli algoritmeiksi), joilla saavutetaan pyydetty tavoite. Tietokannan metadataa tarkastelemalla optimointikomponentti päättää, mikä luoduista suoritussuunnitelmista on ajallisesti nopein toteuttaa. Optimoija lähettää parhaaksi katsomansa suoritussuunnitelman eteenpäin käskyn ajajalle.
Ajokomponentti lopuksi suorittaa suoritussuunnitelman käyttäen apuna varastointikomponenttia.
Varastointikomponentti
Varastointikomponentti on eräänlainen varmistin sille, että dataa käsitellään oikein. Kun ajokomponentti aloittaa suoritussuunnitelman suorittamisen, varastointikomponentti tarkastaa mm. käskyn kannalta tärkeiden, avustavien fyysisten tietorakenteiden toiminnallisuuden. Tässä vaiheessa lokinhallintakomponentti kirjoittaa käskyn DBMS:n lokiin, ja jos käsky tekee muutoksia tietokannan rakenteeseen, nämä muutokset kirjoitetaan DBMS:n metadataan.
Seuraavaksi DBMS:n rinnakkaisuudenhallintakomponentti tarkastaa, onko samanaikaisesti käynnissä muita tapahtumia, jotka voivat haitata käsiteltävää tietokantakäskyä. Jos kaikki on kunnossa, DBMS:n lukkotauluun kirjoitetaan tietokantakäskyn käyttävien tietueiden olevan muiden samanaikaisten tapahtumien käyttämättömissä (ts. lukittuna). Lukitukseen palataan tarkemmin Luvussa 4.5.
Lopuksi muistinhallintakomponentti tekee varsinaiset kyselyt dataan tietokannan fyysista rakennetta sekä järjestelmän muistiarkkitehtuuria huomioon ottaen.
These are the current permissions for this document; please modify if needed. You can always modify these permissions from the manage page.