<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>OpenText Analytics Database 26.2.x – Batch query plan export</title>
    <link>/en/admin/managing-queries/directed-queries/batch-query-plan-export/</link>
    <description>Recent content in Batch query plan export on OpenText Analytics Database 26.2.x</description>
    <generator>Hugo -- gohugo.io</generator>
    
	  <atom:link href="/en/admin/managing-queries/directed-queries/batch-query-plan-export/index.xml" rel="self" type="application/rss+xml" />
    
    
      
        
      
    
    
    <item>
      <title>Admin: Exporting directed queries</title>
      <link>/en/admin/managing-queries/directed-queries/batch-query-plan-export/exporting-directed-queries/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/admin/managing-queries/directed-queries/batch-query-plan-export/exporting-directed-queries/</guid>
      <description>
        
        
        &lt;p&gt;You can batch export any number of query plans as directed queries to an external SQL file, as follows:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Create a SQL file that contains the input queries whose query plans you wish to save. See &lt;a href=&#34;#InputFile&#34;&gt;Input Format&lt;/a&gt; below.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Call the meta-function &lt;a href=&#34;../../../../../en/sql-reference/functions/directed-queries-functions/export-directed-queries/#&#34;&gt;EXPORT_DIRECTED_QUERIES&lt;/a&gt; on that SQL file. The meta-function takes two arguments:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;#Input&#34;&gt;Input queries file&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Optionally, the name of an &lt;a href=&#34;#InputFile&#34;&gt;output file&lt;/a&gt;. EXPORT_DIRECTED_QUERIES writes SQL for creating directed queries to this file. If you supply an empty string, OpenText™ Analytics Database writes the SQL to standard output.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;For example, the following EXPORT_DIRECTED_QUERIES statement specifies input file &lt;code&gt;inputQueries&lt;/code&gt; and output file &lt;code&gt;outputQueries&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT EXPORT_DIRECTED_QUERIES(&amp;#39;/home/dbadmin/inputQueries&amp;#39;,&amp;#39;/home/dbadmin/outputQueries&amp;#39;);
                               EXPORT_DIRECTED_QUERIES
---------------------------------------------------------------------------------------------
 1 queries successfully exported.
Queries exported to /home/dbadmin/outputQueries.

