diff --git a/src/common/backend/catalog/gs_package.cpp b/src/common/backend/catalog/gs_package.cpp index b3ac24d585a8a867e7ce6d15b2189e2bd55c651e..553066b9f82427b34ac1f411cd31fdc343b83c75 100644 --- a/src/common/backend/catalog/gs_package.cpp +++ b/src/common/backend/catalog/gs_package.cpp @@ -493,6 +493,9 @@ Oid PackageBodyCreate(Oid pkgNamespace, const char* pkgName, const Oid ownerId, } oldPkgOid = PackageNameGetOid(pkgName, pkgNamespace); if (!OidIsValid(oldPkgOid)) { +#ifndef ENABLE_MULTIPLE_NODES + InsertGsSource(oldPkgOid, pkgNamespace, pkgName, "package body", false); +#endif ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("package spec not found"))); } /* initialize nulls and values */ diff --git a/src/common/backend/parser/scan.l b/src/common/backend/parser/scan.l index 140090c7a87c5af0636fb332706a504d0ac353d6..94813de5c98acae08101f7b66cf927f731c77b50 100755 --- a/src/common/backend/parser/scan.l +++ b/src/common/backend/parser/scan.l @@ -1269,12 +1269,13 @@ void scanner_yyerror(const char *message, core_yyscan_t yyscanner) { const char *loc = yyextra->scanbuf + *yylloc; - u_sess->plsql_cxt.have_error = true; + u_sess->plsql_cxt.have_error = true; int errstate = 0; int lines = 0; int rc = CompileWhich(); #ifndef ENABLE_MULTIPLE_NODES - if (rc != PLPGSQL_COMPILE_NULL && u_sess->attr.attr_common.plsql_show_all_error) { + if (rc != PLPGSQL_COMPILE_NULL && u_sess->attr.attr_common.plsql_show_all_error + && t_thrd.log_cxt.errordata_stack_depth <= ERRORDATA_STACK_SIZE - 2) { lines = GetProcedureLineNumberInPackage(u_sess->plsql_cxt.curr_compile_context->core_yy->scanbuf, u_sess->plsql_cxt.plpgsql_yylloc); addErrorList(message, lines); } diff --git a/src/common/pl/plpgsql/src/pl_handler.cpp b/src/common/pl/plpgsql/src/pl_handler.cpp index ab08a4cd3fe2d489e552b867fe0dd4e4c7953a64..763f6c2dd74fc20f8b02642fa4046a1b7d1606b4 100755 --- a/src/common/pl/plpgsql/src/pl_handler.cpp +++ b/src/common/pl/plpgsql/src/pl_handler.cpp @@ -137,7 +137,7 @@ void InsertGsSource(Oid objId, Oid nspid, const char* name, const char* type, bo bool notInsert = u_sess->attr.attr_common.upgrade_mode != 0 || IsSystemNamespace(nspid) || IsToastNamespace(nspid) || IsCStoreNamespace(nspid) || IsPackageSchemaOid(nspid) || SKIP_GS_SOURCE; - if (notInsert) { + if (notInsert || t_thrd.log_cxt.errordata_stack_depth > ERRORDATA_STACK_SIZE - 2) { return; } if (g_instance.attr.attr_storage.max_concurrent_autonomous_transactions <= 0) { @@ -1446,10 +1446,7 @@ PLpgSQL_package* plpgsql_package_validator(Oid packageOid, bool isSpec, bool isC PG_CATCH(); { #ifndef ENABLE_MULTIPLE_NODES - bool insertError = (u_sess->attr.attr_common.plsql_show_all_error || - !u_sess->attr.attr_sql.check_function_bodies) && - isCreate; - if (insertError) { + if (isCreate) { SPI_STACK_LOG("finish", NULL, NULL); SPI_finish(); if (!IsInitdb) { diff --git a/src/gausskernel/optimizer/commands/functioncmds.cpp b/src/gausskernel/optimizer/commands/functioncmds.cpp index 26954bfad6d5b2a68b315004ca4793f1ca89d952..088e1711c339597be282dfd5e042b9ae9adab2ed 100644 --- a/src/gausskernel/optimizer/commands/functioncmds.cpp +++ b/src/gausskernel/optimizer/commands/functioncmds.cpp @@ -1650,6 +1650,14 @@ void RemovePackageById(Oid pkgOid, bool isBody) DropErrorByOid(PLPGSQL_PACKAGE, pkgOid); simple_heap_delete(relation, &pkgtup->t_self); } else { + bool isNull = false; + SysCacheGetAttr(PACKAGEOID, pkgtup, Anum_gs_package_pkgbodydeclsrc, &isNull); + if (isNull) { + DropErrorByOid(PLPGSQL_PACKAGE_BODY, pkgOid); + ReleaseSysCache(pkgtup); + heap_close(relation, RowExclusiveLock); + return; + } bool nulls[Natts_gs_package]; Datum values[Natts_gs_package]; bool replaces[Natts_gs_package]; diff --git a/src/test/regress/expected/pldeveloper_gs_source.out b/src/test/regress/expected/pldeveloper_gs_source.out index 26b72e4dfcb49807cfe01466b779786ef661f78e..617c97c19e8d67f2a946fbba81c00c66793f92be 100644 --- a/src/test/regress/expected/pldeveloper_gs_source.out +++ b/src/test/regress/expected/pldeveloper_gs_source.out @@ -676,7 +676,7 @@ QUERY: PACKAGE DECLARE a a; end CONTEXT: compilation of PL/pgSQL package near line 2 -select name,type,status,src from DBE_PLDEVELOPER.gs_source order by name; +select name,type,status,src from DBE_PLDEVELOPER.gs_source order by name,type; name | type | status | src --------------+--------------+--------+--------------------------------------------------------------------------------- bulk_f_039_1 | function | t | create or replace function bulk_f_039_1() returns int[] + @@ -689,6 +689,11 @@ select name,type,status,src from DBE_PLDEVELOPER.gs_source order by name; | | | return var1; + | | | end; + | | | $$; + error2 | package | t | CREATE OR REPLACE PACKAGE error2 IS + + | | | a int;b int; + + | | | FUNCTION func1(a in int, b inout int, c out int) return int; + + | | | FUNCTION func2(a in int, b inout int, c out int) return int; + + | | | END error2; error2 | package body | f | CREATE OR REPLACE PACKAGE BODY error2 IS + | | | FUNCTION func1 (a in int, b inout int c out int) return int + | | | IS + @@ -706,21 +711,11 @@ select name,type,status,src from DBE_PLDEVELOPER.gs_source order by name; | | | RETURN(a1 + a + b); + | | | END; + | | | END error2; - error2 | package | t | CREATE OR REPLACE PACKAGE error2 IS + - | | | a int;b int; + - | | | FUNCTION func1(a in int, b inout int, c out int) return int; + - | | | FUNCTION func2(a in int, b inout int, c out int) return int; + - | | | END error2; func00 | procedure | t | create or replace procedure func00 + | | | is + | | | begin + | | | create role yyy password '********'; + | | | end; - func1 | procedure | f | create or replace procedure func1 + - | | | is + - | | | begin + - | | | insert into fasd af asd asdf; + - | | | end; func1 | function | f | create function func1() returns boolean as $$ declare + | | | sql_temp text; + | | | begin + @@ -729,6 +724,11 @@ select name,type,status,src from DBE_PLDEVELOPER.gs_source order by name; | | | return true; + | | | end; + | | | $$ language plpgsql; + func1 | procedure | f | create or replace procedure func1 + + | | | is + + | | | begin + + | | | insert into fasd af asd asdf; + + | | | end; mask | procedure | t | create or replace procedure mask + | | | is + | | | begin + @@ -752,6 +752,10 @@ select name,type,status,src from DBE_PLDEVELOPER.gs_source order by name; | | | a inv%d; + | | | procedure proc1(c ff%F); + | | | end pkg2; + pkg3 | package | t | create or replace package pkg3 + + | | | is + + | | | a int; + + | | | end pkg3; pkg3 | package body | f | create or replace package body pkg3 + | | | is + | | | a b c d; + @@ -761,10 +765,6 @@ select name,type,status,src from DBE_PLDEVELOPER.gs_source order by name; | | | insert int asd asd; + | | | end; + | | | end pkg3; - pkg3 | package | t | create or replace package pkg3 + - | | | is + - | | | a int; + - | | | end pkg3; pkg4 | package | f | create or replace package pkg4 + | | | is + | | | a a; + @@ -914,7 +914,7 @@ set check_function_bodies to off; create or replace procedure test1 is begin null; end; / set check_function_bodies to on; -select name,type,status,src from DBE_PLDEVELOPER.gs_source order by name; +select name,type,status,src from DBE_PLDEVELOPER.gs_source order by name,type; name | type | status | src --------------+--------------+--------+--------------------------------------------------------------------------------- bulk_f_039_1 | function | t | create or replace function bulk_f_039_1() returns int[] + @@ -927,6 +927,11 @@ select name,type,status,src from DBE_PLDEVELOPER.gs_source order by name; | | | return var1; + | | | end; + | | | $$; + error2 | package | t | CREATE OR REPLACE PACKAGE error2 IS + + | | | a int;b int; + + | | | FUNCTION func1(a in int, b inout int, c out int) return int; + + | | | FUNCTION func2(a in int, b inout int, c out int) return int; + + | | | END error2; error2 | package body | f | CREATE OR REPLACE PACKAGE BODY error2 IS + | | | FUNCTION func1 (a in int, b inout int c out int) return int + | | | IS + @@ -944,11 +949,6 @@ select name,type,status,src from DBE_PLDEVELOPER.gs_source order by name; | | | RETURN(a1 + a + b); + | | | END; + | | | END error2; - error2 | package | t | CREATE OR REPLACE PACKAGE error2 IS + - | | | a int;b int; + - | | | FUNCTION func1(a in int, b inout int, c out int) return int; + - | | | FUNCTION func2(a in int, b inout int, c out int) return int; + - | | | END error2; func00 | procedure | t | create or replace procedure func00 + | | | is + | | | begin + @@ -981,6 +981,10 @@ select name,type,status,src from DBE_PLDEVELOPER.gs_source order by name; | | | insert into test1 values(1); + | | | insert int asd asd; + | | | end; + pack3 | package | f | create or replace package pack3 is + + | | | array_v1 pack1.array_type1; + + | | | procedure pp1(); + + | | | end pack3; pkg1 | package | f | create or replace package pkg1 + | | | is + | | | procedure proc1(c ff%F); + @@ -990,6 +994,10 @@ select name,type,status,src from DBE_PLDEVELOPER.gs_source order by name; | | | a inv%d; + | | | procedure proc1(c ff%F); + | | | end pkg2; + pkg3 | package | t | create or replace package pkg3 + + | | | is + + | | | a int; + + | | | end pkg3; pkg3 | package body | f | create or replace package body pkg3 + | | | is + | | | a b c d; + @@ -999,14 +1007,14 @@ select name,type,status,src from DBE_PLDEVELOPER.gs_source order by name; | | | insert int asd asd; + | | | end; + | | | end pkg3; - pkg3 | package | t | create or replace package pkg3 + - | | | is + - | | | a int; + - | | | end pkg3; pkg4 | package | f | create or replace package pkg4 + | | | is + | | | a a; + | | | end pkg4; + pkg5 | package | f | create or replace package pkg5 + + | | | is + + | | | a a; + + | | | end pkg5; pro25 | procedure | f | create or replace procedure pro25 + | | | as + | | | type tpc1 is ref cursor; + @@ -1039,7 +1047,6 @@ select name,type,status,src from DBE_PLDEVELOPER.gs_source order by name; | | | begin + | | | insert int a; + | | | end; - test1 | procedure | t | create or replace procedure test1 is begin null; end; test1 | function | f | create or replace function test1(aa int) return arrytype + | | | is + | | | begin + @@ -1050,31 +1057,31 @@ select name,type,status,src from DBE_PLDEVELOPER.gs_source order by name; | | | begin + | | | return null; + | | | end; + test1 | procedure | t | create or replace procedure test1 is begin null; end; test2 | function | t | create or replace function test2(aa int) return int + | | | is + | | | begin + | | | a a; + | | | return arrytype; + | | | end; -(22 rows) +(24 rows) -select name,type,line,src from DBE_PLDEVELOPER.gs_errors order by name; +select name,type,line,src from DBE_PLDEVELOPER.gs_errors order by name,type; name | type | line | src ------------+--------------+------+--------------------------------------- emp_bonus9 | package body | 6 | syntax error - error2 | package body | 2 | syntax error error2 | package body | 9 | missing data type declaration + error2 | package body | 2 | syntax error func1 | procedure | 4 | syntax error func2 | function | 4 | it is not a known variable func2 | function | 4 | syntax error - p1 | procedure | 5 | unrecognized row security option p1 | procedure | 5 | relation "account_row" does not exist + p1 | procedure | 5 | unrecognized row security option pkg1 | package | 3 | syntax error pkg2 | package | 3 | invalid type name - pkg4 | package | 3 | type does not exist pro25 | procedure | 6 | it is not a known variable pro71 | procedure | 2 | column "pro70" has pseudo-type void -(13 rows) +(12 rows) drop package if exists pkg4; NOTICE: package pkg4() does not exist, skipping @@ -1160,6 +1167,10 @@ select rolname, name, status, type, src from DBE_PLDEVELOPER.gs_source s join pg | | | | insert into test1 values(1); + | | | | insert int asd asd; + | | | | end; + gs_developper | pack3 | f | package | create or replace package pack3 is + + | | | | array_v1 pack1.array_type1; + + | | | | procedure pp1(); + + | | | | end pack3; gs_developper | pkg1 | f | package | create or replace package pkg1 + | | | | is + | | | | procedure proc1(c ff%F); + @@ -1173,6 +1184,10 @@ select rolname, name, status, type, src from DBE_PLDEVELOPER.gs_source s join pg | | | | is + | | | | a a; + | | | | end pkg4; + gs_developper | pkg5 | f | package | create or replace package pkg5 + + | | | | is + + | | | | a a; + + | | | | end pkg5; gs_developper | pro25 | f | procedure | create or replace procedure pro25 + | | | | as + | | | | type tpc1 is ref cursor; + @@ -1222,7 +1237,7 @@ select rolname, name, status, type, src from DBE_PLDEVELOPER.gs_source s join pg | | | | a a; + | | | | return arrytype; + | | | | end; -(20 rows) +(22 rows) truncate DBE_PLDEVELOPER.gs_source; truncate DBE_PLDEVELOPER.gs_errors; diff --git a/src/test/regress/expected/plsql_show_all_error.out b/src/test/regress/expected/plsql_show_all_error.out index f342e073922c16e70cf35f0f278295d17be39385..dab1436cf79518eab73b3a683e7c71219d60a4fe 100644 --- a/src/test/regress/expected/plsql_show_all_error.out +++ b/src/test/regress/expected/plsql_show_all_error.out @@ -1834,3 +1834,38 @@ select count(*) from dbe_pldeveloper.gs_errors; (1 row) set plsql_show_all_error to off; +delete from DBE_PLDEVELOPER.gs_source; +create package pac_1139606 is +procedure pro_1139606(); +function fun_1139606(); +end pac_1139606; +/ +ERROR: syntax error at or near "BEGIN" +LINE 4: end pac_1139606; + ^ +CONTEXT: compilation of PL/pgSQL package near line 1 +select name, status, src from DBE_PLDEVELOPER.gs_source; + name | status | src +-------------+--------+------------------------------- + pac_1139606 | f | create package pac_1139606 is+ + | | procedure pro_1139606(); + + | | function fun_1139606(); + + | | end pac_1139606; +(1 row) + +delete from DBE_PLDEVELOPER.gs_source; +create package pac_1139606 is +procedure pro_1139606(); +end pac_1139606; +/ +select name, status, src from DBE_PLDEVELOPER.gs_source; + name | status | src +-------------+--------+------------------------------- + pac_1139606 | t | create package pac_1139606 is+ + | | procedure pro_1139606(); + + | | end pac_1139606; +(1 row) + +delete from DBE_PLDEVELOPER.gs_source; +drop package pac_1139606; +NOTICE: drop cascades to function public.pro_1139606() diff --git a/src/test/regress/sql/pldeveloper_gs_source.sql b/src/test/regress/sql/pldeveloper_gs_source.sql index d67b7e5cd2c1bc7ffe337bab81c12978cd57dd38..26aec0b058846c7e1bc6924078488eb59b3c651f 100644 --- a/src/test/regress/sql/pldeveloper_gs_source.sql +++ b/src/test/regress/sql/pldeveloper_gs_source.sql @@ -257,7 +257,7 @@ is a a; end pkg4; / -select name,type,status,src from DBE_PLDEVELOPER.gs_source order by name; +select name,type,status,src from DBE_PLDEVELOPER.gs_source order by name,type; create or replace procedure proc5 is b int; @@ -312,8 +312,8 @@ set check_function_bodies to off; create or replace procedure test1 is begin null; end; / set check_function_bodies to on; -select name,type,status,src from DBE_PLDEVELOPER.gs_source order by name; -select name,type,line,src from DBE_PLDEVELOPER.gs_errors order by name; +select name,type,status,src from DBE_PLDEVELOPER.gs_source order by name,type; +select name,type,line,src from DBE_PLDEVELOPER.gs_errors order by name,type; drop package if exists pkg4; drop package if exists pkg5; drop function if exists proc4; diff --git a/src/test/regress/sql/plsql_show_all_error.sql b/src/test/regress/sql/plsql_show_all_error.sql index 2cab9db60654a1d2e7fa15e003f0a2ff79968117..2ecddba02220ac2069f32bc02a0d5a80b4bee7e6 100644 --- a/src/test/regress/sql/plsql_show_all_error.sql +++ b/src/test/regress/sql/plsql_show_all_error.sql @@ -1190,3 +1190,20 @@ end; select count(*) from dbe_pldeveloper.gs_errors; set plsql_show_all_error to off; + +delete from DBE_PLDEVELOPER.gs_source; +create package pac_1139606 is +procedure pro_1139606(); +function fun_1139606(); +end pac_1139606; +/ +select name, status, src from DBE_PLDEVELOPER.gs_source; +delete from DBE_PLDEVELOPER.gs_source; + +create package pac_1139606 is +procedure pro_1139606(); +end pac_1139606; +/ +select name, status, src from DBE_PLDEVELOPER.gs_source; +delete from DBE_PLDEVELOPER.gs_source; +drop package pac_1139606;