<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Vertica Documentation – Managing directed queries</title>
    <link>/en/admin/managing-queries/directed-queries/managing-directed-queries/</link>
    <description>Recent content in Managing directed queries on Vertica Documentation</description>
    <generator>Hugo -- gohugo.io</generator>
    
	  <atom:link href="/en/admin/managing-queries/directed-queries/managing-directed-queries/index.xml" rel="self" type="application/rss+xml" />
    
    
      
        
      
    
    
    <item>
      <title>Admin: Getting directed queries</title>
      <link>/en/admin/managing-queries/directed-queries/managing-directed-queries/getting-directed-queries/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/admin/managing-queries/directed-queries/managing-directed-queries/getting-directed-queries/</guid>
      <description>
        
        
        &lt;p&gt;You can obtain catalog information about directed queries in two ways:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;#Run&#34;&gt;Use GET DIRECTED QUERY&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;#Query&#34;&gt;Query system table DIRECTED_QUERIES&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a name=&#34;Run&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;get-directed-query&#34;&gt;GET DIRECTED QUERY&lt;/h2&gt;
&lt;p&gt;&lt;a href=&#34;../../../../../en/sql-reference/statements/get-directed-query/&#34;&gt;GET DIRECTED QUERY&lt;/a&gt; queries the system table &lt;a href=&#34;../../../../../en/sql-reference/system-tables/v-catalog-schema/directed-queries/&#34;&gt;DIRECTED_QUERIES&lt;/a&gt; on the specified input query. It returns details of all directed queries that map to the input query.&lt;/p&gt;
&lt;p&gt;The following GET DIRECTED QUERY statement returns the directed query that maps to the following input query, &lt;code&gt;findEmployeesCityJobTitle_OPT&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; GET DIRECTED QUERY SELECT employee_first_name, employee_last_name from employee_dimension where employee_city=&amp;#39;Boston&amp;#39; AND job_title=&amp;#39;Cashier&amp;#39; order by employee_last_name, employee_first_name;
-[ RECORD 1 ]---+
query_name      | findEmployeesCityJobTitle_OPT
is_active       | t
vertica_version | Vertica Analytic Database v11.0.1-20210815
comment         | Optimizer-generated directed query
creation_date   | 2021-08-20 14:53:42.323963
annotated_query | SELECT /*+verbatim*/  employee_dimension.employee_first_name, employee_dimension.employee_last_name FROM public.employee_dimension 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 employee_dimension.employee_last_name, employee_dimension.employee_first_name
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;a name=&#34;Query&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;directed_queries&#34;&gt;DIRECTED_QUERIES&lt;/h2&gt;
&lt;p&gt;You can query the system table &lt;a href=&#34;../../../../../en/sql-reference/system-tables/v-catalog-schema/directed-queries/&#34;&gt;DIRECTED_QUERIES&lt;/a&gt; directly. For example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT query_name, is_active FROM V_CATALOG.DIRECTED_QUERIES WHERE query_name ILIKE &amp;#39;%findEmployeesCityJobTitle%&amp;#39;;
          query_name           | is_active
-------------------------------+-----------
 findEmployeesCityJobTitle_OPT | t
(1 row)
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&#34;admonition caution&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Caution&lt;/h4&gt;

&lt;p&gt;Query results for the fields INPUT_QUERY and ANNOTATED_QUERY are truncated after ~32K characters. You can get the full content of both fields in two ways:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Use the statement &lt;a href=&#34;../../../../../en/sql-reference/statements/get-directed-query/&#34;&gt;GET DIRECTED QUERY&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use &lt;a href=&#34;../../../../../en/sql-reference/functions/management-functions/catalog-functions/export-catalog/&#34;&gt;EXPORT_CATALOG&lt;/a&gt; to export directed queries.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/div&gt;

      </description>
    </item>
    
    <item>
      <title>Admin: Identifying active directed queries</title>
      <link>/en/admin/managing-queries/directed-queries/managing-directed-queries/identifying-active-directed-queries/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/admin/managing-queries/directed-queries/managing-directed-queries/identifying-active-directed-queries/</guid>
      <description>
        
        
        &lt;p&gt;Multiple directed queries can map to the same input query. The &lt;code&gt;is_active&lt;/code&gt; column in system table &lt;a href=&#34;../../../../../en/sql-reference/system-tables/v-catalog-schema/directed-queries/&#34;&gt;DIRECTED_QUERIES&lt;/a&gt; identifies directed queries that are active. If multiple directed queries are active for the same input query, the optimizer uses the first one to be created. In that case, you can use &lt;a href=&#34;../../../../../en/sql-reference/statements/explain/&#34;&gt;EXPLAIN&lt;/a&gt; to identify which directed query is active.

&lt;div class=&#34;alert admonition tip&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Tip&lt;/h4&gt;

