@@ -3049,6 +3049,27 @@ chooseScript(TState *thread)
3049
3049
return i - 1 ;
3050
3050
}
3051
3051
3052
+ /*
3053
+ * Allocate space for CState->prepared: we need one boolean for each command
3054
+ * of each script.
3055
+ */
3056
+ static void
3057
+ allocCStatePrepared (CState * st )
3058
+ {
3059
+ Assert (st -> prepared == NULL );
3060
+
3061
+ st -> prepared = pg_malloc (sizeof (bool * ) * num_scripts );
3062
+ for (int i = 0 ; i < num_scripts ; i ++ )
3063
+ {
3064
+ ParsedScript * script = & sql_script [i ];
3065
+ int numcmds ;
3066
+
3067
+ for (numcmds = 0 ; script -> commands [numcmds ] != NULL ; numcmds ++ )
3068
+ ;
3069
+ st -> prepared [i ] = pg_malloc0 (sizeof (bool ) * numcmds );
3070
+ }
3071
+ }
3072
+
3052
3073
/*
3053
3074
* Prepare the SQL command from st->use_file at command_num.
3054
3075
*/
@@ -3061,23 +3082,8 @@ prepareCommand(CState *st, int command_num)
3061
3082
if (command -> type != SQL_COMMAND )
3062
3083
return ;
3063
3084
3064
- /*
3065
- * If not already done, allocate space for 'prepared' flags: one boolean
3066
- * for each command of each script.
3067
- */
3068
3085
if (!st -> prepared )
3069
- {
3070
- st -> prepared = pg_malloc (sizeof (bool * ) * num_scripts );
3071
- for (int i = 0 ; i < num_scripts ; i ++ )
3072
- {
3073
- ParsedScript * script = & sql_script [i ];
3074
- int numcmds ;
3075
-
3076
- for (numcmds = 0 ; script -> commands [numcmds ] != NULL ; numcmds ++ )
3077
- ;
3078
- st -> prepared [i ] = pg_malloc0 (sizeof (bool ) * numcmds );
3079
- }
3080
- }
3086
+ allocCStatePrepared (st );
3081
3087
3082
3088
if (!st -> prepared [st -> use_file ][command_num ])
3083
3089
{
@@ -3109,13 +3115,15 @@ prepareCommandsInPipeline(CState *st)
3109
3115
Assert (commands [st -> command ]-> type == META_COMMAND &&
3110
3116
commands [st -> command ]-> meta == META_STARTPIPELINE );
3111
3117
3118
+ if (!st -> prepared )
3119
+ allocCStatePrepared (st );
3120
+
3112
3121
/*
3113
3122
* We set the 'prepared' flag on the \startpipeline itself to flag that we
3114
3123
* don't need to do this next time without calling prepareCommand(), even
3115
3124
* though we don't actually prepare this command.
3116
3125
*/
3117
- if (st -> prepared &&
3118
- st -> prepared [st -> use_file ][st -> command ])
3126
+ if (st -> prepared [st -> use_file ][st -> command ])
3119
3127
return ;
3120
3128
3121
3129
for (j = st -> command + 1 ; commands [j ] != NULL ; j ++ )
0 commit comments