Display plan types

You can use EXPLAIN, HTML (also known as bubble), and text plans to analyze how a query is performed.

To obtain these plans, do the following tasks:

  • To obtain an EXPLAIN plan, add the EXPLAIN VERBOSE keyword before the SQL statement. The system displays the output to stdout unless you redirect it to a file.
     EXPLAIN VERBOSE SELECT * FROM foo;
  • To obtain an HTML plan, use either the EXPLAIN or SET command.
    • The following is an example that uses EXPLAIN PLANGRAPH.
      EXPLAIN PLANGRAPH SELECT * FROM foo;
      

      With EXPLAIN PLANGRAPH, the system displays the output to the nzsql terminal. You can copy and paste the output into a file that you can open in your browser.

    • The following is an example that uses SET.
      SET enable_print_plan_html=1;
      SELECT * FROM FOO;
      The SET command saves the output to a file on the host. You can specify the location for the file. For example:
      SET print_plan_path = ’/tmp’;

      In this case, the output would be saved to /tmp/plan#.html (The system begins with the number 1 and names subsequent output sequentially.)

    • Whether you use EXPLAIN PLANGRAPH or SET, the output displays the query plan pictorially as a tree of nodes (ovals), representing how joins are processed. Use the following characteristics to interpret the representations.
      • Ovals with unbroken single lines and clear backgrounds (not shaded) are nodes that ran on the SPUs.
      • Shaded ovals represent nodes that the host (DBOS) executed.
      • Ovals with dashed lines represent virtual nodes (typically subquery scans).
      • Ovals with double lines represent fabric joins, which are streaming nodes that are either broadcast or distributed.
  • To obtain a text plan, use either the EXPLAIN or SET command. The system displays the output to the nzsql terminal unless you redirect it to a file.
    EXPLAIN PLANTEXT SELECT * FROM foo;
    OR
    SET enable_print_plan_text=1;
    SELECT * FROM foo;