Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

A database turns a request such as a SQL query into a set of operations: it checks and interprets the statement, chooses an execution plan, accesses the data, applies transaction rules where needed, and returns rows or a completion status. The exact components differ by database; PostgreSQL, InnoDB, and SQLite are useful examples, not interchangeable blueprints.

How a query travels through a database

In PostgreSQL 18, a typical query follows a documented path from the client to the engine and back. The stages below describe PostgreSQL specifically; other systems may organize the work differently.

  1. The client sends SQL. An application connects to PostgreSQL, sends a statement, and waits for the response. PostgreSQL 18: The Path of a Query
  2. The parser checks the statement. PostgreSQL checks SQL syntax and builds an internal representation of the query. A syntax error can stop the request here.
  3. The rewrite system may transform it. PostgreSQL applies rules from its catalogs. For example, a query against a view can be expanded into a query against the view’s underlying tables.
  4. The planner chooses a plan. It considers ways to retrieve and process the data, estimates their costs, and selects a plan. If suitable indexes exist, an index scan may be one option; a sequential scan may be another.
  5. The executor performs the plan. It carries out operations such as scanning relations, checking conditions, joining rows, or sorting results.
  6. The client receives the outcome. PostgreSQL returns the resulting rows or, for a statement that does not return rows, a completion status.

This is a useful mental model, not a universal checklist of components. SQLite, for instance, describes a different approach: it compiles SQL into bytecode and runs that program in a virtual machine. SQLite: Architecture

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Does a database read the whole table?

Not necessarily. A database can scan a table sequentially, use an index, or choose another plan suited to the query. The planner’s choice depends on the statement and its estimates of the available options; the mere presence of an index does not guarantee that it will be used.

SQL describes the result you want, not a fixed set of retrieval steps. SQLite’s query-planning documentation likewise explains that the engine chooses an algorithm for carrying out a statement. SQLite: Query Planning

What the planner is deciding

A plan is a set of operations for producing the requested result. For example, the engine may need to find matching rows, combine rows from related tables, sort them, and evaluate conditions. Different plans can produce the same answer, but they may involve different work.

Indexes make some access paths possible; they are not an automatic speed switch. The planner compares available choices and selects one it estimates will do the work effectively. An index can be useful for one query and not chosen for another. PostgreSQL documents its planning process in The Path of a Query; MySQL 8.4 also documents how its optimizer selects among query plans in Obtaining Information About a Query.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What happens below the execution plan

The plan’s operations need data, and database implementations manage how that data is represented, accessed, cached, and made durable. The terminology and mechanisms vary by product.

As one implementation-specific example, the MySQL 8.0 manual describes InnoDB as using in-memory structures such as a buffer pool and log buffer, alongside on-disk structures including tablespaces, indexes, redo and undo logs, and a doublewrite buffer. Its documentation also covers transactions, locking, and multi-versioning. These are InnoDB details, not features to assume in every database. MySQL 8.0: InnoDB In-Memory Structures and On-Disk Structures

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why SQLite is not just a smaller PostgreSQL

PostgreSQL’s documented query path is centered on a server-side process that receives a connection’s query and passes it through parser, rewrite, planner, and executor stages. SQLite is an embedded library: it compiles SQL into bytecode, runs that program in a virtual machine, and stores tables and indexes using B-trees. PostgreSQL 18: The Path of a Query · SQLite: Architecture

The comparison is about architecture, not which system is universally better. Where the engine runs, how it represents and executes a statement, and how its storage and transaction systems work are all product-specific.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.