(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;a name=&#34;Input&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;input-file&#34;&gt;Input file&lt;/h2&gt;
&lt;p&gt;The input file that you supply to EXPORT_DIRECTED_QUERIES contains one or more input queries. For each input query, you can optionally specify two fields that are used in the generated directed query:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;DirQueryName&lt;/code&gt; provides the directed query&#39;s unique identifier, a string that conforms to conventions described in &lt;a href=&#34;../../../../../en/sql-reference/language-elements/identifiers/#&#34;&gt;Identifiers&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;DirQueryComment&lt;/code&gt; specifies a quote-delimited string, up to 128 characters.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You format each input query as follows:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;--DirQueryName=&lt;span class=&#34;code-variable&#34;&gt;query-name&lt;/span&gt;
--DirQueryComment=&amp;#39;&lt;span class=&#34;code-variable&#34;&gt;comment&lt;/span&gt;&amp;#39;
&lt;span class=&#34;code-variable&#34;&gt;input-query&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For example, a file can specify one input query as follows:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;/* Query: findEmployeesCityJobTitle_OPT */
/* Comment: This query finds all employees of a given city and job title, ordered by employee name */
SELECT employee_dimension.employee_first_name, employee_dimension.employee_last_name, employee_dimension.job_title FROM public.employee_dimension WHERE (employee_dimension.employee_city = &amp;#39;Boston&amp;#39;::varchar(6)) ORDER BY employee_dimension.job_title;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;a name=&#34;InputFile&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;a-nameoutputfileaoutput-file&#34;&gt;&lt;a name=&#34;OutputFile&#34;&gt;&lt;/a&gt;Output file&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;EXPORT_DIRECTED_QUERIES&lt;/code&gt; generates SQL for creating directed queries, and writes the SQL to the specified file or to standard output. In both cases, output conforms to the following format:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;/* Query: &lt;span class=&#34;code-variable&#34;&gt;directed-query-name &lt;/span&gt;*/
/* Comment: &lt;span class=&#34;code-variable&#34;&gt;directed-query-comment &lt;/span&gt;*/
SAVE QUERY &lt;span class=&#34;code-variable&#34;&gt;input-query&lt;/span&gt;;
CREATE DIRECTED QUERY CUSTOM &amp;#39;&lt;span class=&#34;code-variable&#34;&gt;directed-query-name&lt;/span&gt;&amp;#39;
COMMENT &amp;#39;&lt;span class=&#34;code-variable&#34;&gt;directed-query-comment&lt;/span&gt;&amp;#39;
OPTVER &amp;#39;&lt;span class=&#34;code-variable&#34;&gt;vertica-release-num&lt;/span&gt;&amp;#39;
PSDATE &amp;#39;&lt;span class=&#34;code-variable&#34;&gt;timestamp&lt;/span&gt;&amp;#39;
&lt;span class=&#34;code-variable&#34;&gt;annotated-query&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For example, given the previous input, the database writes the following output to &lt;code&gt;/home/dbadmin/outputQueries&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;/* Query: findEmployeesCityJobTitle_OPT */
/* Comment: This query finds all employees of a given city and job title, ordered by employee name */
SAVE QUERY SELECT employee_dimension.employee_first_name, employee_dimension.employee_last_name FROM public.employee_dimension WHERE ((employee_dimension.employee_city = &amp;#39;Boston&amp;#39;::varchar(6) /*+:v(1)*/) AND (employee_dimension.job_title = &amp;#39;Cashier&amp;#39;::varchar(7) /*+:v(2)*/)) ORDER BY employee_dimension.employee_last_name, employee_dimension.employee_first_name;
CREATE DIRECTED QUERY CUSTOM &amp;#39;findEmployeesCityJobTitle_OPT&amp;#39;
COMMENT &amp;#39;This query finds all employees of a given city and job title, ordered by employee name&amp;#39;
OPTVER &amp;#39;Vertica Analytic Database v11.1.0-20220102&amp;#39;
PSDATE &amp;#39;2022-01-06 13:45:17.430254&amp;#39;
SELECT /*+verbatim*/ employee_dimension.employee_first_name AS employee_first_name, employee_dimension.employee_last_name AS employee_last_name
FROM public.employee_dimension AS employee_dimension/*+projs(&amp;#39;public.employee_dimension&amp;#39;)*/
WHERE (employee_dimension.employee_city = &amp;#39;Boston&amp;#39;::varchar(6) /*+:v(1)*/) AND (employee_dimension.job_title = &amp;#39;Cashier&amp;#39;::varchar(7) /*+:v(2)*/)
ORDER BY 2 ASC, 1 ASC;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If a given input query omits &lt;code&gt;DirQueryName&lt;/code&gt; and &lt;code&gt;DirQueryComment&lt;/code&gt; fields, EXPORT_DIRECTED_QUERIES automatically generates the following output:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;/* Query: Autoname:&lt;/code&gt;&lt;em&gt;&lt;code&gt;timestamp&lt;/code&gt;&lt;/em&gt;&lt;code&gt;.&lt;/code&gt;&lt;em&gt;&lt;code&gt;n&lt;/code&gt;&lt;/em&gt;&lt;code&gt; */&lt;/code&gt;, where &lt;em&gt;&lt;code&gt;n&lt;/code&gt;&lt;/em&gt; is a zero-based integer index that ensures uniqueness among auto-generated names with the same timestamp.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;/* Comment: Optimizer-generated directed query */&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, the following input file contains one &lt;code&gt;SELECT&lt;/code&gt; statement, and omits the &lt;code&gt;DirQueryName&lt;/code&gt; and &lt;code&gt;DirQueryComment&lt;/code&gt; fields:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
SELECT employee_dimension.employee_first_name, employee_dimension.employee_last_name
FROM public.employee_dimension WHERE (employee_dimension.employee_city = &amp;#39;Boston&amp;#39;::varchar(6))
ORDER BY employee_dimension.job_title;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Given this file, EXPORT_DIRECTED_QUERIES returns with a warning about the missing input fields, which it also writes to an &lt;a href=&#34;#ErrorFile&#34;&gt;error file&lt;/a&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;&amp;gt; SELECT EXPORT_DIRECTED_QUERIES(&amp;#39;/home/dbadmin/inputQueries2&amp;#39;,&amp;#39;/home/dbadmin/outputQueries3&amp;#39;);
                                              EXPORT_DIRECTED_QUERIES
--------------------------------------------------------------------------------------------------------------
 1 queries successfully exported.
1 warning message was generated.
Queries exported to /home/dbadmin/outputQueries3.
See error report, /home/dbadmin/outputQueries3.err for details.
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The output file contains the following content:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;/* Query: Autoname:2022-01-06 14:11:23.071559.0 */
/* Comment: Optimizer-generated directed query */
SAVE QUERY SELECT employee_dimension.employee_first_name, employee_dimension.employee_last_name FROM public.employee_dimension WHERE (employee_dimension.employee_city = &amp;#39;Boston&amp;#39;::varchar(6) /*+:v(1)*/) ORDER BY employee_dimension.job_title;
CREATE DIRECTED QUERY CUSTOM &amp;#39;Autoname:2022-01-06 14:11:23.071559.0&amp;#39;
COMMENT &amp;#39;Optimizer-generated directed query&amp;#39;
OPTVER &amp;#39;Vertica Analytic Database v11.1.0-20220102&amp;#39;
PSDATE &amp;#39;2022-01-06 14:11:23.071559&amp;#39;
SELECT /*+verbatim*/ employee_dimension.employee_first_name AS employee_first_name, employee_dimension.employee_last_name AS employee_last_name
FROM public.employee_dimension AS employee_dimension/*+projs(&amp;#39;public.employee_dimension&amp;#39;)*/
WHERE (employee_dimension.employee_city = &amp;#39;Boston&amp;#39;::varchar(6) /*+:v(1)*/)
ORDER BY employee_dimension.job_title ASC;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;a name=&#34;ErrorFile&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;a-nameerrorfileaerror-file&#34;&gt;&lt;a name=&#34;ErrorFile&#34;&gt;&lt;/a&gt;Error file&lt;/h2&gt;
&lt;p&gt;If any errors or warnings occur during EXPORT_DIRECTED_QUERIES execution, it returns with a message like this one:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;1 queries successfully exported.
1 warning message was generated.
Queries exported to /home/dbadmin/outputQueries.
See error report, /home/dbadmin/outputQueries.err for details.
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;EXPORT_DIRECTED_QUERIES writes all errors and warnings to a file that it creates on the same path as the output file, and uses the output file&#39;s base name.&lt;/p&gt;

&lt;p&gt;In the previous example, the output filename is &lt;code&gt;/home/dbadmin/outputQueries&lt;/code&gt;, so EXPORT_DIRECTED_QUERIES writes errors to &lt;code&gt;/home/dbadmin/outputQueries.err&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The error file can capture a number of errors and warnings, such as all instances where EXPORT_DIRECTED_QUERIES was unable to create a directed query. In the following example, the error file contains a warning that no name field was supplied for the specified input query, and records the name that was auto-generated for it:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
----------------------------------------------------------------------------------------------------
WARNING: Name field not supplied. Using auto-generated name: &amp;#39;Autoname:2016-10-13 09:44:33.527548.0&amp;#39;
Input Query: SELECT employee_dimension.employee_first_name, employee_dimension.employee_last_name, employee_dimension.job_title FROM public.employee_dimension WHERE (employee_dimension.employee_city = &amp;#39;Boston&amp;#39;::varchar(6)) ORDER BY employee_dimension.job_title;
END WARNING
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Admin: Importing directed queries</title>
      <link>/en/admin/managing-queries/directed-queries/batch-query-plan-export/importing-directed-queries/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/admin/managing-queries/directed-queries/batch-query-plan-export/importing-directed-queries/</guid>
      <description>
        
        
        &lt;p&gt;After you determine which exported query plans you wish to use in the current database, you import them with &lt;a href=&#34;../../../../../en/sql-reference/functions/directed-queries-functions/import-directed-queries/#&#34;&gt;IMPORT_DIRECTED_QUERIES&lt;/a&gt;. You supply this function with the name of the export file that you created with EXPORT_DIRECTED_QUERIES, and the names of directed queries you wish to import. For example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
=&amp;gt; SELECT IMPORT_DIRECTED_QUERIES(&amp;#39;/home/dbadmin/outputQueries&amp;#39;,&amp;#39;FindEmployeesBoston&amp;#39;);
                                    IMPORT_DIRECTED_QUERIES
------------------------------------------------------------------------------------------
 1 directed queries successfully imported.
To activate a query named &amp;#39;my_query1&amp;#39;:
=&amp;gt; ACTIVATE DIRECTED QUERY &amp;#39;my_query1&amp;#39;;

(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;After importing the desired directed queries, you must activate them with &lt;a href=&#34;../../../../../en/sql-reference/statements/activate-directed-query/#&#34;&gt;ACTIVATE DIRECTED QUERY&lt;/a&gt; before you can use them to create query plans.&lt;/p&gt;

      </description>
    </item>
    
  </channel>
</rss>
