aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Rowley <drowley@postgresql.org>2022-08-05 10:14:40 +1200
committerDavid Rowley <drowley@postgresql.org>2022-08-05 10:14:40 +1200
commit270eb4b5d4986534f2d522ebb19f67396d13cf44 (patch)
tree313b3dd8d1d6678592575b6a8177c48ddf4e4705 /src
parent6f7e7d0c482dd3c635f0de8e77fe6f783e43a078 (diff)
downloadpostgresql-270eb4b5d4986534f2d522ebb19f67396d13cf44.tar.gz
postgresql-270eb4b5d4986534f2d522ebb19f67396d13cf44.zip
Fix failure to set correct operator in window run condition
This was a simple omission in 9d9c02ccd where the code didn't correctly set the operator to use in the run condition OpExpr when the window function was both monotonically increasing and decreasing. Bug discovered by Julien Roze, although he did not report it. Reported-by: Phil Florent Discussion: https://postgr.es/m/PA4P191MB160009A09B9D0624359278CFBA9F9@PA4P191MB1600.EURP191.PROD.OUTLOOK.COM Backpatch-through: 15, where 9d9c02ccd was added
Diffstat (limited to 'src')
-rw-r--r--src/backend/optimizer/path/allpaths.c1
-rw-r--r--src/test/regress/expected/window.out17
-rw-r--r--src/test/regress/sql/window.sql11
3 files changed, 29 insertions, 0 deletions
diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c
index 4cf0cdc4beb..8a193cfea37 100644
--- a/src/backend/optimizer/path/allpaths.c
+++ b/src/backend/optimizer/path/allpaths.c
@@ -2306,6 +2306,7 @@ find_window_run_conditions(Query *subquery, RangeTblEntry *rte, Index rti,
{
*keep_original = false;
runopexpr = opexpr;
+ runoperator = opexpr->opno;
break;
}
diff --git a/src/test/regress/expected/window.out b/src/test/regress/expected/window.out
index 433a0bb0259..55dcd668c94 100644
--- a/src/test/regress/expected/window.out
+++ b/src/test/regress/expected/window.out
@@ -3646,6 +3646,23 @@ WHERE c <= 3;
3 | sales | 4800 | 3
(8 rows)
+-- Ensure we get the correct run condition when the window function is both
+-- monotonically increasing and decreasing.
+EXPLAIN (COSTS OFF)
+SELECT * FROM
+ (SELECT empno,
+ depname,
+ salary,
+ count(empno) OVER () c
+ FROM empsalary) emp
+WHERE c = 1;
+ QUERY PLAN
+--------------------------------------------------------
+ WindowAgg
+ Run Condition: (count(empsalary.empno) OVER (?) = 1)
+ -> Seq Scan on empsalary
+(3 rows)
+
-- Some more complex cases with multiple window clauses
EXPLAIN (COSTS OFF)
SELECT * FROM
diff --git a/src/test/regress/sql/window.sql b/src/test/regress/sql/window.sql
index a504e46e403..57c39e796c1 100644
--- a/src/test/regress/sql/window.sql
+++ b/src/test/regress/sql/window.sql
@@ -1150,6 +1150,17 @@ SELECT * FROM
FROM empsalary) emp
WHERE c <= 3;
+-- Ensure we get the correct run condition when the window function is both
+-- monotonically increasing and decreasing.
+EXPLAIN (COSTS OFF)
+SELECT * FROM
+ (SELECT empno,
+ depname,
+ salary,
+ count(empno) OVER () c
+ FROM empsalary) emp
+WHERE c = 1;
+
-- Some more complex cases with multiple window clauses
EXPLAIN (COSTS OFF)
SELECT * FROM