<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Can we get the actual query execution plan programmatically after a query is executed? Apart fro in Get Started Discussions</title>
    <link>https://community.databricks.com/t5/get-started-discussions/can-we-get-the-actual-query-execution-plan-programmatically/m-p/64442#M6864</link>
    <description>&lt;P class="_1t7bu9h1 paragraph"&gt;You can obtain the query execution plan programmatically using the &lt;CODE&gt;EXPLAIN&lt;/CODE&gt; statement in SQL. The &lt;CODE&gt;EXPLAIN&lt;/CODE&gt; statement displays the execution plan that the database planner generates for the supplied statement. The execution plan shows how the table(s) referenced by the statement will be scanned — by plain sequential scan, index scan, etc. — and if multiple tables are referenced, what join algorithms will be used to bring together the required rows from each input table.&lt;/P&gt;
&lt;P class="_1t7bu9h1 paragraph"&gt;Here is an example of how you can use it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class="_1t7bu9hb markdown-code-python hljs language-python" data-highlighted="yes"&gt;&lt;SPAN class="hljs-comment"&gt;# Spark SQL&lt;/SPAN&gt;
query = &lt;SPAN class="hljs-string"&gt;"SELECT * FROM table"&lt;/SPAN&gt;
plan = spark.sql(&lt;SPAN class="hljs-string"&gt;f"EXPLAIN &lt;SPAN class="hljs-subst"&gt;{query}&lt;/SPAN&gt;"&lt;/SPAN&gt;)
plan.show(truncate=&lt;SPAN class="hljs-literal"&gt;False&lt;/SPAN&gt;)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="_1t7bu9h1 paragraph"&gt;This will return a DataFrame with a single row and column that contains the execution plan as a string.&lt;/P&gt;
&lt;P class="_1t7bu9h1 paragraph"&gt;&lt;CODE&gt;EXPLAIN&lt;/CODE&gt; command will only provide the logical and physical plans. It will not provide the runtime details like how much time each stage took, how much data was read, etc. For that level of detail, you would need to parse the Spark UI or logs.&lt;/P&gt;</description>
    <pubDate>Sat, 23 Mar 2024 14:50:45 GMT</pubDate>
    <dc:creator>Walter_C</dc:creator>
    <dc:date>2024-03-23T14:50:45Z</dc:date>
    <item>
      <title>Can we get the actual query execution plan programmatically after a query is executed? Apart from UI</title>
      <link>https://community.databricks.com/t5/get-started-discussions/can-we-get-the-actual-query-execution-plan-programmatically/m-p/64388#M6863</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Let's say i have run a query and it showed me results. we can find the respective query execution plan on the UI. Is there any way we can get that execution plan through programmatically or through API?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2024 10:24:30 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/can-we-get-the-actual-query-execution-plan-programmatically/m-p/64388#M6863</guid>
      <dc:creator>Ak_0926</dc:creator>
      <dc:date>2024-03-22T10:24:30Z</dc:date>
    </item>
    <item>
      <title>Re: Can we get the actual query execution plan programmatically after a query is executed? Apart fro</title>
      <link>https://community.databricks.com/t5/get-started-discussions/can-we-get-the-actual-query-execution-plan-programmatically/m-p/64442#M6864</link>
      <description>&lt;P class="_1t7bu9h1 paragraph"&gt;You can obtain the query execution plan programmatically using the &lt;CODE&gt;EXPLAIN&lt;/CODE&gt; statement in SQL. The &lt;CODE&gt;EXPLAIN&lt;/CODE&gt; statement displays the execution plan that the database planner generates for the supplied statement. The execution plan shows how the table(s) referenced by the statement will be scanned — by plain sequential scan, index scan, etc. — and if multiple tables are referenced, what join algorithms will be used to bring together the required rows from each input table.&lt;/P&gt;
&lt;P class="_1t7bu9h1 paragraph"&gt;Here is an example of how you can use it:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class="_1t7bu9hb markdown-code-python hljs language-python" data-highlighted="yes"&gt;&lt;SPAN class="hljs-comment"&gt;# Spark SQL&lt;/SPAN&gt;
query = &lt;SPAN class="hljs-string"&gt;"SELECT * FROM table"&lt;/SPAN&gt;
plan = spark.sql(&lt;SPAN class="hljs-string"&gt;f"EXPLAIN &lt;SPAN class="hljs-subst"&gt;{query}&lt;/SPAN&gt;"&lt;/SPAN&gt;)
plan.show(truncate=&lt;SPAN class="hljs-literal"&gt;False&lt;/SPAN&gt;)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="_1t7bu9h1 paragraph"&gt;This will return a DataFrame with a single row and column that contains the execution plan as a string.&lt;/P&gt;
&lt;P class="_1t7bu9h1 paragraph"&gt;&lt;CODE&gt;EXPLAIN&lt;/CODE&gt; command will only provide the logical and physical plans. It will not provide the runtime details like how much time each stage took, how much data was read, etc. For that level of detail, you would need to parse the Spark UI or logs.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Mar 2024 14:50:45 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/can-we-get-the-actual-query-execution-plan-programmatically/m-p/64442#M6864</guid>
      <dc:creator>Walter_C</dc:creator>
      <dc:date>2024-03-23T14:50:45Z</dc:date>
    </item>
    <item>
      <title>Re: Can we get the actual query execution plan programmatically after a query is executed? Apart fro</title>
      <link>https://community.databricks.com/t5/get-started-discussions/can-we-get-the-actual-query-execution-plan-programmatically/m-p/64465#M6865</link>
      <description>&lt;P&gt;The EXPLAIN docs show some extra functionality:&amp;nbsp;&lt;A href="https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-qry-explain.html" target="_blank"&gt;https://docs.databricks.com/en/sql/language-manual/sql-ref-syntax-qry-explain.html&lt;/A&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;EXPLAIN [ EXTENDED | CODEGEN | COST | FORMATTED ] statement&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 24 Mar 2024 02:29:33 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/can-we-get-the-actual-query-execution-plan-programmatically/m-p/64465#M6865</guid>
      <dc:creator>Danny_Lee</dc:creator>
      <dc:date>2024-03-24T02:29:33Z</dc:date>
    </item>
  </channel>
</rss>

