@@ -2470,32 +2470,38 @@ ExecInitExprRec(Expr *node, ExprState *state,
2470
2470
}
2471
2471
else
2472
2472
{
2473
+ JsonConstructorExprState * jcstate ;
2474
+
2475
+ jcstate = palloc0 (sizeof (JsonConstructorExprState ));
2476
+
2473
2477
scratch .opcode = EEOP_JSON_CONSTRUCTOR ;
2474
- scratch .d .json_constructor .constructor = ctor ;
2475
- scratch .d .json_constructor .arg_values = palloc (sizeof (Datum ) * nargs );
2476
- scratch .d .json_constructor .arg_nulls = palloc (sizeof (bool ) * nargs );
2477
- scratch .d .json_constructor .arg_types = palloc (sizeof (Oid ) * nargs );
2478
- scratch .d .json_constructor .nargs = nargs ;
2478
+ scratch .d .json_constructor .jcstate = jcstate ;
2479
+
2480
+ jcstate -> constructor = ctor ;
2481
+ jcstate -> arg_values = palloc (sizeof (Datum ) * nargs );
2482
+ jcstate -> arg_nulls = palloc (sizeof (bool ) * nargs );
2483
+ jcstate -> arg_types = palloc (sizeof (Oid ) * nargs );
2484
+ jcstate -> nargs = nargs ;
2479
2485
2480
2486
foreach (lc , args )
2481
2487
{
2482
2488
Expr * arg = (Expr * ) lfirst (lc );
2483
2489
2484
- scratch . d . json_constructor . arg_types [argno ] = exprType ((Node * ) arg );
2490
+ jcstate -> arg_types [argno ] = exprType ((Node * ) arg );
2485
2491
2486
2492
if (IsA (arg , Const ))
2487
2493
{
2488
2494
/* Don't evaluate const arguments every round */
2489
2495
Const * con = (Const * ) arg ;
2490
2496
2491
- scratch . d . json_constructor . arg_values [argno ] = con -> constvalue ;
2492
- scratch . d . json_constructor . arg_nulls [argno ] = con -> constisnull ;
2497
+ jcstate -> arg_values [argno ] = con -> constvalue ;
2498
+ jcstate -> arg_nulls [argno ] = con -> constisnull ;
2493
2499
}
2494
2500
else
2495
2501
{
2496
2502
ExecInitExprRec (arg , state ,
2497
- & scratch . d . json_constructor . arg_values [argno ],
2498
- & scratch . d . json_constructor . arg_nulls [argno ]);
2503
+ & jcstate -> arg_values [argno ],
2504
+ & jcstate -> arg_nulls [argno ]);
2499
2505
}
2500
2506
argno ++ ;
2501
2507
}
@@ -2506,14 +2512,14 @@ ExecInitExprRec(Expr *node, ExprState *state,
2506
2512
bool is_jsonb =
2507
2513
ctor -> returning -> format -> format_type == JS_FORMAT_JSONB ;
2508
2514
2509
- scratch . d . json_constructor . arg_type_cache =
2510
- palloc (sizeof (* scratch . d . json_constructor . arg_type_cache ) * nargs );
2515
+ jcstate -> arg_type_cache =
2516
+ palloc (sizeof (* jcstate -> arg_type_cache ) * nargs );
2511
2517
2512
2518
for (int i = 0 ; i < nargs ; i ++ )
2513
2519
{
2514
2520
int category ;
2515
2521
Oid outfuncid ;
2516
- Oid typid = scratch . d . json_constructor . arg_types [i ];
2522
+ Oid typid = jcstate -> arg_types [i ];
2517
2523
2518
2524
if (is_jsonb )
2519
2525
{
@@ -2532,8 +2538,8 @@ ExecInitExprRec(Expr *node, ExprState *state,
2532
2538
category = (int ) jscat ;
2533
2539
}
2534
2540
2535
- scratch . d . json_constructor . arg_type_cache [i ].outfuncid = outfuncid ;
2536
- scratch . d . json_constructor . arg_type_cache [i ].category = category ;
2541
+ jcstate -> arg_type_cache [i ].outfuncid = outfuncid ;
2542
+ jcstate -> arg_type_cache [i ].category = category ;
2537
2543
}
2538
2544
}
2539
2545
@@ -2572,41 +2578,44 @@ ExecInitExprRec(Expr *node, ExprState *state,
2572
2578
case T_JsonExpr :
2573
2579
{
2574
2580
JsonExpr * jexpr = castNode (JsonExpr , node );
2581
+ JsonExprState * jsestate = palloc0 (sizeof (JsonExprState ));
2575
2582
ListCell * argexprlc ;
2576
2583
ListCell * argnamelc ;
2577
2584
2578
2585
scratch .opcode = EEOP_JSONEXPR ;
2579
- scratch .d .jsonexpr .jsexpr = jexpr ;
2586
+ scratch .d .jsonexpr .jsestate = jsestate ;
2587
+
2588
+ jsestate -> jsexpr = jexpr ;
2580
2589
2581
- scratch . d . jsonexpr . formatted_expr =
2582
- palloc (sizeof (* scratch . d . jsonexpr . formatted_expr ));
2590
+ jsestate -> formatted_expr =
2591
+ palloc (sizeof (* jsestate -> formatted_expr ));
2583
2592
2584
2593
ExecInitExprRec ((Expr * ) jexpr -> formatted_expr , state ,
2585
- & scratch . d . jsonexpr . formatted_expr -> value ,
2586
- & scratch . d . jsonexpr . formatted_expr -> isnull );
2594
+ & jsestate -> formatted_expr -> value ,
2595
+ & jsestate -> formatted_expr -> isnull );
2587
2596
2588
- scratch . d . jsonexpr . pathspec =
2589
- palloc (sizeof (* scratch . d . jsonexpr . pathspec ));
2597
+ jsestate -> pathspec =
2598
+ palloc (sizeof (* jsestate -> pathspec ));
2590
2599
2591
2600
ExecInitExprRec ((Expr * ) jexpr -> path_spec , state ,
2592
- & scratch . d . jsonexpr . pathspec -> value ,
2593
- & scratch . d . jsonexpr . pathspec -> isnull );
2601
+ & jsestate -> pathspec -> value ,
2602
+ & jsestate -> pathspec -> isnull );
2594
2603
2595
- scratch . d . jsonexpr . res_expr =
2596
- palloc (sizeof (* scratch . d . jsonexpr . res_expr ));
2604
+ jsestate -> res_expr =
2605
+ palloc (sizeof (* jsestate -> res_expr ));
2597
2606
2598
- scratch . d . jsonexpr . result_expr = jexpr -> result_coercion
2607
+ jsestate -> result_expr = jexpr -> result_coercion
2599
2608
? ExecInitExprWithCaseValue ((Expr * ) jexpr -> result_coercion -> expr ,
2600
2609
state -> parent ,
2601
- & scratch . d . jsonexpr . res_expr -> value ,
2602
- & scratch . d . jsonexpr . res_expr -> isnull )
2610
+ & jsestate -> res_expr -> value ,
2611
+ & jsestate -> res_expr -> isnull )
2603
2612
: NULL ;
2604
2613
2605
- scratch . d . jsonexpr . default_on_empty = !jexpr -> on_empty ? NULL :
2614
+ jsestate -> default_on_empty = !jexpr -> on_empty ? NULL :
2606
2615
ExecInitExpr ((Expr * ) jexpr -> on_empty -> default_expr ,
2607
2616
state -> parent );
2608
2617
2609
- scratch . d . jsonexpr . default_on_error =
2618
+ jsestate -> default_on_error =
2610
2619
ExecInitExpr ((Expr * ) jexpr -> on_error -> default_expr ,
2611
2620
state -> parent );
2612
2621
@@ -2617,11 +2626,11 @@ ExecInitExprRec(Expr *node, ExprState *state,
2617
2626
2618
2627
/* lookup the result type's input function */
2619
2628
getTypeInputInfo (jexpr -> returning -> typid , & typinput ,
2620
- & scratch . d . jsonexpr . input .typioparam );
2621
- fmgr_info (typinput , & scratch . d . jsonexpr . input .func );
2629
+ & jsestate -> input .typioparam );
2630
+ fmgr_info (typinput , & jsestate -> input .func );
2622
2631
}
2623
2632
2624
- scratch . d . jsonexpr . args = NIL ;
2633
+ jsestate -> args = NIL ;
2625
2634
2626
2635
forboth (argexprlc , jexpr -> passing_values ,
2627
2636
argnamelc , jexpr -> passing_names )
@@ -2640,11 +2649,11 @@ ExecInitExprRec(Expr *node, ExprState *state,
2640
2649
var -> value = (Datum ) 0 ;
2641
2650
var -> isnull = true;
2642
2651
2643
- scratch . d . jsonexpr . args =
2644
- lappend (scratch . d . jsonexpr . args , var );
2652
+ jsestate -> args =
2653
+ lappend (jsestate -> args , var );
2645
2654
}
2646
2655
2647
- scratch . d . jsonexpr . cache = NULL ;
2656
+ jsestate -> cache = NULL ;
2648
2657
2649
2658
if (jexpr -> coercions )
2650
2659
{
@@ -2653,13 +2662,13 @@ ExecInitExprRec(Expr *node, ExprState *state,
2653
2662
Datum * caseval ;
2654
2663
bool * casenull ;
2655
2664
2656
- scratch . d . jsonexpr . coercion_expr =
2657
- palloc (sizeof (* scratch . d . jsonexpr . coercion_expr ));
2665
+ jsestate -> coercion_expr =
2666
+ palloc (sizeof (* jsestate -> coercion_expr ));
2658
2667
2659
- caseval = & scratch . d . jsonexpr . coercion_expr -> value ;
2660
- casenull = & scratch . d . jsonexpr . coercion_expr -> isnull ;
2668
+ caseval = & jsestate -> coercion_expr -> value ;
2669
+ casenull = & jsestate -> coercion_expr -> isnull ;
2661
2670
2662
- for (cstate = & scratch . d . jsonexpr . coercions .null ,
2671
+ for (cstate = & jsestate -> coercions .null ,
2663
2672
coercion = & jexpr -> coercions -> null ;
2664
2673
coercion <= & jexpr -> coercions -> composite ;
2665
2674
coercion ++ , cstate ++ )
0 commit comments