×

Query optimization in DBMS

Choosing an effective execution strategy to execute a query is a process known as query optimization.

After the decision-making process of query parsing, which determines how many distinct ways a given query can be executed, the parsed query is sent to the query optimizer, which creates several execution plans to examine the parsed query and choose the one with the lowest estimated cost.

By producing the costs of each plan, the catalog manager helps the optimizer choose the best one to execute the query.

Query optimization in DBMS

The most effective technique to access and change the database is through query optimization. It is the art of getting the information you need in a timely, dependable, and predictable manner.

 The technique of converting a query into a similar form that may be assessed more quickly is known as query optimization. Finding an execution plan that shortens the time needed to process a query is the aim of query optimization. The objective of query optimization is to process a query. We need to carry out two crucial tasks to achieve this optimization aim.

Purpose of query optimization in DBMS:

An SQL statement's best execution plan is sought after by the optimizer.

The optimizer selects the candidate plan with the lowest cost out of all those that were considered.

The optimizer determines expenses using the available data. For a specific query in a certain environment, the cost computation takes query execution factors like I/O, CPU, and communication into account.

NameclassRole
Harini10CR
Harsha10 

For instance, one question asks for details on students who hold leadership positions, including class representatives. A full table search may be deemed to be the most effective if the optimizer statistics reveal that 50% of students hold leadership roles

Consequently, all SQL statements use the optimizer.

Components of query optimizer:

The transformer, estimator, and plan generator are the three components that make up the optimizer. These elements are represented in the image below.

Query optimization in DBMS
  1. Query transformer:
    The query transformer determines if it is advantageous to change some statements' original SQL statements into less expensive, semantically equivalent SQL statements.
  2. Estimator:
    The overall cost of a particular execution plan is determined by the   optimizer's estimator. The estimator uses three techniques to calculate the cost:
  3. Selectivity: With 0 denoting no rows and 1 denoting all rows, the query selects a percentage of the row set's row selectivity that can be established using a query predicate, such as where the last name LIKE X%, or a mixture of predicates. A predicate grows more selective as the selectivity value approaches zero; in contrast, a predicate becomes less selective as the value approaches one.
  4. Cardinality: The number of rows that each action returns is the cardinality of an execution plan. This input, which is shared by all cost functions, is crucial for choosing the appropriate course of action. The estimated cardinality is displayed in the Rows column of an execution plan.
  5. Cost: This measure shows how many labor or resource units were employed. The query optimizer measures effort in terms of disc I/O, CPU use, and memory usage.
  6. Plan generator: Due to the multiple combinations the database might utilize to get the same goal, there are numerous designs that are feasible.

Automatic tuning optimizer:

Various operations are carried out by the optimizer depending on how it is invoked.

The following categories of optimizations are offered by the database:

  • Normal optimization: After parsing the SQL, the optimizer generates an execution strategy. For most SQL statements, the default option generates a reasonable plan. When operating in regular mode, the optimizer must choose the optimum course of action within severe time restrictions, which are frequently a fraction of a second.
  • SQL tuning advisor optimization: When SQL Tuning Advisor activates the optimizer by passing one or more SQL queries as input, the optimizer is referred to as the Automatic Tuning Optimizer. In this case, the optimizer performs further research to enhance the plan created in regular mode. To create a better plan, the optimizer creates a set of activities, along with their reason and expected payment.

Methods of query optimization in DBMS:

Cost based:

The practice of choosing the most effective way to carry out a SQL statement is known as query optimization. The optimizer can combine, reorganize, and process data in any sequence because SQL is a nonprocedural language.

The optimizer determines a cost estimate for the plan or potential strategy by discovering these values individually for each step of a feasible plan for a given query and environment. After examining all of the costs associated with potential solutions, the optimizer searches for the plan with the lowest cost estimate. The Optimizer is also referred to as the Cost-Based Optimizer as a result.

  • Execution plans: The strategy outlines the actions Oracle Database takes to carry out a SQL statement. Line 0 of an execution plan states the plan's total cost, as well as the cost of each operation. Costs are internal units that only appear in the execution plan to compare plans. The cost value cannot be modified or altered as a result.
  • Query blocks: The optimizer takes as input a parsed version of a SQL statement. Internally, a query block stands in for each SELECT block in the original SQL statement. An unmerged view, a subquery, or a top-level statement can all be included in a query block.

    Consider the following SQL statement, which consists of two distinct query parts. The inner query block consists of the subquery surrounded in parentheses.

    The names of the employees in the departments whose IDs were provided by the subquery are retrieved in the remaining portion of the outer query block of the SQL statement. The query form displays the connections between the query blocks.
  • Adaptive query optimizer in DBMS:
    With adaptive query optimization, the optimizer can modify execution plans in real-time and learn new facts that could improve statistics. Adaptive optimization is useful when the available data are insufficient to generate a perfect plan.

    Adaptive plans are significant because the optimizer occasionally selects a subpar default plan because of an incorrect cardinality estimation. A more ideal final plan results from the ability to adjust the plan as it is being executed based on actual execution statistics. The optimizer selects the final plan and utilizes it for further executions, making sure that the subpar plan is not utilized again.

