Skip to content

Commit 357858f

Browse files
committed
[BABEL-4673] Clean up added fields in FuncCall, FuncExpr
Added a new Node type BbfPivotData. Replaced pivot related fields with generic Node * fields in FuncCall and FuncExpr. Task: BABEL-4673 Signed-off-by: Yanjie Xu <[email protected]>
1 parent 3fd80cb commit 357858f

File tree

8 files changed

+34
-30
lines changed

8 files changed

+34
-30
lines changed

src/backend/executor/execSRF.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "funcapi.h"
2626
#include "miscadmin.h"
2727
#include "nodes/nodeFuncs.h"
28+
#include "nodes/parsenodes.h"
2829
#include "parser/parser.h"
2930
#include "parser/parse_coerce.h"
3031
#include "pgstat.h"
@@ -206,10 +207,10 @@ ExecMakeTableFunctionResult(SetExprState *setexpr,
206207

207208
/* if current FuncExpr is a bbf_pivot function, we set the fcinfo context to pivot data */
208209
if (sql_dialect == SQL_DIALECT_TSQL && IsA(setexpr->expr, FuncExpr)
209-
&& ((FuncExpr*) setexpr->expr)->pivot_parsetree != NIL
210-
&& ((FuncExpr*) setexpr->expr)->pivot_extrainfo != NIL)
210+
&& ((FuncExpr*) setexpr->expr)->context != NULL
211+
&& (IsA(((FuncExpr*) setexpr->expr)->context, BbfPivotData)))
211212
{
212-
fcinfo->context = (Node *) list_make2(((FuncExpr*) setexpr->expr)->pivot_parsetree, ((FuncExpr*) setexpr->expr)->pivot_extrainfo);
213+
fcinfo->context = ((FuncExpr*) setexpr->expr)->context;
213214
}
214215

215216
/*

src/backend/nodes/gen_node_support.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ sub elem
107107
# ABI stability during development.
108108

109109
my $last_nodetag = 'WindowObjectData';
110-
my $last_nodetag_no = 455;
110+
my $last_nodetag_no = 456;
111111

112112
# output file names
113113
my @output_files;

src/backend/nodes/makefuncs.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,7 @@ makeFuncExpr(Oid funcid, Oid rettype, List *args,
534534
funcexpr->inputcollid = inputcollid;
535535
funcexpr->args = args;
536536
funcexpr->location = -1;
537-
funcexpr->pivot_parsetree = NIL;
538-
funcexpr->pivot_extrainfo = NIL;
537+
funcexpr->context = NULL;
539538

540539
return funcexpr;
541540
}
@@ -602,8 +601,7 @@ makeFuncCall(List *name, List *args, CoercionForm funcformat, int location)
602601
n->func_variadic = false;
603602
n->funcformat = funcformat;
604603
n->location = location;
605-
n->pivot_parsetree = NIL;
606-
n->pivot_extrainfo = NIL;
604+
n->context = NULL;
607605
return n;
608606
}
609607

src/backend/optimizer/util/clauses.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2601,8 +2601,7 @@ eval_const_expressions_mutator(Node *node,
26012601
newexpr->inputcollid = expr->inputcollid;
26022602
newexpr->args = args;
26032603
newexpr->location = expr->location;
2604-
newexpr->pivot_parsetree = expr->pivot_parsetree;
2605-
newexpr->pivot_extrainfo = expr->pivot_extrainfo;
2604+
newexpr->context = expr->context;
26062605
return (Node *) newexpr;
26072606
}
26082607
case T_OpExpr:
@@ -4564,8 +4563,7 @@ evaluate_function(Oid funcid, Oid result_type, int32 result_typmod,
45644563
newexpr->inputcollid = input_collid;
45654564
newexpr->args = args;
45664565
newexpr->location = -1;
4567-
newexpr->pivot_parsetree = NIL;
4568-
newexpr->pivot_extrainfo = NIL;
4566+
newexpr->context = NULL;
45694567

45704568
return evaluate_expr((Expr *) newexpr, result_type, result_typmod,
45714569
result_collid);
@@ -4678,8 +4676,7 @@ inline_function(Oid funcid, Oid result_type, Oid result_collid,
46784676
fexpr->inputcollid = input_collid;
46794677
fexpr->args = args;
46804678
fexpr->location = -1;
4681-
fexpr->pivot_parsetree = NIL;
4682-
fexpr->pivot_extrainfo = NIL;
4679+
fexpr->context = NULL;
46834680

46844681
/* Fetch the function body */
46854682
tmp = SysCacheGetAttrNotNull(PROCOID, func_tuple, Anum_pg_proc_prosrc);

