# Query execution plan

The `EXPLAIN` command shows the execution plan of a statement. It means you can see details on the approach that the planner took to execute the statement. For example, how the tables are scanned, what join algorithms are used to bring together the required rows, statement execution costs, and other information.

Execution cost is the planner's guess at how long it takes to run the statement. The measurement is made in relative cost units. The execution cost has two options: start-up and total. The start-up cost shows how long it takes before the first row can be processed, while the total cost shows how long it takes to process all the rows.

IntelliJ IDEA provides the following actions for the `EXPLAIN` command:

* Explain Plan: the statement is only planned.

* Explain Analyse: the statement is actually executed, not only planned. In this case, you can see the run time statistics in milliseconds. This action is available only for databases that support it.

These actions are located in the ![the Explain plan icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/database-plugin.icons.expui.consoleShowPlan.svg) Explain Plan dropdown on the code editor toolbar. You can also invoke them using the  [code editor context menu](code-editor-tips-and-ref-db-tools-and-sql.html#context_menu). To also have the Explain Plan (Raw) and Explain Analyse (Raw) actions in the dropdown, [add them to the menu](customize-actions-menus-and-toolbars.html#customize-menus-and-toolbars).

![Explain Plan dropdown on the code editor toolbar](https://resources.jetbrains.com.cn/help/img/idea/2026.2/db_explain_plan_toolbar_dropdown.png)

The result is shown in a mixed tree and table format on a dedicated Query Plan tab. For more information about the Query Plan tab, refer to the [Services tool window](services-tool-window.html#query_plan_tab) topic.

Procedure: Copy a query plan

You can copy the query plan in the database’s native format, for example, JSON or XML.

1. Right-click an SQL statement, and select ![the Explain plan icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/database-plugin.icons.expui.consoleShowPlan.svg) `Explain Plan |  Explain Plan`.

Alternatively, click ![the Explain plan icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/database-plugin.icons.expui.consoleShowPlan.svg) Explain Plan on the toolbar and select  Explain Plan

2. In the Query Plan tab, click ![the Copy Original Query Plan icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app-client.expui.general.copy.svg) Copy Original Query Plan at the top of the left toolbar.

This is supported for PostgreSQL, Amazon Redshift, MySQL, MariaDB, Oracle, Microsoft SQL Server, and Snowflake.

![The Copy Original Query Plan button](https://resources.jetbrains.com.cn/help/img/idea/2026.2/db_explain_plan_copy_plan_button.png)

Procedure: Visualize a query plan

1. Right-click an SQL statement, and select ![the Explain plan icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/database-plugin.icons.expui.consoleShowPlan.svg) `Explain Plan |  Explain Plan`.

Alternatively, click ![the Explain plan icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/database-plugin.icons.expui.consoleShowPlan.svg) Explain Plan on the toolbar and select  Explain Plan

2. By default, the tree representation of the query plan is displayed in the Query Plan tab of the Services tool window.  To visualize the query execution plan, click ![the Show Diagram icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.fileTypes.diagram.svg) Show Diagram…, or press `Ctrl+Alt+Shift+U` (Windows), `⌘ ⌥ ⇧ U` (macOS), `⌘ ⌥ ⇧ U` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ ⇧ U` (macOS System Shortcuts), `Ctrl+Alt+Shift+U` (XWin), `Ctrl+Alt+Shift+U` (GNOME), `Ctrl+Alt+Shift+U` (KDE), `Ctrl+Alt+Shift+U` (Emacs), `Ctrl+Alt+Shift+U` (Sublime Text), `⌘ ⌥ ⇧ U` (Sublime Text (macOS)), `Ctrl+Alt+Shift+U` (NetBeans), `Ctrl+Alt+Shift+U` (Visual Studio), `⌘ ⌥ ⇧ U` (Visual Studio (macOS)), `Ctrl+Alt+Shift+U` (Eclipse), `⌘ ⌥ ⇧ U` (Eclipse (macOS)).

[Video](https://resources.jetbrains.com.cn/help/img/idea/2026.2/db_visualize_query_plan.mp4)

The different views available for a query plan are displayed in separate inner tabs. These inner tabs can be accessed at the bottom of the Query Plan tab. They are hidden by default and appear only when more than one tab is open.

Procedure: Open raw plan

1. Right-click an SQL statement, and select ![the Explain plan icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/database-plugin.icons.expui.consoleShowPlan.svg) `Explain Plan |  Explain Plan`.

Alternatively, click ![the Explain plan icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/database-plugin.icons.expui.consoleShowPlan.svg) Explain Plan on the toolbar and select  Explain Plan

2. By default, the tree representation of the query plan is displayed in the Query Plan tab of the Services tool window.    Click ![the Raw icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/database-plugin.icons.expui.consoleShowPlan.svg) Raw on the left toolbar of the tab.

3. IntelliJ IDEA displays the raw explain plan in the Raw inner tab. The explain plan tree also remains available in the Operations Tree inner tab.

For Explain Plan (Raw), the button is replaced with Show Tree and opens the Operations Tree inner tab next to the Raw one.

![The Raw button on the left toolbar of the Query Plan tab](https://resources.jetbrains.com.cn/help/img/idea/2026.2/db_explain_plan_inner_tabs.png)

Procedure: Generate a flame graph for EXPLAIN

1. Right-click an SQL statement, and select ![the Explain plan icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/database-plugin.icons.expui.consoleShowPlan.svg) `Explain Plan |  Explain Plan`.

Alternatively, click ![the Explain plan icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/database-plugin.icons.expui.consoleShowPlan.svg) Explain Plan on the toolbar and select  Explain Plan

2. By default, the tree representation of the query plan is displayed in the Query Plan tab of the Services tool window.   Click ![the Flame Graph icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/database-plugin.icons.sqlGroupByType.svg) Flame Graph and select between the following options:

* Total Cost: how long it takes to return all the rows.

* Startup Cost: how long it takes before the first row can be processed.

IntelliJ IDEA displays the newly opened graph in a separate inner tab, keeping the tree representation in the Operation Tree inner tab.

![Inner tabs of the Query Plan tab](https://resources.jetbrains.com.cn/help/img/idea/2026.2/db_explain_plan_view_tabs.png)

## See also

### Reference

[Diagrams](creating-diagrams.html#reference) [Services tool window](services-tool-window.html) [Query Plan tab](services-tool-window.html#query_plan_tab)

