Urgent.News

What's breaking now, across hundreds of outlets.

Tech

How a Query Planner Chooses the Fastest Path

SQL is declarative. You write what you want: "the names of customers in Oran who ordered this month". You do not write how to get it: which table to read first, whether to use an index, how to combine the rows. That decision belongs to the query planner, also called the query optimizer. The same query can run in milliseconds or minutes depending on the plan it picks. This article explains what…

The query optimizer, also known as the query planner, decides how to execute a SQL query, which can have a significant impact on performance. SQL is a declarative language, meaning you specify what you want without detailing how to obtain it. The planner handles tasks such as selecting the optimal table access path, join algorithms, and join order.

Several join methods are available, including nested loop, hash join, and merge join. The choice of join method often plays a more crucial role in performance than the specific join order, particularly with a larger number of tables. The planner estimates the cost of each possible query plan using a cost-based approach, factoring in variables like page reads, row processing, and CPU usage.

These estimates are based on statistics gathered from the database, such as the number of rows, pages, and distinct values in each table and column.

When the database encounters a query, it generates a tree of operators, where leaves read data, and inner nodes combine and transform the data. The planner then selects the plan with the lowest estimated cost. To ensure accurate planning, it is essential to maintain up-to-date statistics on table and column data distribution. This information helps the planner make more informed decisions about the most efficient query execution plan.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

Pattern Matching on Spans and UTF-8 Literals in C# 15 / .NET 11

High-throughput network parsers (Kestrel, custom TCP, Kafka consumers) read wire data as ReadOnlySpan . Historically, running a clean switch statement on headers or commands required either string…

  • C# 15 introduces direct switch pattern matching on byte spans
  • Eliminates zero allocations and Gen0 garbage collection pressure
  • Improves code readability with idiomatic pattern matching syntax

JDBC Mapping Without Reflection: Up to 117 Faster Than Spring JDBC

SQL execution isn't the only cost of a database query. Turning a ResultSet into Java objects costs time and memory, too. What if we generated the mapping code at compile time instead?

  • SJF4J generates mapping code at compile time, 117 times faster than Spring JDBC
  • Uses @CompiledJdbcMapper annotation for compile-time code generation
  • Allocated 50 times less memory than Spring's DataClassRowMapper

More from Tuesday, 1 December 2026 →