SQLite Study Notes (3)

Source: Internet
Author: User

SQLite architecture:

SQLite is composed of interfaces, compilers, virtual machines, and backend servers.Program(Back end.

 

Two other architecture diagrams are relatively simple:

 

Interface ):

It is composed of SQLite C APIs. Programs, scripts, library files, and so on interact with the database and are converted to API calls (the same is true for ODBC and JDBC ). Database users communicate with the database through APIS.

Compiler (compiler ):

Contains tokenizer, parser ),CodeCode Generator ). Tokenizer and parser are responsible for checking the SQL syntax, converting it into a hierarchical data structure syntax tree, sending code genetator to process it into assembly code, and sending it to the VM for execution.

Virtual Machine ):

Virtual database enegine is also the most important part of the kernel. Based on registers, 128 operation commands (Opcodes) are independent of the OS, CPU, and system systems of the system and are specially used to process data. All the commands in its instruction set can be used to perform specific database operations (such as opening a table cursor, recording, extracting a column, or starting a transaction ), or you can control the stack in some way to prepare for these operations. All SQL statements in SQLite-from selecting and updating records to creating tables, views, and indexes-are first compiled into a virtual machine language to form an independent instruction set that defines how to complete a given command. Vdbe is the core of SQLite. All of its previous modules are used to create the vdbe program, and all of its subsequent modules are used to execute the vdbe program and execute a command each time.

Back end ):

Including B-tree, page cache (PAGER), and operating system interface (System Call ). B-tree and page cache jointly manage data. The main function of B-tree is indexing, which maintains the complex relationship between pages and facilitates the quick discovery of the required data. The main function of pager is to pass pages between B-tree and disk through the OS interface. B-tree is responsible for sorting. It maintains a complex relationship between multiple pages, which ensures fast locating and finding all associated data. B-tree organizes pages into a tree structure (which is also called B-tree). This structure is suitable for searching, and pages are the leaves of the tree.

In details, pager (a Data Structure of SQLite) helps B-tree to manage pages, which are responsible for transmission. Pager reads pages from the disk or writes pages to the disk based on B-tree requests. Disk operations are currently one of the most slow tasks that computers must do. Therefore, pager tries to accelerate this operation by caching frequently used pages in the memory, thus minimizing the time it takes for direct interaction with the hard disk. The pager function description page contains transaction management, database locks, and crash recovery. Many of these functions are implemented through the OS interface. Many things like filelock are implemented differently on different operating systems. OS interface (OS
Interface) provides an abstraction layer for other SQLite modules to block these differences. The final result is that other modules see a consistent external system interface. Therefore, pager does not have to worry about locking files in one way on windows, but on other operating systems (such as UNIX. This makes it easy for SQLite to be transplanted to different operating systems.

Note that the last graph can be interpreted as follows:

The SQL statements and SQLite commands passed by the front-end preprocessing application. Analyze, optimize, and convert the obtained encoding to the SQLite internal bytecode that can be executed by the backend. The backend is the engine used to explain the bytecode program. This engine is used for real database processing.

Tool and test code:

The tool module contains a variety of practical functions, and some public services such as memory allocation, string comparison, and Unicode conversion are also in the tool module. This module is an all-encompassing toolbox. Many other modules need to call and share it. The test module contains countless regression test statements to check every detail of the database code. This module is one of the reasons why SQLite performance is so reliable.

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.