Skip to content

Commit 3c4f813

Browse files
committed
reduce false alarms
1 parent 72bfcef commit 3c4f813

File tree

4 files changed

+70
-1
lines changed

4 files changed

+70
-1
lines changed

expected/plpgsql_check_active-16.out

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,3 +601,32 @@ select * from plpgsql_check_function('f1');
601601
------------------------
602602
(0 rows)
603603

604+
drop function f1();
605+
-- do not raise false warning
606+
create or replace function test_function()
607+
returns text as $$
608+
declare s text;
609+
begin
610+
get diagnostics s = PG_CONTEXT;
611+
return s;
612+
end;
613+
$$ language plpgsql;
614+
create or replace procedure test_procedure()
615+
as $$
616+
begin
617+
null;
618+
end;
619+
$$ language plpgsql;
620+
-- should be without any warnings
621+
select * from plpgsql_check_function('test_function', performance_warnings=>true);
622+
plpgsql_check_function
623+
------------------------
624+
(0 rows)
625+
626+
select * from plpgsql_check_function('test_procedure', performance_warnings=>true);
627+
plpgsql_check_function
628+
------------------------
629+
(0 rows)
630+
631+
drop function test_function();
632+
drop procedure test_procedure();

sql/plpgsql_check_active-16.sql

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,3 +372,29 @@ $$ language plpgsql;
372372

373373
-- should be ok
374374
select * from plpgsql_check_function('f1');
375+
376+
drop function f1();
377+
378+
-- do not raise false warning
379+
create or replace function test_function()
380+
returns text as $$
381+
declare s text;
382+
begin
383+
get diagnostics s = PG_CONTEXT;
384+
return s;
385+
end;
386+
$$ language plpgsql;
387+
388+
create or replace procedure test_procedure()
389+
as $$
390+
begin
391+
null;
392+
end;
393+
$$ language plpgsql;
394+
395+
-- should be without any warnings
396+
select * from plpgsql_check_function('test_function', performance_warnings=>true);
397+
select * from plpgsql_check_function('test_procedure', performance_warnings=>true);
398+
399+
drop function test_function();
400+
drop procedure test_procedure();

src/check_function.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,8 @@ setup_cstate(PLpgSQL_checkstate *cstate,
12341234

12351235
#endif
12361236

1237-
plpgsql_check_is_eventtriggeroid(cinfo->rettype));
1237+
plpgsql_check_is_eventtriggeroid(cinfo->rettype) ||
1238+
cinfo->is_procedure);
12381239
cstate->estate = NULL;
12391240
cstate->result_info = result_info;
12401241
cstate->cinfo = cinfo;

src/stmtwalk.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#include "access/tupconvert.h"
1515
#include "catalog/pg_collation.h"
16+
#include "catalog/pg_proc.h"
1617
#include "catalog/pg_type.h"
1718
#include "nodes/nodeFuncs.h"
1819
#include "nodes/value.h"
@@ -1237,6 +1238,18 @@ plpgsql_check_stmt(PLpgSQL_checkstate *cstate, PLpgSQL_stmt *stmt, int *closing,
12371238
PLpgSQL_diag_item *diag_item = (PLpgSQL_diag_item *) lfirst(lc);
12381239

12391240
plpgsql_check_target(cstate, diag_item->target, NULL, NULL);
1241+
1242+
/*
1243+
* Using GET DIAGNOSTICS stack = PG_CONTEXT is like using
1244+
* other VOLATILE function.
1245+
*/
1246+
if (!cstate->skip_volatility_check &&
1247+
cstate->cinfo->performance_warnings &&
1248+
!stmt_getdiag->is_stacked)
1249+
{
1250+
if (diag_item->kind == PLPGSQL_GETDIAG_CONTEXT)
1251+
cstate->volatility = PROVOLATILE_VOLATILE;
1252+
}
12401253
}
12411254

12421255
if (stmt_getdiag->is_stacked &&

0 commit comments

Comments
 (0)