src/backend/parser/parse_func.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -765,17 +765,10 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
765765
/* funccollid and inputcollid will be set by parse_collate.c */
766766
funcexpr->args = fargs;
767767
funcexpr->location = location;
768+
funcexpr->context = NULL;
769+
768770
if (fn != NULL)
769-
{
770-
funcexpr->pivot_parsetree = copyObject(fn->pivot_parsetree);
771-
funcexpr->pivot_extrainfo = copyObject(fn->pivot_extrainfo);
772-
}
773-
else
774-
{
775-
funcexpr->pivot_parsetree = NIL;
776-
funcexpr->pivot_extrainfo = NIL;
777-
}
778-
771+
funcexpr->context = copyObject(fn->context);
779772

780773
retval = (Node *) funcexpr;
781774
}

src/include/nodes/parsenodes.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,7 @@ typedef struct FuncCall
432432
bool func_variadic; /* last argument was labeled VARIADIC */
433433
CoercionForm funcformat; /* how to display this node */
434434
int location; /* token location, or -1 if unknown */
435-
List *pivot_parsetree; /* bbf_pivot function required rewritted parsetrees */
436-
List *pivot_extrainfo; /* bbf_pivot function required aggregation function and source sql string */
435+
Node *context; /* pass necessary info through planner and executor */
437436
} FuncCall;
438437

439438
/*
@@ -4084,4 +4083,21 @@ typedef struct DropSubscriptionStmt
40844083
DropBehavior behavior; /* RESTRICT or CASCADE behavior */
40854084
} DropSubscriptionStmt;
40864085

4086+
/*
4087+
* BbfPivotData
4088+
* struct node to carry extra tsql pivot data produced by analyzer.
4089+
*/
4090+
typedef struct BbfPivotData
4091+
{
4092+
NodeTag type;
4093+
/* reconstructed source sql parsetree from tsql pivot stmt */
4094+
Node *source_sql_parsetree;
4095+
/* reconstructed catagory sql parsetree from tsql pivot stmt */
4096+
Node *category_sql_parsetree;
4097+
/* original tsql pivot stmt string */
4098+
char *tsql_definition;
4099+
/* aggregate function name for bbf_pivot function determine NULL or 0 for output */
4100+
char *agg_func_name;
4101+
}BbfPivotData;
4102+
40874103
#endif /* PARSENODES_H */

src/include/nodes/primnodes.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -695,10 +695,8 @@ typedef struct FuncExpr
695695
List *args;
696696
/* token location, or -1 if unknown */
697697
int location;
698-
/* bbf_pivot function required rewritted parsetrees */
699-
List *pivot_parsetree pg_node_attr(query_jumble_ignore, read_write_ignore, read_as(NULL));
700-
/* bbf_pivot function required aggregation function name and source sql string */
701-
List *pivot_extrainfo pg_node_attr(query_jumble_ignore, read_write_ignore, read_as(NULL));
698+
/* pass necessary info through planner and executor */
699+
Node *context pg_node_attr(query_jumble_ignore, read_write_ignore, read_as(NULL));
702700
} FuncExpr;
703701

704702
/*

src/tools/pgindent/typedefs.list

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ BaseBackupCmd
242242
BaseBackupTargetHandle
243243
BaseBackupTargetType
244244
BasicArchiveData
245+
BbfPivotData
245246
BeginDirectModify_function
246247
BeginForeignInsert_function
247248
BeginForeignModify_function

0 commit comments

Comments
 (0)