From 418cb3e61e0421dc3b0601523cde51fe69c94ff7 Mon Sep 17 00:00:00 2001 From: Henson Choi Date: Wed, 10 Jun 2026 16:21:08 +0900 Subject: [PATCH 69/77] Move RPR EXPLAIN marker description and add a worked example The paragraph describing the pattern absorption markers ("a+\"" and "(a' b')+\"") that EXPLAIN may print for Row Pattern Recognition was located in the Window Functions tutorial, which is not where readers look for EXPLAIN output details. Move it to the "Using EXPLAIN" section and illustrate it with an actual EXPLAIN plan over the stock table, so the markers are shown in real output rather than described in the abstract. --- doc/src/sgml/advanced.sgml | 14 ------------ doc/src/sgml/perform.sgml | 44 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/doc/src/sgml/advanced.sgml b/doc/src/sgml/advanced.sgml index 1410a443609..bdc552ad75f 100644 --- a/doc/src/sgml/advanced.sgml +++ b/doc/src/sgml/advanced.sgml @@ -676,20 +676,6 @@ FROM stock O(n2) to O(n) for many common patterns. - - When examining query plans for Row Pattern Recognition with - EXPLAIN, the pattern output may include special - markers that indicate optimization opportunities. A double quote - " marks where pattern absorption can occur, - and a single quote ' marks absorbable elements - within a branch. For example, a+" indicates that - repeated matches of a can be absorbed, while - (a' b')+" shows that both a - and b within the group are absorbable. - These markers are primarily useful for understanding internal - optimization behavior. - - When a query involves multiple window functions, it is possible to write out each one with a separate OVER clause, but this is diff --git a/doc/src/sgml/perform.sgml b/doc/src/sgml/perform.sgml index 604e8578a8d..01a83ab105d 100644 --- a/doc/src/sgml/perform.sgml +++ b/doc/src/sgml/perform.sgml @@ -701,6 +701,50 @@ FROM tenk1 t1 WHERE t1.ten = (SELECT (random() * 10)::integer); happen without the sub-SELECT construct. + + When examining query plans for Row Pattern Recognition with + EXPLAIN, the pattern output may include special + markers that indicate optimization opportunities. A double quote + " marks where pattern absorption can occur, + and a single quote ' marks absorbable elements + within a branch. For example, using the stock + table from , a query that looks for + repeated up-then-down movements reports its pattern as + (up' down')+": + + +EXPLAIN (COSTS OFF) +SELECT company, tdate, price, count(price) OVER w +FROM stock +WINDOW w AS ( + PARTITION BY company + ORDER BY tdate + ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING + AFTER MATCH SKIP PAST LAST ROW + INITIAL + PATTERN ((UP DOWN)+) + DEFINE UP AS price > PREV(price), + DOWN AS price < PREV(price) +); + + QUERY PLAN +-------------------------------------------------------------------&zwsp;------------------------------------ + WindowAgg + Window: w AS (PARTITION BY company ORDER BY tdate ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) + Pattern: (up' down')+" + Nav Mark Lookback: 1 + -> Sort + Sort Key: company, tdate + -> Seq Scan on stock + + + Here the single quotes mark up and + down as absorbable within the group, while the + trailing double quote marks the repeated group itself as absorbable. + These markers are primarily useful for understanding internal + optimization behavior. + + -- 2.50.1 (Apple Git-155)