<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Vertica Documentation – INSERT-SELECT operations</title>
    <link>/en/data-analysis/query-optimization/insert-select-operations/</link>
    <description>Recent content in INSERT-SELECT operations on Vertica Documentation</description>
    <generator>Hugo -- gohugo.io</generator>
    
	  <atom:link href="/en/data-analysis/query-optimization/insert-select-operations/index.xml" rel="self" type="application/rss+xml" />
    
    
      
        
      
    
    
    <item>
      <title>Data-Analysis: Matching sort orders</title>
      <link>/en/data-analysis/query-optimization/insert-select-operations/matching-sort-orders/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/data-analysis/query-optimization/insert-select-operations/matching-sort-orders/</guid>
      <description>
        
        
        &lt;p&gt;When performing &lt;code&gt;INSERT&lt;/code&gt;-&lt;code&gt;SELECT&lt;/code&gt; operations, to avoid the sort phase of the &lt;code&gt;INSERT&lt;/code&gt;, make sure that the sort order for the &lt;code&gt;SELECT&lt;/code&gt; query matches the projection sort order of the target table.&lt;/p&gt;
&lt;p&gt;For example, on a single-node database:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE source (col1 INT, col2 INT, col3 INT);
=&amp;gt; CREATE PROJECTION source_p (col1, col2, col3)
     AS SELECT col1, col2, col3 FROM source
     ORDER BY col1, col2, col3
     SEGMENTED BY HASH(col3)
     ALL NODES;
=&amp;gt; CREATE TABLE destination (col1 INT, col2 INT, col3 INT);
=&amp;gt; CREATE PROJECTION destination_p (col1, col2, col3)
     AS SELECT col1, col2, col3 FROM destination
     ORDER BY col1, col2, col3
     SEGMENTED BY HASH(col3)
     ALL NODES;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following &lt;code&gt;INSERT&lt;/code&gt; does not require a sort because the query result has the column order of the projection:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; INSERT /*+direct*/ INTO destination SELECT * FROM source;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following &lt;code&gt;INSERT&lt;/code&gt; requires a sort because the order of the columns in the &lt;code&gt;SELECT&lt;/code&gt; statement does not match the projection order:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; INSERT /*+direct*/ INTO destination SELECT &lt;span class=&#34;code-input&#34;&gt;col1, col3, col2&lt;/span&gt; FROM source;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following &lt;code&gt;INSERT&lt;/code&gt; does not require a sort. The order of the columns doesn&#39;t match, but the explicit ORDER BY causes the output to be sorted by &lt;code&gt;c1&lt;/code&gt;, &lt;code&gt;c3&lt;/code&gt;, &lt;code&gt;c2&lt;/code&gt; in Vertica:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; INSERT /*+direct*/ INTO destination SELECT col1, col3, col2 FROM source
      GROUP BY col1, col3, col2
      ORDER BY col1, col2, col3 ;
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Data-Analysis: Identical segmentation</title>
      <link>/en/data-analysis/query-optimization/insert-select-operations/identical-segmentation/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/data-analysis/query-optimization/insert-select-operations/identical-segmentation/</guid>
      <description>
        
        
        &lt;p&gt;When performing an &lt;code&gt;INSERT-SELECT&lt;/code&gt; operation from a segmented source table to a segmented destination table, segment both projections on the same column to avoid resegmenting the data, as in the following example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;CREATE TABLE source (col1 INT, col2 INT, col3 INT);
CREATE PROJECTION source_p (col1, col2, col3) AS
   SELECT col1, col2, col3 FROM source
   SEGMENTED BY HASH(col3) ALL NODES;
CREATE TABLE destination (col1 INT, col2 INT, col3 INT);
CREATE PROJECTION destination_p (col1, col2, col3) AS
    SELECT col1, col2, col3 FROM destination
    SEGMENTED BY HASH(col3) ALL NODES;
INSERT /*+direct*/ INTO destination SELECT * FROM source;
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
  </channel>
</rss>
