Skip to content

Commit

Permalink
postgresql17-plpgsql_check.spec
Browse files Browse the repository at this point in the history
- add new option constants_tracing (true by default) for controling of possibility to trace constants.
- increase version to 2.6 - API change
  • Loading branch information
okbob committed Oct 31, 2023
1 parent d47c3c6 commit 9384afc
Show file tree
Hide file tree
Showing 17 changed files with 74 additions and 19 deletions.
4 changes: 2 additions & 2 deletions META.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"name": "plpgsql_check",
"abstract": "Additional tools for plpgsql functions validation",
"description": "The plpgsql_check is PostgreSQL extension with functionality for direct or indirect extra validation of functions in plpgsql language. It verifies a validity of SQL identifiers used in plpgsql code. It try to identify a performance issues. Modern versions has integrated profiler. The table and function dependencies can be displayed",
"version": "2.5.4",
"version": "2.6.0",
"maintainer": "Pavel STEHULE <[email protected]>",
"license": "bsd",
"provides": {
"plpgsql_check": {
"abstract": "Additional tools for plpgsql functions validation",
"file": "sql/plpgsql_check_active.sql",
"docfile": "README.md",
"version": "2.5.4"
"version": "2.6.0"
}
},
"prereqs": {
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

MODULE_big = plpgsql_check
OBJS = $(patsubst %.c,%.o,$(wildcard src/*.c))
DATA = plpgsql_check--2.5.sql
DATA = plpgsql_check--2.6.sql
EXTENSION = plpgsql_check

ifndef MAJORVERSION
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ You can set level of warnings via function's parameters:
* `incomment_options_usage_warning DEFAULT false` - when it is true, then the warning is raised when
in-comment option is used.

* `constant_tracing boolean DEFAULT true` - when it is true, then the variable that holds
some constant content, can be used like constant (it is work only in some simple cases,
and the content of variable should not be ambigonuous).

## Triggers

When you want to check any trigger, you have to enter a relation that will be
Expand Down
12 changes: 8 additions & 4 deletions plpgsql_check--2.5.sql → plpgsql_check--2.6.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ CREATE FUNCTION plpgsql_check_function_tb(funcoid regprocedure,
without_warnings boolean DEFAULT false,
all_warnings boolean DEFAULT false,
use_incomment_options boolean DEFAULT true,
incomment_options_usage_warning boolean DEFAULT false)
incomment_options_usage_warning boolean DEFAULT false,
constant_tracing boolean DEFAULT true)
RETURNS TABLE(functionid regproc,
lineno int,
statement text,
Expand Down Expand Up @@ -53,7 +54,8 @@ CREATE FUNCTION plpgsql_check_function(funcoid regprocedure,
without_warnings boolean DEFAULT false,
all_warnings boolean DEFAULT false,
use_incomment_options boolean DEFAULT true,
incomment_options_usage_warning boolean DEFAULT false)
incomment_options_usage_warning boolean DEFAULT false,
constant_tracing boolean DEFAULT true)
RETURNS SETOF text
AS 'MODULE_PATHNAME','plpgsql_check_function'
LANGUAGE C;
Expand All @@ -76,7 +78,8 @@ CREATE FUNCTION plpgsql_check_function_tb(name text,
without_warnings boolean DEFAULT false,
all_warnings boolean DEFAULT false,
use_incomment_options boolean DEFAULT true,
incomment_options_usage_warning boolean DEFAULT false)
incomment_options_usage_warning boolean DEFAULT false,
constant_tracing boolean DEFAULT true)
RETURNS TABLE(functionid regproc,
lineno int,
statement text,
Expand Down Expand Up @@ -110,7 +113,8 @@ CREATE FUNCTION plpgsql_check_function(name text,
without_warnings boolean DEFAULT false,
all_warnings boolean DEFAULT false,
use_incomment_options boolean DEFAULT true,
incomment_options_usage_warning boolean DEFAULT false)
incomment_options_usage_warning boolean DEFAULT false,
constant_tracing boolean DEFAULT true)
RETURNS SETOF text
AS 'MODULE_PATHNAME','plpgsql_check_function_name'
LANGUAGE C;
Expand Down
2 changes: 1 addition & 1 deletion plpgsql_check.control
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# plpgsql_check extension
comment = 'extended check for plpgsql functions'
default_version = '2.5'
default_version = '2.6'
module_pathname = '$libdir/plpgsql_check'
relocatable = false
requires = 'plpgsql'
5 changes: 4 additions & 1 deletion postgresql12-plpgsql_check.spec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
%global sname plpgsql_check

Name: %{sname}_%{pgmajorversion}
Version: 2.5.4
Version: 2.6.0
Release: 1%{?dist}
Summary: Additional tools for plpgsql functions validation

Expand Down Expand Up @@ -49,6 +49,9 @@ rm -rf %{buildroot}
%{pginstdir}/share/extension/*.control

%changelog
* Tue Oct 31 2023 - Pavel Stehule <[email protected]> 2.6.0
- simple constant tracing support

* Sat Apr 29 2023 - Pavel Stehule <[email protected]> 2.4.0
- remove support for PostgreSQL 10 and 11

Expand Down
5 changes: 4 additions & 1 deletion postgresql13-plpgsql_check.spec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
%global sname plpgsql_check

Name: %{sname}_%{pgmajorversion}
Version: 2.5.4
Version: 2.6.0
Release: 1%{?dist}
Summary: Additional tools for plpgsql functions validation

Expand Down Expand Up @@ -49,6 +49,9 @@ rm -rf %{buildroot}
%{pginstdir}/share/extension/*.control

%changelog
* Tue Oct 31 2023 - Pavel Stehule <[email protected]> 2.6.0
- simple constant tracing support

* Sat Apr 29 2023 - Pavel Stehule <[email protected]> 2.4.0
- remove support for PostgreSQL 10 and 11

Expand Down
5 changes: 4 additions & 1 deletion postgresql14-plpgsql_check.spec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
%global sname plpgsql_check

Name: %{sname}_%{pgmajorversion}
Version: 2.5.4
Version: 2.6.0
Release: 1%{?dist}
Summary: Additional tools for plpgsql functions validation

Expand Down Expand Up @@ -49,6 +49,9 @@ rm -rf %{buildroot}
%{pginstdir}/share/extension/*.control

%changelog
* Tue Oct 31 2023 - Pavel Stehule <[email protected]> 2.6.0
- simple constant tracing support

* Sat Apr 29 2023 - Pavel Stehule <[email protected]> 2.4.0
- remove support for PostgreSQL 10 and 11

Expand Down
5 changes: 4 additions & 1 deletion postgresql15-plpgsql_check.spec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
%global sname plpgsql_check

Name: %{sname}_%{pgmajorversion}
Version: 2.5.4
Version: 2.6.0
Release: 1%{?dist}
Summary: Additional tools for plpgsql functions validation

Expand Down Expand Up @@ -49,6 +49,9 @@ rm -rf %{buildroot}
%{pginstdir}/share/extension/*.control

%changelog
* Tue Oct 31 2023 - Pavel Stehule <[email protected]> 2.6.0
- simple constant tracing support

* Sat Apr 29 2023 - Pavel Stehule <[email protected]> 2.4.0
- remove support for PostgreSQL 10 and 11

Expand Down
5 changes: 4 additions & 1 deletion postgresql16-plpgsql_check.spec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
%global sname plpgsql_check

Name: %{sname}_%{pgmajorversion}
Version: 2.5.4
Version: 2.6.0
Release: 1%{?dist}
Summary: Additional tools for plpgsql functions validation

Expand Down Expand Up @@ -49,6 +49,9 @@ rm -rf %{buildroot}
%{pginstdir}/share/extension/*.control

%changelog
* Tue Oct 31 2023 - Pavel Stehule <[email protected]> 2.6.0
- simple constant tracing support

* Sat Apr 29 2023 - Pavel Stehule <[email protected]> 2.4.0
- remove support for PostgreSQL 10 and 11

Expand Down
5 changes: 4 additions & 1 deletion postgresql17-plpgsql_check.spec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
%global sname plpgsql_check

Name: %{sname}_%{pgmajorversion}
Version: 2.5.4
Version: 2.6.0
Release: 1%{?dist}
Summary: Additional tools for plpgsql functions validation

Expand Down Expand Up @@ -49,6 +49,9 @@ rm -rf %{buildroot}
%{pginstdir}/share/extension/*.control

%changelog
* Tue Oct 31 2023 - Pavel Stehule <[email protected]> 2.6.0
- simple constant tracing support

* Sat Apr 29 2023 - Pavel Stehule <[email protected]> 2.4.0
- remove support for PostgreSQL 10 and 11

Expand Down
6 changes: 4 additions & 2 deletions src/check_expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,9 @@ plpgsql_check_get_tracked_const(PLpgSQL_checkstate *cstate, Node *node)
if (!cstate->strconstvars)
return NULL;

if (cstate->pragma_vector.disable_constants_tracing)
return NULL;

if (IsA(node, Param))
{
Param *p = (Param *) node;
Expand Down Expand Up @@ -1386,8 +1389,7 @@ plpgsql_check_expr_as_rvalue(PLpgSQL_checkstate *cstate, PLpgSQL_expr *expr,
}
}

/* constant tracing */
if (/* cstate->cinfo->constant_tracing && */ targetdno != -1)
if (cstate->cinfo->constants_tracing && targetdno != -1)
{
char *str;

Expand Down
3 changes: 3 additions & 0 deletions src/check_function.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ bool plpgsql_check_extra_warnings = false;
bool plpgsql_check_performance_warnings = false;
bool plpgsql_check_compatibility_warnings = false;
bool plpgsql_check_fatal_errors = true;
bool plpgsql_check_constants_tracing = true;
int plpgsql_check_mode = PLPGSQL_CHECK_MODE_BY_FUNCTION;

/* ----------
Expand Down Expand Up @@ -352,6 +353,7 @@ passive_check_func_beg(PLpgSQL_execstate *estate, PLpgSQL_function *func, void *
cinfo.performance_warnings = plpgsql_check_performance_warnings,
cinfo.extra_warnings = plpgsql_check_extra_warnings,
cinfo.compatibility_warnings = plpgsql_check_compatibility_warnings;
cinfo.constants_tracing = plpgsql_check_constants_tracing;

ri.format = PLPGSQL_CHECK_FORMAT_ELOG;

Expand Down Expand Up @@ -1164,6 +1166,7 @@ setup_cstate(PLpgSQL_checkstate *cstate,
cstate->pragma_vector.disable_extra_warnings = false;
cstate->pragma_vector.disable_security_warnings = false;
cstate->pragma_vector.disable_compatibility_warnings = false;
cstate->pragma_vector.disable_constants_tracing = false;

/* try to find oid of plpgsql_check pragma function */
cstate->pragma_foid = plpgsql_check_pragma_func_oid();
Expand Down
10 changes: 9 additions & 1 deletion src/plpgsql_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static bool is_expected_extversion = false;
*/
#define LOAD_EXTERNAL_FUNCTION(file, funcname) ((void *) (load_external_function(file, funcname, true, NULL)))

#define EXPECTED_EXTVERSION "2.5"
#define EXPECTED_EXTVERSION "2.6"

void
plpgsql_check_check_ext_version(Oid fn_oid)
Expand Down Expand Up @@ -237,6 +237,14 @@ _PG_init(void)
PGC_USERSET, 0,
NULL, NULL, NULL);

DefineCustomBoolVariable("plpgsql_check.constants_tracing",
"when is true, the variables with constant value can be used like constant",
NULL,
&plpgsql_check_constants_tracing,
true,
PGC_USERSET, 0,
NULL, NULL, NULL);

DefineCustomBoolVariable("plpgsql_check.fatal_errors",
"when is true, then plpgsql check stops execution on detected error",
NULL,
Expand Down
3 changes: 3 additions & 0 deletions src/plpgsql_check.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ typedef struct plpgsql_check_info
bool extra_warnings;
bool security_warnings;
bool compatibility_warnings;
bool constants_tracing;
bool show_profile;

bool all_warnings;
Expand All @@ -127,6 +128,7 @@ typedef struct
unsigned int disable_extra_warnings : 1;
unsigned int disable_security_warnings : 1;
unsigned int disable_compatibility_warnings : 1;
unsigned int disable_constants_tracing : 1;
} plpgsql_check_pragma_vector;

#define CI_MAGIC 2023042922
Expand Down Expand Up @@ -246,6 +248,7 @@ extern bool plpgsql_check_extra_warnings;
extern bool plpgsql_check_performance_warnings;
extern bool plpgsql_check_compatibility_warnings;
extern bool plpgsql_check_fatal_errors;
extern bool plpgsql_check_constants_tracing;
extern int plpgsql_check_mode;

/*
Expand Down
7 changes: 7 additions & 0 deletions src/pragma.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ pragma_apply(PLpgSQL_checkstate *cstate,
else if (strcasecmp(pragma_str, "COMPATIBILITY_WARNINGS") == 0)
elog(NOTICE, "compatibility_warnings is %s",
pv->disable_compatibility_warnings ? "disabled" : "enabled");
else if (strcasecmp(pragma_str, "CONSTANTS_TRANCING") == 0)
elog(NOTICE, "constants_traising is %s",
pv->disable_constants_tracing ? "disabled" : "enabled");
else
{
elog(WARNING, "unsuported pragma: %s", pragma_str);
Expand Down Expand Up @@ -140,6 +143,8 @@ pragma_apply(PLpgSQL_checkstate *cstate,
pv->disable_security_warnings = false;
else if (strcasecmp(pragma_str, "COMPATIBILITY_WARNINGS") == 0)
pv->disable_compatibility_warnings = false;
else if (strcasecmp(pragma_str, "CONSTANTS_TRACING") == 0)
pv->disable_constants_tracing = false;
else
{
elog(WARNING, "unsuported pragma: %s", pragma_str);
Expand Down Expand Up @@ -167,6 +172,8 @@ pragma_apply(PLpgSQL_checkstate *cstate,
pv->disable_security_warnings = true;
else if (strcasecmp(pragma_str, "COMPATIBILITY_WARNINGS") == 0)
pv->disable_compatibility_warnings = true;
else if (strcasecmp(pragma_str, "CONSTANTS_TRACING") == 0)
pv->disable_constants_tracing = true;
else
elog(WARNING, "unsuported pragma: %s", pragma_str);
}
Expand Down
10 changes: 8 additions & 2 deletions src/tablefunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ check_function_internal(Oid fnoid, FunctionCallInfo fcinfo)

plpgsql_check_check_ext_version(fcinfo->flinfo->fn_oid);

Assert(PG_NARGS() == 20);
Assert(PG_NARGS() == 21);

/* check to see if caller supports us returning a tuplestore */
rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
Expand Down Expand Up @@ -139,6 +139,8 @@ check_function_internal(Oid fnoid, FunctionCallInfo fcinfo)
ERR_NULL_OPTION("use_incomment_options");
if (PG_ARGISNULL(19))
ERR_NULL_OPTION("incomment_options_usage_warning");
if (PG_ARGISNULL(20))
ERR_NULL_OPTION("constants_tracing");

format = plpgsql_check_format_num(text_to_cstring(PG_GETARG_TEXT_PP(2)));

Expand All @@ -153,6 +155,7 @@ check_function_internal(Oid fnoid, FunctionCallInfo fcinfo)
cinfo.compatibility_warnings = PG_GETARG_BOOL(8);

cinfo.incomment_options_usage_warning = PG_GETARG_BOOL(19);
cinfo.constants_tracing = PG_GETARG_BOOL(20);

/* without_warnings */
if (PG_GETARG_BOOL(16))
Expand Down Expand Up @@ -240,7 +243,7 @@ check_function_tb_internal(Oid fnoid, FunctionCallInfo fcinfo)

plpgsql_check_check_ext_version(fcinfo->flinfo->fn_oid);

Assert(PG_NARGS() == 19);
Assert(PG_NARGS() == 20);

/* check to see if caller supports us returning a tuplestore */
rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
Expand Down Expand Up @@ -279,6 +282,8 @@ check_function_tb_internal(Oid fnoid, FunctionCallInfo fcinfo)
ERR_NULL_OPTION("use_incomment_options");
if (PG_ARGISNULL(18))
ERR_NULL_OPTION("incomment_options_usage_warning");
if (PG_ARGISNULL(19))
ERR_NULL_OPTION("constants_tracing");


plpgsql_check_info_init(&cinfo, fnoid);
Expand All @@ -292,6 +297,7 @@ check_function_tb_internal(Oid fnoid, FunctionCallInfo fcinfo)
cinfo.compatibility_warnings = PG_GETARG_BOOL(7);

cinfo.incomment_options_usage_warning = PG_GETARG_BOOL(18);
cinfo.constants_tracing = PG_GETARG_BOOL(19);

/* without_warnings */
if (PG_GETARG_BOOL(15))
Expand Down

0 comments on commit 9384afc

Please sign in to comment.