It is good practice to activate only one directed query at a time for a given input query.

&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;The following query on DIRECTED_QUERIES finds all active directed queries where the input query contains the name of the queried table &lt;code&gt;employee_dimension&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT * FROM directed_queries WHERE input_query ILIKE (&amp;#39;%employee_dimension%&amp;#39;) AND is_active=&amp;#39;t&amp;#39;;
-[ RECORD 1 ]------+
query_name         | findEmployeesCityJobTitle_OPT
is_active          | t
vertica_version    | Vertica Analytic Database v11.0.1-20210815
comment            | Optimizer-generated directed query
save_plans_version | 0
username           | dbadmin
creation_date      | 2021-08-20 14:53:42.323963
since_date         |
input_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
annotated_query    | SELECT /*+verbatim*/  employee_dimension.employee_first_name, employee_dimension.employee_last_name FROM public.employee_dimension 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 employee_dimension.employee_last_name, employee_dimension.employee_first_name
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If you run EXPLAIN on the input query, it returns with a query plan that confirms use of &lt;code&gt;findEmployeesCityJobTitle_OPT&lt;/code&gt; as the active directed query:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; EXPLAIN SELECT employee_first_name, employee_last_name FROM employee_dimension WHERE employee_city=&amp;#39;Boston&amp;#39; AND job_title =&amp;#39;Cashier&amp;#39; ORDER BY employee_last_name, employee_first_name;

 &lt;span class=&#34;code-input&#34;&gt;The following active directed query(query name: findEmployeesCityJobTitle_OPT) is being executed:&lt;/span&gt;
 SELECT /*+verbatim*/  employee_dimension.employee_first_name, employee_dimension.employee_last_name FROM public.employee_dimension employee_dimension/*+projs(&amp;#39;public.employee_dimension&amp;#39;)*/ WHERE ((employee_dimension.employee_city = &amp;#39;Boston&amp;#39;::varchar(6)) AND (employee_dimension.job_title = &amp;#39;Cashier&amp;#39;::varchar(7))) ORDER BY employee_dimension.employee_last_name, employee_dimension.employee_first_name
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Admin: Activating and deactivating directed queries</title>
      <link>/en/admin/managing-queries/directed-queries/managing-directed-queries/activating-and-deactivating-directed-queries/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/admin/managing-queries/directed-queries/managing-directed-queries/activating-and-deactivating-directed-queries/</guid>
      <description>
        
        
        &lt;p&gt;The optimizer uses only directed queries that are active. If multiple directed queries share the same input query, the optimizer uses the first one to be created.&lt;/p&gt;
&lt;p&gt;You activate and deactivate directed queries with &lt;a href=&#34;../../../../../en/sql-reference/statements/activate-directed-query/&#34;&gt;ACTIVATE DIRECTED QUERY&lt;/a&gt; and &lt;a href=&#34;../../../../../en/sql-reference/statements/deactivate-directed-query/&#34;&gt;DEACTIVATE DIRECTED QUERY&lt;/a&gt;, respectively. For example, the following ACTIVATE DIRECTED QUERY statement deactivates &lt;code&gt;RegionalSalesProducts_JoinTables&lt;/code&gt; and activates &lt;code&gt;RegionalSalesProduct&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
=&amp;gt; DEACTIVATE DIRECTED QUERY RegionalSalesProducts_JoinTables;
DEACTIVATE DIRECTED QUERY;
=&amp;gt; ACTIVATE DIRECTED QUERY RegionalSalesProduct;
ACTIVATE DIRECTED QUERY;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;ACTIVATE DIRECTED QUERY and DEACTIVATE DIRECTED QUERY can also activate and deactivate multiple directed queries that are filtered from system table &lt;a href=&#34;../../../../../en/sql-reference/system-tables/v-catalog-schema/directed-queries/&#34;&gt;DIRECTED_QUERIES&lt;/a&gt;. In the following example, DEACTIVATE DIRECTED QUERY deactivates all directed queries with the same &lt;code&gt;save_plans_version&lt;/code&gt; identifier:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; DEACTIVATE DIRECTED QUERY WHERE save_plans_version = 21;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Vertica uses the active directed query for a given query across all sessions until it is explicitly deactivated by DEACTIVATE DIRECTED QUERY or removed from storage by &lt;a href=&#34;../../../../../en/sql-reference/statements/drop-statements/drop-directed-query/&#34;&gt;DROP DIRECTED QUERY&lt;/a&gt;. If a directed query is active at the time of database shutdown, Vertica automatically reactivates it when you restart the database.&lt;/p&gt;
&lt;p&gt;After a direct query is deactivated, the query optimizer handles subsequent invocations of the input query by using another directed query, if one is available. Otherwise, it generates its own query plan.&lt;/p&gt;

      </description>
    </item>
    
    <item>
      <title>Admin: Exporting directed queries from the catalog</title>
      <link>/en/admin/managing-queries/directed-queries/managing-directed-queries/exporting-directed-queries-from-catalog/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/admin/managing-queries/directed-queries/managing-directed-queries/exporting-directed-queries-from-catalog/</guid>
      <description>
        
        
        
&lt;div class=&#34;alert admonition tip&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Tip&lt;/h4&gt;

You can also export query plans as directed queries to an external SQL file. See &lt;a href=&#34;../../../../../en/admin/managing-queries/directed-queries/batch-query-plan-export/&#34;&gt;Batch query plan export&lt;/a&gt;.

&lt;/div&gt;
&lt;p&gt;Before upgrading to a new version of Vertica, you can export directed queries for those queries whose optimal performance is critical to your system:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Use &lt;a href=&#34;../../../../../en/sql-reference/functions/management-functions/catalog-functions/export-catalog/&#34;&gt;EXPORT_CATALOG&lt;/a&gt; with the argument &lt;code&gt;DIRECTED_QUERIES&lt;/code&gt; to export from the database catalog all current directed queries and their current activation status:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT EXPORT_CATALOG(&amp;#39;../../export_directedqueries&amp;#39;, &amp;#39;DIRECTED_QUERIES&amp;#39;);
EXPORT_CATALOG
-------------------------------------
Catalog data exported successfully
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;EXPORT_CATALOG creates a script to recreate the directed queries, as in the following example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;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 findEmployeesCityJobTitle_OPT COMMENT &amp;#39;Optimizer-generated directed query&amp;#39; OPTVER &amp;#39;Vertica Analytic Database v11.0.1-20210815&amp;#39; PSDATE &amp;#39;2021-08-20 14:53:42.323963&amp;#39; SELECT /*+verbatim*/  employee_dimension.employee_first_name, employee_dimension.employee_last_name
FROM public.employee_dimension 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 employee_dimension.employee_last_name, employee_dimension.employee_first_name;
ACTIVATE DIRECTED QUERY findEmployeesCityJobTitle_OPT;
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

The script that &lt;code&gt;EXPORT_CATALOG&lt;/code&gt; creates specifies to recreate all directed queries with CREATE DIRECTED QUERY CUSTOM, regardless of how they were created originally.

&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;After the upgrade is complete, remove each directed query from the database catalog with &lt;a href=&#34;../../../../../en/sql-reference/statements/drop-statements/drop-directed-query/&#34;&gt;DROP DIRECTED QUERY&lt;/a&gt;. Alternatively, edit the export script and insert a DROP DIRECTED QUERY statement before each CREATE DIRECTED QUERY statement. For example, you might modify the script generated earlier with the changes shown in bold:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;SAVE QUERY SELECT employee_dimension.employee_first_name, ... ;
&lt;span class=&#34;code-input&#34;&gt;DROP DIRECTED QUERY findEmployeesCityJobTitle_OPT;&lt;/span&gt;
CREATE DIRECTED QUERY CUSTOM findEmployeesCityJobTitle_OPT COMMENT &amp;#39;Optimizer-generated ... ;
ACTIVATE DIRECTED QUERY findEmployeesCityJobTitle_OPT;
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;When you run this script, Vertica recreates the directed queries and restores their activation status:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; \i /home/dbadmin/export_directedqueries
SAVE QUERY
DROP DIRECTED QUERY
CREATE DIRECTED QUERY
ACTIVATE DIRECTED QUERY
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ol&gt;

      </description>
    </item>
    
    <item>
      <title>Admin: Dropping directed queries</title>
      <link>/en/admin/managing-queries/directed-queries/managing-directed-queries/dropping-directed-queries/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/admin/managing-queries/directed-queries/managing-directed-queries/dropping-directed-queries/</guid>
      <description>
        
        
        &lt;p&gt;&lt;a href=&#34;../../../../../en/sql-reference/statements/drop-statements/drop-directed-query/&#34;&gt;DROP DIRECTED QUERY&lt;/a&gt; removes the specified directed query from the database catalog. If the directed query is active, Vertica deactivates it before removal.&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; DROP DIRECTED QUERY findBostonCashiers_CUSTOM;
DROP DIRECTED QUERY
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;DROP DIRECTED QUERY can also drop multiple directed queries that are filtered from system table &lt;a href=&#34;../../../../../en/sql-reference/system-tables/v-catalog-schema/directed-queries/&#34;&gt;DIRECTED_QUERIES&lt;/a&gt;. In the following example, DROP DIRECTED QUERY drops all directed queries with the same &lt;code&gt;save_plans_version&lt;/code&gt; identifier:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; DROP DIRECTED QUERY WHERE save_plans_version = 21;
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
  </channel>
</rss>
