<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>OpenText Analytics Database 26.2.x – Analytic functions</title>
    <link>/en/data-analysis/query-optimization/analytic-functions/</link>
    <description>Recent content in Analytic functions on OpenText Analytics Database 26.2.x</description>
    <generator>Hugo -- gohugo.io</generator>
    
	  <atom:link href="/en/data-analysis/query-optimization/analytic-functions/index.xml" rel="self" type="application/rss+xml" />
    
    
      
        
      
    
    
    <item>
      <title>Data-Analysis: Empty OVER clauses</title>
      <link>/en/data-analysis/query-optimization/analytic-functions/empty-over-clauses/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/data-analysis/query-optimization/analytic-functions/empty-over-clauses/</guid>
      <description>
        
        
        &lt;p&gt;The &lt;code&gt;OVER()&lt;/code&gt; clause does not require a windowing clause. If your query uses an analytic function like &lt;code&gt;SUM(x)&lt;/code&gt; and you specify an empty &lt;code&gt;OVER()&lt;/code&gt; clause, the analytic function is used as a reporting function, where the entire input is treated as a single partition; the aggregate returns the same aggregated value for each row of the result set. The query executes on a single node, potentially resulting in poor performance.&lt;/p&gt;
&lt;p&gt;If you add a &lt;code&gt;PARTITION BY&lt;/code&gt; clause to the &lt;code&gt;OVER()&lt;/code&gt; clause, the query executes on multiple nodes, improving its performance.&lt;/p&gt;

      </description>
    </item>
    
    <item>
      <title>Data-Analysis: NULL sort order</title>
      <link>/en/data-analysis/query-optimization/analytic-functions/null-sort-order/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/data-analysis/query-optimization/analytic-functions/null-sort-order/</guid>
      <description>
        
        
        &lt;p&gt;By default, projection column values are stored in ascending order, but placement of NULL values depends on a column&#39;s data type.&lt;/p&gt;
