Returns query plans in an HTML format string.
HTML_PLAN ( string-expression )
CIS functional compensation performance considerations apply. See “Conditions that cause processing by SQL Anywhere” in Chapter 3, “Optimizing Queries and Deletions,” in the Performance and Tuning Guide.
string-expression SQL statement for which the plan is to be generated. It is primarily a SELECT statement but can be an UPDATE or DELETE statement.
If you do not provide an argument to the HTML_PLAN function, the query plan is returned to you from the cache. If there is no query plan in the cache, this message appears:
No plan available
The behavior of the HTML_PLAN function is controlled by database options QUERY_PLAN_TEXT_ACCESS and QUERY_PLAN_TEXT_CACHING. If QUERY_PLAN_TEXT_ACCESS is OFF (the default), this message appears:
Plan not available. The database option QUERY_PLAN_TEXT_ACCESS is OFF
If QUERY_PLAN_TEXT_ACCESS is ON, and the query plan for the string expression is available in the cache maintained on the server, the query plan from the cache is returned to you.
The HTML_PLAN function can be used to return query plans to Interactive SQL using SELECT, UPDATE, DELETE, INSERT SELECT, and SELECT INTO.
Users can view the query plan for cursors opened for IQ queries. To obtain the query plan for the most recently opened cursor, use:
SELECT HTML_PLAN ( );
With QUERY_PLAN_AFTER_RUN option OFF, the plan appears after OPEN CURSOR or CLOSE CURSOR. However, if QUERY_PLAN_AFTER_RUN is ON, CLOSE CURSOR must be executed before you request the plan.
For information on viewing the query optimizer's execution plan for a SQL statement in the Plan Viewer window in Interactive SQL, see "Viewing plans using the Interactive SQL Plan Viewer".
When Interactive SQL users request plans for UPDATE, DELETE, SELECT INTO, and INSERT SELECT queries, the NOEXEC plan is not supported. To access the query plan, first explicitly execute the query, then request the plan.
When you request an HTML_PLAN for a SQL Anywhere query or for an OMNI/CIS decomposed query, the following message is returned:
No plan. HTML_PLAN function is not supported for this type of statement or database.
The following example passes a SELECT statement as a string parameter and returns the HTML plan for executing the query. It saves the plan in the file hplan.html.
SELECT HTML_PLAN ('SELECT * FROM Employees'); OUTPUT to 'C:\hplan.html' HEXADECIMAL ASIS QUOTE '';
The OUTPUT TO clause HEXADECIMAL ASIS is useful for text that contains formatting characters such as tabs or carriage returns. When set to ASIS, values are written as is, without any escaping, even if the values contain control characters.
The following example returns the HTML query plan from the cache, if available.
SELECT HTML_PLAN ( );
“GRAPHICAL_PLAN function [String]”
“OUTPUT statement [DBISQL]” in Reference: Building Blocks, Tables, and Procedures
“NOEXEC option,” “QUERY_PLAN_AFTER_RUN option,” “QUERY_PLAN_AS_HTML option,” “QUERY_PLAN_TEXT_ACCESS option,”and “QUERY_PLAN_TEXT_CACHING option” in Reference: Statements and Options
PLAN function [Miscellaneous], EXPLANATION function, [Miscellaneous], GRAPHICAL_ULPLAN function [Miscellaneous], LONG_ULPLAN function [Miscellaneous], and SHORT_ULPLAN function [Miscellaneous] in SQL Anywhere Server – SQL Reference.