@@ -40,6 +40,7 @@ static void check_fishy_qual(PLpgSQL_checkstate *cstate, CachedPlan *cplan, char
4040static Const * expr_get_const (PLpgSQL_checkstate * cstate , PLpgSQL_expr * expr );
4141static bool is_const_null_expr (PLpgSQL_checkstate * cstate , PLpgSQL_expr * expr );
4242static void force_plan_checks (PLpgSQL_checkstate * cstate , PLpgSQL_expr * expr );
43+ static bool is_pure_expr (PLpgSQL_checkstate * cstate , Query * query );
4344
4445static int RowGetValidFields (PLpgSQL_row * row );
4546static int TupleDescNVatts (TupleDesc tupdesc );
@@ -248,7 +249,7 @@ prepare_plan(PLpgSQL_checkstate *cstate,
248249 int cursorOptions ,
249250 ParserSetupHook parser_setup ,
250251 void * arg ,
251- bool pure_expr_check )
252+ bool is_expression )
252253{
253254 Query * query ;
254255 CachedPlanSource * plansource = NULL ;
@@ -273,8 +274,47 @@ prepare_plan(PLpgSQL_checkstate *cstate,
273274 collect_volatility (cstate , query );
274275 plpgsql_check_detect_dependency (cstate , query );
275276
276- if (pure_expr_check )
277+ if (is_expression )
277278 check_pure_expr (cstate , query , expr -> query );
279+ else
280+ {
281+ if (cstate -> estate && cstate -> cinfo -> performance_warnings )
282+ {
283+ PLpgSQL_stmt * stmt = cstate -> estate -> err_stmt ;
284+
285+ if (stmt )
286+ {
287+ bool have_into = false;
288+ PLpgSQL_variable * target ;
289+
290+ if (stmt -> cmd_type == PLPGSQL_STMT_EXECSQL )
291+ {
292+ have_into = ((PLpgSQL_stmt_execsql * ) stmt )-> into ;
293+ target = ((PLpgSQL_stmt_execsql * ) stmt )-> target ;
294+
295+ if (have_into && target -> dtype == PLPGSQL_DTYPE_ROW )
296+ {
297+ PLpgSQL_row * row = (PLpgSQL_row * ) target ;
298+
299+ if (row -> nfields == 1 &&
300+ plpgsql_check_is_internal_variable (cstate , target ))
301+ {
302+ if (is_pure_expr (cstate , query ))
303+ {
304+ plpgsql_check_put_error (cstate ,
305+ 0 , 0 ,
306+ "detected \"SELECT expr INTO variable\"" ,
307+ "This obsolete syntax of assigning can be slow." ,
308+ "Use syntax \"variable := expr\" instead." ,
309+ PLPGSQL_CHECK_WARNING_PERFORMANCE ,
310+ 0 , expr -> query , NULL );
311+ }
312+ }
313+ }
314+ }
315+ }
316+ }
317+ }
278318}
279319
280320/*
0 commit comments