Search notes:

Oracle SQL Plan operation: WINDOW

The WINDOW plan operations always has one row source.
create table tq84_tab (
   part  varchar2(10),
   num   number
);

WINDOW BUFFER

The plan operation window in combination with the option buffer is used for analytic functions without order by or partition by clause:
explain plan for
select
   part,
   num,
   sum(num) over () cnt
from
   tq84_tab;

select * from table(dbms_xplan.display(format=>'basic'));
--
-- ---------------------------------------
-- | Id  | Operation          | Name     |
-- ---------------------------------------
-- |   0 | SELECT STATEMENT   |          |
-- |   1 |  WINDOW BUFFER     |          |
-- |   2 |   TABLE ACCESS FULL| TQ84_TAB |
-- ---------------------------------------

WINDOW SORT

An analytic function with a partition by or order by clause requires the window operation with the sort option.
explain plan for
select
   part,
   num,
   count(num) over (partition by part) cnt
from
   tq84_tab;

select * from table(dbms_xplan.display(format=>'basic'));
--
-- ---------------------------------------
-- | Id  | Operation          | Name     |
-- ---------------------------------------
-- |   0 | SELECT STATEMENT   |          |
-- |   1 |  WINDOW SORT       |          |
-- |   2 |   TABLE ACCESS FULL| TQ84_TAB |
-- ---------------------------------------
explain plan for
select
   part,
   num,
   sum(num) over (order by num) cnt
from
   tq84_tab;

select * from table(dbms_xplan.display(format=>'basic'));
--
-- ---------------------------------------
-- | Id  | Operation          | Name     |
-- ---------------------------------------
-- |   0 | SELECT STATEMENT   |          |
-- |   1 |  WINDOW SORT       |          |
-- |   2 |   TABLE ACCESS FULL| TQ84_TAB |
-- ---------------------------------------

WINDOW SORT PUSHED RANK

The operation window requires a sort pushed rank operation if the analytic function rank() over () is used to in a subquery to limit the number of returned records.
The following query has a rank() over () analytic function, but it does not occur in a subquery. The operation is window, the option is sort:
explain plan for
select
   t.*,
   rank() over (order by t.num) rn
from
   tq84_tab t;

select * from table(dbms_xplan.display(format=>'basic'));
--
-- ---------------------------------------
-- | Id  | Operation          | Name     |
-- ---------------------------------------
-- |   0 | SELECT STATEMENT   |          |
-- |   1 |  WINDOW SORT       |          |
-- |   2 |   TABLE ACCESS FULL| TQ84_TAB |
-- ---------------------------------------
However, if the previous query is used a subquery and the outer query uses the value returned by the rank() analytic function, the option of the window operation changes from sort to sort pushed rank:
explain plan for
select
   part,
   num
from (
   select
      t.*,
      rank() over (order by t.num) rn
   from
      tq84_tab t
)
where
   rn <= 42;
--
-- ---------------------------------------------
-- | Id  | Operation                | Name     |
-- ---------------------------------------------
-- |   0 | SELECT STATEMENT         |          |
-- |   1 |  VIEW                    |          |
-- |   2 |   WINDOW SORT PUSHED RANK|          |
-- |   3 |    TABLE ACCESS FULL     | TQ84_TAB |
-- ---------------------------------------------

See also

Plan operations

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758199880, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/Oracle/SQL/statement/execution/plan/operations/window/index(156): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78