Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 901ac1c

Browse files
tatsuo-ishiiCommitfest Bot
authored and
Commitfest Bot
committed
Row pattern recognition patch (planner).
1 parent e71c9ad commit 901ac1c

File tree

5 files changed

+73
-3
lines changed

5 files changed

+73
-3
lines changed

src/backend/optimizer/plan/createplan.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,9 @@ static Memoize *make_memoize(Plan *lefttree, Oid *hashoperators,
288288
static WindowAgg *make_windowagg(List *tlist, WindowClause *wc,
289289
int partNumCols, AttrNumber *partColIdx, Oid *partOperators, Oid *partCollations,
290290
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
291-
List *runCondition, List *qual, bool topWindow,
291+
List *runCondition, RPSkipTo rpSkipTo, List *patternVariable,
292+
List *patternRegexp, List *defineClause, List *defineInitial,
293+
List *qual, bool topWindow,
292294
Plan *lefttree);
293295
static Group *make_group(List *tlist, List *qual, int numGroupCols,
294296
AttrNumber *grpColIdx, Oid *grpOperators, Oid *grpCollations,
@@ -2690,6 +2692,11 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
26902692
ordOperators,
26912693
ordCollations,
26922694
best_path->runCondition,
2695+
wc->rpSkipTo,
2696+
wc->patternVariable,
2697+
wc->patternRegexp,
2698+
wc->defineClause,
2699+
wc->defineInitial,
26932700
best_path->qual,
26942701
best_path->topwindow,
26952702
subplan);
@@ -6699,7 +6706,9 @@ static WindowAgg *
66996706
make_windowagg(List *tlist, WindowClause *wc,
67006707
int partNumCols, AttrNumber *partColIdx, Oid *partOperators, Oid *partCollations,
67016708
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
6702-
List *runCondition, List *qual, bool topWindow, Plan *lefttree)
6709+
List *runCondition, RPSkipTo rpSkipTo, List *patternVariable,
6710+
List *patternRegexp, List *defineClause, List *defineInitial,
6711+
List *qual, bool topWindow, Plan *lefttree)
67036712
{
67046713
WindowAgg *node = makeNode(WindowAgg);
67056714
Plan *plan = &node->plan;
@@ -6726,6 +6735,11 @@ make_windowagg(List *tlist, WindowClause *wc,
67266735
node->inRangeAsc = wc->inRangeAsc;
67276736
node->inRangeNullsFirst = wc->inRangeNullsFirst;
67286737
node->topWindow = topWindow;
6738+
node->rpSkipTo = rpSkipTo;
6739+
node->patternVariable = patternVariable;
6740+
node->patternRegexp = patternRegexp;
6741+
node->defineClause = defineClause;
6742+
node->defineInitial = defineInitial;
67296743

67306744
plan->targetlist = tlist;
67316745
plan->lefttree = lefttree;

src/backend/optimizer/plan/planner.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
901901
EXPRKIND_LIMIT);
902902
wc->endOffset = preprocess_expression(root, wc->endOffset,
903903
EXPRKIND_LIMIT);
904+
wc->defineClause = (List *) preprocess_expression(root,
905+
(Node *) wc->defineClause,
906+
EXPRKIND_TARGET);
904907
}
905908

906909
parse->limitOffset = preprocess_expression(root, parse->limitOffset,

src/backend/optimizer/plan/setrefs.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
211211
List *runcondition,
212212
Plan *plan);
213213

214-
215214
/*****************************************************************************
216215
*
217216
* SUBPLAN REFERENCES
@@ -2551,6 +2550,32 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset)
25512550
NRM_EQUAL,
25522551
NUM_EXEC_QUAL(plan));
25532552

2553+
/*
2554+
* Modifies an expression tree in each DEFINE clause so that all Var
2555+
* nodes's varno refers to OUTER_VAR.
2556+
*/
2557+
if (IsA(plan, WindowAgg))
2558+
{
2559+
WindowAgg *wplan = (WindowAgg *) plan;
2560+
2561+
if (wplan->defineClause != NIL)
2562+
{
2563+
foreach(l, wplan->defineClause)
2564+
{
2565+
TargetEntry *tle = (TargetEntry *) lfirst(l);
2566+
2567+
tle->expr = (Expr *)
2568+
fix_upper_expr(root,
2569+
(Node *) tle->expr,
2570+
subplan_itlist,
2571+
OUTER_VAR,
2572+
rtoffset,
2573+
NRM_EQUAL,
2574+
NUM_EXEC_QUAL(plan));
2575+
}
2576+
}
2577+
}
2578+
25542579
pfree(subplan_itlist);
25552580
}
25562581

src/backend/optimizer/prep/prepjointree.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2446,6 +2446,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
24462446
parse->returningList = (List *)
24472447
pullup_replace_vars((Node *) parse->returningList, rvcontext);
24482448

2449+
foreach(lc, parse->windowClause)
2450+
{
2451+
WindowClause *wc = lfirst_node(WindowClause, lc);
2452+
2453+
if (wc->defineClause != NIL)
2454+
wc->defineClause = (List *)
2455+
pullup_replace_vars((Node *) wc->defineClause, rvcontext);
2456+
}
2457+
24492458
if (parse->onConflict)
24502459
{
24512460
parse->onConflict->onConflictSet = (List *)

src/include/nodes/plannodes.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "lib/stringinfo.h"
2121
#include "nodes/bitmapset.h"
2222
#include "nodes/lockoptions.h"
23+
#include "nodes/parsenodes.h"
2324
#include "nodes/primnodes.h"
2425

2526

@@ -1236,6 +1237,24 @@ typedef struct WindowAgg
12361237
/* nulls sort first for in_range tests? */
12371238
bool inRangeNullsFirst;
12381239

1240+
/* Row Pattern Recognition AFTER MACH SKIP clause */
1241+
RPSkipTo rpSkipTo; /* Row Pattern Skip To type */
1242+
1243+
/* Row Pattern PATTERN variable name (list of String) */
1244+
List *patternVariable;
1245+
1246+
/*
1247+
* Row Pattern RPATTERN regular expression quantifier ('+' or ''. list of
1248+
* String)
1249+
*/
1250+
List *patternRegexp;
1251+
1252+
/* Row Pattern DEFINE clause (list of TargetEntry) */
1253+
List *defineClause;
1254+
1255+
/* Row Pattern DEFINE variable initial names (list of String) */
1256+
List *defineInitial;
1257+
12391258
/*
12401259
* false for all apart from the WindowAgg that's closest to the root of
12411260
* the plan

0 commit comments

Comments
 (0)