Related Topics

Components of DBMS

The database management system (DBMS) represents an essential tool for processing data within effectively structured structures. The database management system consists of important components that work together to maintain the...

6 minutes read.

Concurrent Execution of Transaction

In the transaction process, a system usually allows executing more than one transaction simultaneously. This process is called a concurrent execution. Advantages of concurrent execution of a transaction Decrease waiting time or...

4 minutes read.

Difference between Dropbox and Amazon Drive

What is Dropbox? It is a file organising company that is owned by the American Company Dropbox Inc. Itsheadquarters is situated in San Francisco, California, U.S. Dropbox offers personal cloud, client...

3 minutes read.

Integrity Constraints in DBMS

Integrity constraints in DBMS (Database Management System) are used to ensure the accuracy and consistency of data in a database. They are a set of rules that define the allowed...

1 minute read.

ACID Properties in DBMS

A transaction in a database has the following four properties, known as ACID properties. These properties are used to maintain the consistency of the database in the case of system failure and concurrent...

4 minutes read.

Attributes in DBMS

What is Attribute? An attribute is an element in the database management system that describes the property or certain characteristics of the database entity. It is a crucial element of the...

3 minutes read.

B-Tree Insertion in DBMS

A B-tree is a special type of m-way tree, commonly used for disk access. A B-tree of order m can have at most m-1 keys and m descendants. B-trees are...

4 minutes read.

Anomalies in Database Management System

Anomalies in a database management system (DBMS) are problems that can arise when the database is not designed or implemented correctly. These anomalies can affect the integrity and accuracy of...

3 minutes read.

Fragmentation in Distributed DBMS

Fragmentation is a course of isolating the entire or full information base into different sub tables or sub relations with the goal that information can be put away in various...

4 minutes read.

Inference Rules

Armstrong’s axioms are the complete set of basic inference rules used to infer all the functional dependencies on the relational database. An inference rule is a type of assertion that a user can...

2 minutes read.

What is Transaction in DBMS

A transaction is a collection of logically related operations which reads and possibly updates the various data items in the database. Usually, a transaction is initiated by a user program written in high-level...

3 minutes read.

Concurrency Control Protocols

Concurrency Control Protocols Concurrency control protocols ensure the atomicity, serializability and isolation of the concurrent transactions. The Concurrency control protocols can be broadly classified into the following categories: Lock Based ProtocolTimestamp protocol Lock Based Protocol In this protocol,...

5 minutes read.

DBMS Examples

Introduction to DBMS A database management system (DBMS) is a software application that is designed to manage and organize data stored in a database. It is responsible for storing, retrieving, and...

4 minutes read.

Enforcing Integrity Constraints in DBMS

Introduction Integrity constraints are rules that specify the conditions that must be met for the data in a database to be considered valid. These constraints help to ensure the accuracy and...

2 minutes read.

DBMS Generalization, Specialization, and Aggregation

DBMS Generalization Generalization is a bottom-up approach in which the common attributes of two or more lower-level entities combines to form a new higher-level entity. In generalization, the generalized entity of higher level can also...

3 minutes read.

Difference between File System and DBMS

What is File Management System? A file management system is a collection of programs that manage and store data in files and folders in a computer hard disk. A file management...

9 minutes read.

Query processing in DBMS

Operations on DBMSs are made much simpler, more organized, and methodical with SQL. These are not only simpler for people to comprehend, but after gaining a basic comprehension of them, they...

4 minutes read.

ER Diagram for Company Database in DBMS

What is ER Diagram? An ER diagram (short for Entity Relationship Diagram), also known as an ERD, is a diagram that shows the relationships of a set of entities stored in...

7 minutes read.

Advantages and Disadvantages of DBMS

We need to understand what is Database Management System before discussing the advantages and disadvantages of the database management system, and also, need to understand what were the technologies and...

5 minutes read.

Red-Black Tree Deletion in DBMS

Introduction To Red Black Tree Each node's extra bit in a red-black tree, a type of self-balancing binary search tree, is frequently understood as the color (red or black). The balance...

3 minutes read.