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

Commite3c8038

Browse files
author
Nikita Glukhov
committed
Remove handling of JSON parsing errors in SQL/JSON functions
1 parentfee6ee5 commite3c8038

File tree

12 files changed

+21
-83
lines changed

12 files changed

+21
-83
lines changed

‎contrib/pg_stat_statements/pg_stat_statements.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3139,7 +3139,7 @@ JumbleExpr(pgssJumbleState *jstate, Node *node)
31393139
JsonExpr*jexpr= (JsonExpr*)node;
31403140

31413141
APP_JUMB(jexpr->op);
3142-
JumbleExpr(jstate,jexpr->raw_expr);
3142+
JumbleExpr(jstate,jexpr->formatted_expr);
31433143
JumbleExpr(jstate,jexpr->path_spec);
31443144
foreach(temp,jexpr->passing_names)
31453145
{

‎src/backend/executor/execExpr.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,12 +2213,12 @@ ExecInitExprRec(Expr *node, ExprState *state,
22132213
scratch.opcode=EEOP_JSONEXPR;
22142214
scratch.d.jsonexpr.jsexpr=jexpr;
22152215

2216-
scratch.d.jsonexpr.raw_expr=
2217-
palloc(sizeof(*scratch.d.jsonexpr.raw_expr));
2216+
scratch.d.jsonexpr.formatted_expr=
2217+
palloc(sizeof(*scratch.d.jsonexpr.formatted_expr));
22182218

2219-
ExecInitExprRec((Expr*)jexpr->raw_expr,state,
2220-
&scratch.d.jsonexpr.raw_expr->value,
2221-
&scratch.d.jsonexpr.raw_expr->isnull);
2219+
ExecInitExprRec((Expr*)jexpr->formatted_expr,state,
2220+
&scratch.d.jsonexpr.formatted_expr->value,
2221+
&scratch.d.jsonexpr.formatted_expr->isnull);
22222222

22232223
scratch.d.jsonexpr.pathspec=
22242224
palloc(sizeof(*scratch.d.jsonexpr.pathspec));
@@ -2227,12 +2227,6 @@ ExecInitExprRec(Expr *node, ExprState *state,
22272227
&scratch.d.jsonexpr.pathspec->value,
22282228
&scratch.d.jsonexpr.pathspec->isnull);
22292229

2230-
scratch.d.jsonexpr.formatted_expr=
2231-
ExecInitExprWithCaseValue((Expr*)jexpr->formatted_expr,
2232-
state->parent,
2233-
&scratch.d.jsonexpr.raw_expr->value,
2234-
&scratch.d.jsonexpr.raw_expr->isnull);
2235-
22362230
scratch.d.jsonexpr.res_expr=
22372231
palloc(sizeof(*scratch.d.jsonexpr.res_expr));
22382232

‎src/backend/executor/execExprInterp.c

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4780,26 +4780,6 @@ ExecEvalJsonExpr(ExprEvalStep *op, ExprContext *econtext,
47804780
boolempty= false;
47814781
Datumres= (Datum)0;
47824782

4783-
if (op->d.jsonexpr.formatted_expr)
4784-
{
4785-
boolisnull;
4786-
4787-
Assert(!cxt->coercionInSubtrans);
4788-
4789-
op->d.jsonexpr.raw_expr->value=item;
4790-
op->d.jsonexpr.raw_expr->isnull= false;
4791-
4792-
item=ExecEvalExpr(op->d.jsonexpr.formatted_expr,econtext,&isnull);
4793-
if (isnull)
4794-
{
4795-
/* execute domain checks for NULLs */
4796-
(void)ExecEvalJsonExprCoercion(op,econtext,res,resnull,
4797-
NULL,NULL);
4798-
*resnull= true;
4799-
return (Datum)0;
4800-
}
4801-
}
4802-
48034783
switch (jexpr->op)
48044784
{
48054785
caseIS_JSON_QUERY:
@@ -4929,9 +4909,6 @@ ExecEvalJsonNeedsSubTransaction(JsonExpr *jsexpr,
49294909
if (jsexpr->on_error->btype==JSON_BEHAVIOR_ERROR)
49304910
return false;
49314911

4932-
if (jsexpr->formatted_expr)
4933-
return true;
4934-
49354912
if (jsexpr->op==IS_JSON_EXISTS)
49364913
return false;
49374914

@@ -4961,7 +4938,7 @@ ExecEvalJson(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
49614938
*op->resnull= true;/* until we get a result */
49624939
*op->resvalue= (Datum)0;
49634940

4964-
if (op->d.jsonexpr.raw_expr->isnull||op->d.jsonexpr.pathspec->isnull)
4941+
if (op->d.jsonexpr.formatted_expr->isnull||op->d.jsonexpr.pathspec->isnull)
49654942
{
49664943
/* execute domain checks for NULLs */
49674944
(void)ExecEvalJsonExprCoercion(op,econtext,res,op->resnull,
@@ -4973,7 +4950,7 @@ ExecEvalJson(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
49734950
return;
49744951
}
49754952

4976-
item=op->d.jsonexpr.raw_expr->value;
4953+
item=op->d.jsonexpr.formatted_expr->value;
49774954
path=DatumGetJsonPathP(op->d.jsonexpr.pathspec->value);
49784955

49794956
/* reset JSON path variable contexts */

‎src/backend/nodes/copyfuncs.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2449,7 +2449,6 @@ _copyJsonExpr(const JsonExpr *from)
24492449
JsonExpr*newnode=makeNode(JsonExpr);
24502450

24512451
COPY_SCALAR_FIELD(op);
2452-
COPY_NODE_FIELD(raw_expr);
24532452
COPY_NODE_FIELD(formatted_expr);
24542453
COPY_NODE_FIELD(result_coercion);
24552454
COPY_NODE_FIELD(format);

‎src/backend/nodes/equalfuncs.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,6 @@ static bool
984984
_equalJsonExpr(constJsonExpr*a,constJsonExpr*b)
985985
{
986986
COMPARE_SCALAR_FIELD(op);
987-
COMPARE_NODE_FIELD(raw_expr);
988987
COMPARE_NODE_FIELD(formatted_expr);
989988
COMPARE_NODE_FIELD(result_coercion);
990989
COMPARE_NODE_FIELD(format);

‎src/backend/nodes/nodeFuncs.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,7 +1654,7 @@ exprLocation(const Node *expr)
16541654

16551655
/* consider both function name and leftmost arg */
16561656
loc=leftmostLoc(jsexpr->location,
1657-
exprLocation(jsexpr->raw_expr));
1657+
exprLocation(jsexpr->formatted_expr));
16581658
}
16591659
break;
16601660
default:
@@ -2382,8 +2382,6 @@ expression_tree_walker(Node *node,
23822382
{
23832383
JsonExpr*jexpr= (JsonExpr*)node;
23842384

2385-
if (walker(jexpr->raw_expr,context))
2386-
return true;
23872385
if (walker(jexpr->formatted_expr,context))
23882386
return true;
23892387
if (walker(jexpr->result_coercion,context))
@@ -3406,7 +3404,6 @@ expression_tree_mutator(Node *node,
34063404

34073405
FLATCOPY(newnode,jexpr,JsonExpr);
34083406
MUTATE(newnode->path_spec,jexpr->path_spec,Node*);
3409-
MUTATE(newnode->raw_expr,jexpr->raw_expr,Node*);
34103407
MUTATE(newnode->formatted_expr,jexpr->formatted_expr,Node*);
34113408
MUTATE(newnode->result_coercion,jexpr->result_coercion,JsonCoercion*);
34123409
MUTATE(newnode->passing_values,jexpr->passing_values,List*);

‎src/backend/nodes/outfuncs.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1780,7 +1780,6 @@ _outJsonExpr(StringInfo str, const JsonExpr *node)
17801780
WRITE_NODE_TYPE("JSONEXPR");
17811781

17821782
WRITE_ENUM_FIELD(op,JsonExprOp);
1783-
WRITE_NODE_FIELD(raw_expr);
17841783
WRITE_NODE_FIELD(formatted_expr);
17851784
WRITE_NODE_FIELD(result_coercion);
17861785
WRITE_NODE_FIELD(format);

‎src/backend/nodes/readfuncs.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,6 @@ _readJsonExpr(void)
14311431
READ_LOCALS(JsonExpr);
14321432

14331433
READ_ENUM_FIELD(op,JsonExprOp);
1434-
READ_NODE_FIELD(raw_expr);
14351434
READ_NODE_FIELD(formatted_expr);
14361435
READ_NODE_FIELD(result_coercion);
14371436
READ_NODE_FIELD(format);

‎src/backend/parser/parse_expr.c

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3693,8 +3693,7 @@ makeCaseTestExpr(Node *expr)
36933693
*/
36943694
staticNode*
36953695
transformJsonValueExprExt(ParseState*pstate,JsonValueExpr*ve,
3696-
JsonFormatTypedefault_format,boolisarg,
3697-
Node**prawexpr)
3696+
JsonFormatTypedefault_format,boolisarg)
36983697
{
36993698
Node*expr=transformExprRecurse(pstate, (Node*)ve->raw_expr);
37003699
Node*rawexpr;
@@ -3715,17 +3714,6 @@ transformJsonValueExprExt(ParseState *pstate, JsonValueExpr *ve,
37153714

37163715
rawexpr=expr;
37173716

3718-
if (prawexpr)
3719-
{
3720-
/*
3721-
* Save a raw context item expression if it is needed for the isolation
3722-
* of error handling in the formatting stage.
3723-
*/
3724-
*prawexpr=expr;
3725-
assign_expr_collations(pstate,expr);
3726-
expr=makeCaseTestExpr(expr);
3727-
}
3728-
37293717
if (ve->format->format!=JS_FORMAT_DEFAULT)
37303718
{
37313719
if (ve->format->encoding!=JS_ENC_DEFAULT&&exprtype!=BYTEAOID)
@@ -3846,7 +3834,7 @@ transformJsonValueExprExt(ParseState *pstate, JsonValueExpr *ve,
38463834
staticNode*
38473835
transformJsonValueExpr(ParseState*pstate,JsonValueExpr*jve)
38483836
{
3849-
returntransformJsonValueExprExt(pstate,jve,JS_FORMAT_JSON, false,NULL);
3837+
returntransformJsonValueExprExt(pstate,jve,JS_FORMAT_JSON, false);
38503838
}
38513839

38523840
/*
@@ -3855,7 +3843,7 @@ transformJsonValueExpr(ParseState *pstate, JsonValueExpr *jve)
38553843
staticNode*
38563844
transformJsonValueExprDefault(ParseState*pstate,JsonValueExpr*jve)
38573845
{
3858-
returntransformJsonValueExprExt(pstate,jve,JS_FORMAT_DEFAULT, false,NULL);
3846+
returntransformJsonValueExprExt(pstate,jve,JS_FORMAT_DEFAULT, false);
38593847
}
38603848

38613849
/*
@@ -4505,7 +4493,7 @@ transformJsonPassingArgs(ParseState *pstate, JsonFormatType format, List *args,
45054493
{
45064494
JsonArgument*arg=castNode(JsonArgument,lfirst(lc));
45074495
Node*expr=transformJsonValueExprExt(pstate,arg->val,
4508-
format, true,NULL);
4496+
format, true);
45094497

45104498
assign_expr_collations(pstate,expr);
45114499

@@ -4550,20 +4538,12 @@ transformJsonExprCommon(ParseState *pstate, JsonFuncExpr *func)
45504538

45514539
jsexpr->location=func->location;
45524540
jsexpr->op=func->op;
4553-
jsexpr->formatted_expr=transformJsonValueExprExt(pstate,
4554-
func->common->expr,
4555-
JS_FORMAT_JSON,
4556-
false,
4557-
&jsexpr->raw_expr);
4541+
jsexpr->formatted_expr=transformJsonValueExpr(pstate,func->common->expr);
45584542

45594543
assign_expr_collations(pstate,jsexpr->formatted_expr);
45604544

45614545
/* format is determined by context item type */
4562-
format=exprType(jsexpr->formatted_expr)==JSONBOID ?
4563-
JS_FORMAT_JSONB :JS_FORMAT_JSON;
4564-
4565-
if (jsexpr->formatted_expr==jsexpr->raw_expr)
4566-
jsexpr->formatted_expr=NULL;
4546+
format=exprType(jsexpr->formatted_expr)==JSONBOID ?JS_FORMAT_JSONB :JS_FORMAT_JSON;
45674547

45684548
jsexpr->result_coercion=NULL;
45694549
jsexpr->omit_quotes= false;
@@ -4662,8 +4642,7 @@ static void
46624642
transformJsonFuncExprOutput(ParseState*pstate,JsonFuncExpr*func,
46634643
JsonExpr*jsexpr)
46644644
{
4665-
Node*expr=jsexpr->formatted_expr ?
4666-
jsexpr->formatted_expr :jsexpr->raw_expr;
4645+
Node*expr=jsexpr->formatted_expr;
46674646

46684647
jsexpr->returning=transformJsonOutput(pstate,func->output, false);
46694648

@@ -4689,7 +4668,7 @@ transformJsonFuncExprOutput(ParseState *pstate,JsonFuncExpr *func,
46894668
return;
46904669
}
46914670

4692-
assignDefaultJsonReturningType(jsexpr->raw_expr,jsexpr->format,&ret);
4671+
assignDefaultJsonReturningType(jsexpr->formatted_expr,jsexpr->format,&ret);
46934672

46944673
if (ret.typid!=jsexpr->returning->typid||
46954674
ret.typmod!=jsexpr->returning->typmod)
@@ -4704,7 +4683,7 @@ transformJsonFuncExprOutput(ParseState *pstate,JsonFuncExpr *func,
47044683
}
47054684
}
47064685
else
4707-
assignDefaultJsonReturningType(jsexpr->raw_expr,jsexpr->format,
4686+
assignDefaultJsonReturningType(jsexpr->formatted_expr,jsexpr->format,
47084687
jsexpr->returning);
47094688
}
47104689

@@ -4809,9 +4788,8 @@ static Node *
48094788
transformJsonFuncExpr(ParseState*pstate,JsonFuncExpr*func)
48104789
{
48114790
JsonExpr*jsexpr=transformJsonExprCommon(pstate,func);
4812-
Node*contextItemExpr=
4813-
jsexpr->formatted_expr ?jsexpr->formatted_expr :jsexpr->raw_expr;
48144791
constchar*func_name=NULL;
4792+
Node*contextItemExpr=jsexpr->formatted_expr;
48154793

48164794
switch (func->op)
48174795
{

‎src/backend/utils/adt/ruleutils.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9280,9 +9280,7 @@ get_rule_expr(Node *node, deparse_context *context,
92809280
break;
92819281
}
92829282

9283-
get_rule_expr(jexpr->raw_expr,context,showimplicit);
9284-
9285-
get_json_format(jexpr->format,context->buf);
9283+
get_rule_expr(jexpr->formatted_expr,context,showimplicit);
92869284

92879285
appendStringInfoString(buf,", ");
92889286

‎src/include/executor/execExpr.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,12 +673,11 @@ typedef struct ExprEvalStep
673673
}input;/* I/O info for output type */
674674

675675
NullableDatum
676-
*raw_expr,/*raw context item value */
676+
*formatted_expr,/*formatted context item value */
677677
*res_expr,/* result item */
678678
*coercion_expr,/* input for JSON item coercion */
679679
*pathspec;/* path specification value */
680680

681-
ExprState*formatted_expr;/* formatted context item */
682681
ExprState*result_expr;/* coerced to output type */
683682
ExprState*default_on_empty;/* ON EMPTY DEFAULT expression */
684683
ExprState*default_on_error;/* ON ERROR DEFAULT expression */

‎src/include/nodes/primnodes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1390,7 +1390,6 @@ typedef struct JsonExpr
13901390
{
13911391
Exprxpr;
13921392
JsonExprOpop;/* json function ID */
1393-
Node*raw_expr;/* raw context item expression */
13941393
Node*formatted_expr;/* formatted context item expression */
13951394
JsonCoercion*result_coercion;/* resulting coercion to RETURNING type */
13961395
JsonFormat*format;/* context item format (JSON/JSONB) */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp