SHOW PLAN

Displays the EXPLAIN plan of a query as per the plan ID.

Syntax

SHOW PLAN [JSON] plan_id

Remarks

  • SHOW PLAN displays the same information as EXPLAIN. You can use the SHOW PLAN command as an alternative to the EXPLAIN command, if your database client does not support EXPLAIN.

  • By default, the SHOW PLAN command displays the EXPLAIN information of a query in text format. You can optionally choose to display the information in JSON format using the SHOW PLAN JSON command.

  • You can get the plan_id of a query from the INFORMATION_SCHEMA.PLANCACHE view. See Example for details.

  • The SHOW PLAN command throws the following error if the global variable enable_disk_plan_explain is not enabled:

    ERROR 2394 (HY000): The plan does not have associated explain information. enable_disk_plan_explain must be enabled at the time of plan generation.

    In this scenario, you need to do the following:

    1. Run the following command to drop the plan from the plancache:

      DROP 25 FROM PLANCACHE;
    2. Enable the global variable:

      SET GLOBAL enable_disk_plan_explain=ON;
    3. Rerun the query to regenerate the plan, and query the plancache again to obtain the new plan_id.

    Note: Every time a query is run, a new plan is generated along with the plan_id.

Example

The following example displays the plan statistics for the following SELECT statement:

SELECT * FROM Employee;
+------+------+
| ID | Name |
+------+------+
| 10 | Jack |
| 30 | Ritz |
| 20 | Rob |
| 40 | Rick |
+------+------+

Run the following command to view the plan ID of the SELECT query:

SELECT QUERY_TEXT,PLAN_ID FROM INFORMATION_SCHEMA.PLANCACHE WHERE QUERY_TEXT LIKE 'SELECT * FROM Employee';
+---------+------------------------+
| PLAN_ID | QUERY_TEXT             |
+---------+------------------------+
|      25 | SELECT * FROM Employee |
+---------+------------------------+

Note: In the SELECT statement, you can omit the WHERE clause to view the plan ID of all the queries executed in the current session.

Now run the following command to view the statistics of the plan ID 25:

SHOW PLAN 25;
+---------------------------------------------------+
| PLAN                                              |
+---------------------------------------------------+
| Gather partitions:all alias:remote_0              |
| Project [Employee.ID, Employee.Name]              |
| TableScan db.Employee table_type:sharded_rowstore |
+---------------------------------------------------+

Last modified: October 8, 2021

Was this article helpful?

Verification instructions

Note: You must install cosign to verify the authenticity of the SingleStore file.

Use the following steps to verify the authenticity of singlestoredb-server, singlestoredb-toolbox, singlestoredb-studio, and singlestore-client SingleStore files that have been downloaded.

You may perform the following steps on any computer that can run cosign, such as the main deployment host of the cluster.

  1. (Optional) Run the following command to view the associated signature files.

    curl undefined
  2. Download the signature file from the SingleStore release server.

    • Option 1: Click the Download Signature button next to the SingleStore file.

    • Option 2: Copy and paste the following URL into the address bar of your browser and save the signature file.

    • Option 3: Run the following command to download the signature file.

      curl -O undefined
  3. After the signature file has been downloaded, run the following command to verify the authenticity of the SingleStore file.

    echo -n undefined |
    cosign verify-blob --certificate-oidc-issuer https://oidc.eks.us-east-1.amazonaws.com/id/CCDCDBA1379A5596AB5B2E46DCA385BC \
    --certificate-identity https://kubernetes.io/namespaces/freya-production/serviceaccounts/job-worker \
    --bundle undefined \
    --new-bundle-format -
    Verified OK