{"id":571,"date":"2012-01-11T19:31:47","date_gmt":"2012-01-11T19:31:47","guid":{"rendered":"http:\/\/tech.avant.net\/q\/?p=571"},"modified":"2017-06-20T08:42:54","modified_gmt":"2017-06-20T08:42:54","slug":"sqlplus-explain-plan","status":"publish","type":"post","link":"https:\/\/tech.avant.net\/q\/sqlplus-explain-plan\/","title":{"rendered":"sqlplus explain plan"},"content":{"rendered":"<p>I would like to view explain plan output in sqlplus.<\/p>\n<p>One easy approach is to set autotrace. You can <strong>set autotrace on<\/strong> to show query statistics as well as an exection plan. You can also view only the execution plan, for example,<\/p>\n<pre class=\"sh_oracle\">\r\nfoo_owner@FOO> set autotrace on explain\r\nfoo_owner@FOO> SELECT COUNT(*) FROM tax_facts WHERE create_date <= TO_DATE('10-JAN-12', 'DD-MON-YY');\r\n\r\n  COUNT(*)\r\n----------\r\n   3768447\r\n\r\n\r\nExecution Plan\r\n----------------------------------------------------------\r\nPlan hash value: 3136400752\r\n\r\n--------------------------------------------------------------------------------------\r\n| Id  | Operation\t      | Name\t     | Rows  | Bytes | Cost (%CPU)| Time     |\r\n--------------------------------------------------------------------------------------\r\n|   0 | SELECT STATEMENT      | \t     |\t   1 |\t   8 |\t1988   (5)| 00:00:36 |\r\n|   1 |  SORT AGGREGATE       | \t     |\t   1 |\t   8 |\t\t  |\t     |\r\n|*  2 |   INDEX FAST FULL SCAN| TAXFCT_CRTDT |\t3774K|\t  28M|\t1988   (5)| 00:00:36 |\r\n--------------------------------------------------------------------------------------\r\n\r\nPredicate Information (identified by operation id):\r\n---------------------------------------------------\r\n\r\n   2 - filter(\"CREATE_DATE\"<=TO_DATE('10-JAN-12','DD-MON-YY'))\r\n\r\nfoo_owner@FOO>\r\n<\/pre>\n<p>Alternatively, you can use <strong>EXPLAIN PLAN FOR<\/strong> in front of your sql-statement, but viewing the plan output is less-intuitive, e.g.,<\/p>\n<pre class=\"sh_oracle\">\r\nfoo_owner@FOO> EXPLAIN PLAN FOR  SELECT COUNT(*) FROM tax_facts WHERE create_date <= TO_DATE('10-JAN-12', 'DD-MON-YY');\r\n\r\nExplained.\r\n\r\nfoo_owner@FOO> SELECT PLAN_TABLE_OUTPUT FROM TABLE(DBMS_XPLAN.DISPLAY());\r\n\r\nPLAN_TABLE_OUTPUT\r\n------------------------------------------------------------------------------------------------------------------------\r\nPlan hash value: 3136400752\r\n\r\n--------------------------------------------------------------------------------------\r\n| Id  | Operation\t      | Name\t     | Rows  | Bytes | Cost (%CPU)| Time     |\r\n--------------------------------------------------------------------------------------\r\n|   0 | SELECT STATEMENT      | \t     |\t   1 |\t   8 |\t1988   (5)| 00:00:36 |\r\n|   1 |  SORT AGGREGATE       | \t     |\t   1 |\t   8 |\t\t  |\t     |\r\n|*  2 |   INDEX FAST FULL SCAN| TAXFCT_CRTDT |\t3774K|\t  28M|\t1988   (5)| 00:00:36 |\r\n--------------------------------------------------------------------------------------\r\n\r\nPredicate Information (identified by operation id):\r\n---------------------------------------------------\r\n\r\n   2 - filter(\"CREATE_DATE\"<=TO_DATE('10-JAN-12','DD-MON-YY'))\r\n\r\n14 rows selected.\r\n\r\nfoo_owner@FOO> \r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I would like to view explain plan output in sqlplus. One easy approach is to set autotrace. You can set autotrace on to show query statistics as well as an exection plan. You can also view only the execution plan, for example, foo_owner@FOO> set autotrace on explain foo_owner@FOO> SELECT COUNT(*) FROM tax_facts WHERE create_date EXPLAIN [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[18],"tags":[],"_links":{"self":[{"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/posts\/571"}],"collection":[{"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/comments?post=571"}],"version-history":[{"count":4,"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/posts\/571\/revisions"}],"predecessor-version":[{"id":700,"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/posts\/571\/revisions\/700"}],"wp:attachment":[{"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/media?parent=571"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/categories?post=571"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tech.avant.net\/q\/wp-json\/wp\/v2\/tags?post=571"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}