&lt;h2 id=&#34;null-placement-differences-with-order-by-clauses&#34;&gt;NULL placement differences with ORDER BY clauses&lt;/h2&gt;
&lt;p&gt;The analytic 
&lt;code&gt;OVER(&lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/language-elements/window-clauses/window-order-clause/#&#34;&gt;window-order-clause&lt;/a&gt;&lt;/span&gt;)&lt;/code&gt; and the SQL &lt;code&gt;ORDER BY&lt;/code&gt; clause have slightly different semantics:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;OVER(ORDER BY ...)&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The analytic window order clause uses the &lt;code&gt;ASC&lt;/code&gt; or &lt;code&gt;DESC&lt;/code&gt; sort order to determine &lt;code&gt;NULLS FIRST&lt;/code&gt; or &lt;code&gt;NULLS LAST&lt;/code&gt; placement for analytic function results. NULL values are placed as follows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;ASC&lt;/code&gt;, &lt;code&gt;NULLS LAST&lt;/code&gt; — NULL values appear at the end of the sorted result.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;DESC&lt;/code&gt;, &lt;code&gt;NULLS FIRST&lt;/code&gt; — NULL values appear at the beginning of the sorted result.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;(SQL) ORDER BY&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The SQL and OpenText™ Analytics Database &lt;code&gt;ORDER BY&lt;/code&gt; clauses produce different results. The SQL &lt;code&gt;ORDER BY&lt;/code&gt; clause specifies only ascending or descending sort order. The OpenText™ Analytics Database &lt;code&gt;ORDER BY&lt;/code&gt; clause determines NULL placement based on the column data type:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;NUMERIC, INTEGER, DATE, TIME, TIMESTAMP, and INTERVAL columns: &lt;code&gt;NULLS FIRST&lt;/code&gt; (NULL values appear at the beginning of a sorted projection.)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;FLOAT, STRING, and BOOLEAN columns: &lt;code&gt;NULLS LAST&lt;/code&gt; (NULL values appear at the end of a sorted projection.)&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;null-sort-options&#34;&gt;NULL sort options&lt;/h2&gt;
&lt;p&gt;If you do not care about NULL placement in queries that involve analytic computations, or if you know that columns do not contain any NULL values, specify &lt;code&gt;NULLS AUTO&lt;/code&gt;—irrespective of data type. The database chooses the placement that gives the fastest performance, as in the following query. Otherwise, specify &lt;code&gt;NULLS FIRST&lt;/code&gt; or &lt;code&gt;NULLS LAST&lt;/code&gt;.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT x, RANK() OVER (ORDER BY x NULLS AUTO) FROM t;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can carefully formulate queries so the database can avoid sorting the data and increase query performance, as illustrated by the following example. The database sorts inputs from table &lt;code&gt;t&lt;/code&gt; on column &lt;code&gt;x&lt;/code&gt;, as specified in the &lt;code&gt;OVER(ORDER BY)&lt;/code&gt; clause, and then evaluates &lt;code&gt;RANK()&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE t (
    x FLOAT,
    y FLOAT );
=&amp;gt; CREATE PROJECTION t_p (x, y) AS SELECT * FROM t
   ORDER BY x, y UNSEGMENTED ALL NODES;
=&amp;gt; SELECT x, RANK() OVER (ORDER BY x) FROM t;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In the preceding &lt;code&gt;SELECT&lt;/code&gt; statement, the database eliminates the &lt;code&gt;ORDER BY&lt;/code&gt; clause and executes the query quickly because column &lt;code&gt;x&lt;/code&gt; is a FLOAT data type. As a result, the projection sort order matches the analytic default ordering (&lt;code&gt;ASC + NULLS LAST&lt;/code&gt;). The database can also avoid having to sort the data when the underlying projection is already sorted.&lt;/p&gt;
&lt;p&gt;However, if column &lt;code&gt;x&lt;/code&gt; is an INTEGER data type, the database must sort the data because the projection sort order for INTEGER data types (&lt;code&gt;ASC + NULLS FIRST&lt;/code&gt;) does not match the default analytic ordering (&lt;code&gt;ASC + NULLS LAST&lt;/code&gt;). To help the database eliminate the sort, specify the placement of NULLs to match the default ordering:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT x, RANK() OVER (ORDER BY x NULLS FIRST) FROM t;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If column &lt;code&gt;x&lt;/code&gt; is a STRING, the following query eliminates the sort:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT x, RANK() OVER (ORDER BY x NULLS LAST) FROM t;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If you omit &lt;code&gt;NULLS LAST&lt;/code&gt; in the preceding query, Ver eliminates the sort because &lt;code&gt;ASC + NULLS LAST&lt;/code&gt; is the default sort specification for both the analytic &lt;code&gt;ORDER BY&lt;/code&gt; clause and for string-related columns.&lt;/p&gt;
&lt;h2 id=&#34;see-also&#34;&gt;See also&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/query-optimization/analytic-functions/runtime-sorting-of-null-values-analytic-functions/#&#34;&gt;Runtime sorting of NULL values in analytic functions&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&#34;../../../../en/data-analysis/sql-analytics/#&#34;&gt;SQL analytics&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

      </description>
    </item>
    
    <item>
      <title>Data-Analysis: Runtime sorting of NULL values in analytic functions</title>
      <link>/en/data-analysis/query-optimization/analytic-functions/runtime-sorting-of-null-values-analytic-functions/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/data-analysis/query-optimization/analytic-functions/runtime-sorting-of-null-values-analytic-functions/</guid>
      <description>
        
        
        &lt;p&gt;By carefully writing queries or creating your design (or both), you can help the query optimizer skip sorting all columns in a table when performing an analytic function, which can improve query performance.&lt;/p&gt;
&lt;p&gt;To minimize the need to sort projections during query execution, redefine the &lt;code&gt;employee&lt;/code&gt; table and specify that NULL values are not allowed in the sort fields:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; DROP TABLE employee CASCADE;
=&amp;gt; CREATE TABLE employee
   (empno INT,
    deptno INT &lt;span class=&#34;code-input&#34;&gt;NOT NULL&lt;/span&gt;,
    sal INT &lt;span class=&#34;code-input&#34;&gt;NOT NULL&lt;/span&gt;);
CREATE TABLE
=&amp;gt; CREATE PROJECTION employee_p AS
   SELECT * FROM employee
&lt;span class=&#34;code-input&#34;&gt;   ORDER BY &lt;/span&gt;deptno,&lt;span class=&#34;code-input&#34;&gt; sal&lt;/span&gt;;
CREATE PROJECTION
=&amp;gt; INSERT INTO employee VALUES(101,10,50000);
=&amp;gt; INSERT INTO employee VALUES(103,10,43000);
=&amp;gt; INSERT INTO employee VALUES(104,10,45000);
=&amp;gt; INSERT INTO employee VALUES(105,20,97000);
=&amp;gt; INSERT INTO employee VALUES(108,20,33000);
=&amp;gt; INSERT INTO employee VALUES(109,20,51000);
=&amp;gt; COMMIT;
COMMIT
&lt;/code&gt;&lt;/pre&gt;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT * FROM employee;
 empno | deptno |  sal
-------+--------+-------
   101 |     10 | 50000
   103 |     10 | 43000
   104 |     10 | 45000
   105 |     20 | 97000
   108 |     20 | 33000
   109 |     20 | 51000
(6 rows)
=&amp;gt; SELECT deptno, sal, empno, RANK() OVER
     (PARTITION BY deptno ORDER BY sal)
   FROM employee;
 deptno |  sal  | empno | ?column?
--------+-------+-------+----------
     10 | 43000 |   103 |        1
     10 | 45000 |   104 |        2
     10 | 50000 |   101 |        3
     20 | 33000 |   108 |        1
     20 | 51000 |   109 |        2
     20 | 97000 |   105 |        3
(6 rows)
&lt;/code&gt;&lt;/pre&gt;
&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;

If you do not care about NULL placement in queries that involve analytic computations, or if you know that columns contain no NULL values, specify &lt;code&gt;NULLS AUTO&lt;/code&gt; in your queries&lt;code&gt;.&lt;/code&gt; The database attempts to choose the placement that gives the fastest performance. Otherwise, specify &lt;code&gt;NULLS FIRST&lt;/code&gt; or &lt;code&gt;NULLS LAST&lt;/code&gt;.

&lt;/div&gt;

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