Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit836c31b

Browse files
committed
Disable WindowAgg inverse transitions when subplans are present
When an aggregate function is used as a WindowFunc and a tuple transitionsout of the window frame, we ordinarily try to make use of the aggregatefunction's inverse transition function to "unaggregate" the exiting tuple.This optimization is disabled for various cases, including when theaggregate contains a volatile function. In such a case we'd be unable toensure that the transition value was calculated to the same value duringtransitions and inverse transitions. Unfortunately, we did this check bycalling contain_volatile_functions() which does not recursively searchSubPlans for volatile functions. If the aggregate function's arguments orits FILTER clause contained a subplan with volatile functions then we'dfail to notice this.Here we fix this by just disabling the optimization when the WindowFunccontains any subplans. Volatile functions are not the only reason that asubplan may have nonrepeatable results.Bug: #17777Reported-by: Anban CompanyDiscussion:https://postgr.es/m/17777-860b739b6efde977%40postgresql.orgReviewed-by: Tom LaneBackpatch-through: 11
1 parent2a507f6 commit836c31b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

‎src/backend/executor/nodeWindowAgg.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include"executor/nodeWindowAgg.h"
4242
#include"miscadmin.h"
4343
#include"nodes/nodeFuncs.h"
44+
#include"optimizer/clauses.h"
4445
#include"optimizer/optimizer.h"
4546
#include"parser/parse_agg.h"
4647
#include"parser/parse_coerce.h"
@@ -2803,16 +2804,24 @@ initialize_peragg(WindowAggState *winstate, WindowFunc *wfunc,
28032804
* aggregate's arguments (and FILTER clause if any) contain any calls to
28042805
* volatile functions. Otherwise, the difference between restarting and
28052806
* not restarting the aggregation would be user-visible.
2807+
*
2808+
* We also don't risk using moving aggregates when there are subplans in
2809+
* the arguments or FILTER clause. This is partly because
2810+
* contain_volatile_functions() doesn't look inside subplans; but there
2811+
* are other reasons why a subplan's output might be volatile. For
2812+
* example, syncscan mode can render the results nonrepeatable.
28062813
*/
28072814
if (!OidIsValid(aggform->aggminvtransfn))
28082815
use_ma_code= false;/* sine qua non */
28092816
elseif (aggform->aggmfinalmodify==AGGMODIFY_READ_ONLY&&
2810-
aggform->aggfinalmodify!=AGGMODIFY_READ_ONLY)
2817+
aggform->aggfinalmodify!=AGGMODIFY_READ_ONLY)
28112818
use_ma_code= true;/* decision forced by safety */
28122819
elseif (winstate->frameOptions&FRAMEOPTION_START_UNBOUNDED_PRECEDING)
28132820
use_ma_code= false;/* non-moving frame head */
28142821
elseif (contain_volatile_functions((Node*)wfunc))
28152822
use_ma_code= false;/* avoid possible behavioral change */
2823+
elseif (contain_subplans((Node*)wfunc))
2824+
use_ma_code= false;/* subplans might contain volatile functions */
28162825
else
28172826
use_ma_code= true;/* yes, let's use it */
28182827
if (use_ma_code)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp