When a query is to be executed, a query plan is used by the database to forge a data path where the best and the most efficient types of routes are created. If there are table join, indexes, and a number of rows in the tables, a variety of mathematical calculations using different algorithms are prepared. Having an execution plan is useful when there are issues with SQL, and to debug multiple table joins and index setups, and follow a path to solve a data or programming issue.
Apart from the straightforward SQL statements in a plain format, there will be those statements that will be used within iOS and wrapped in one of the languages such as Objective-C or Swift.
When the query execution plan is executed, the data, the information, is geared for debugging only and should be used as guidance. Every SQLite release will have different updates that affect the product. The whole idea of a plan is to outline the strategy path an SQL command takes.
A keyword called EXPLAIN, or a phrase, namely, EXPLAIN QUERY PLAN, is required to be used for obtaining the details of a table. These commands are for debugging and analysis only. These commands are partially documented and the behavior is not always 100%:
Next, we see what an SQL statement with a salary
selection will look like. Using the EXPLAIN QUERY PLAN
command with the SELECT
statement, the basic plan outlines the order of the table with its name. By learning the query execution plans effectively, you get a view of how SQLite accesses your data and see how it is committed:
The EXPLAIN QUERY PLAN
command exists as a guidance and plan for executing the SQL Query. It will report and provide information that relates to how the database indices are effectively used to access the data.
The system catalog is also the master place where all tables and indexes are listed. For example, the sqlite_master
table is the, as shown here: