From 7d485a13e643958376eee38fd48bb595a3a5eb99 Mon Sep 17 00:00:00 2001 From: Kushaal Shroff <51415286+KushaalShroff@users.noreply.github.com> Date: Wed, 18 Dec 2024 11:13:11 +0530 Subject: [PATCH] Fix error handling for already created functions that could give syntax error in newer releases (#3247) Our code assumes that function once created will never give syntax error. But certain fixes like 5251e4a where we disallow declaring reserved @@var, functions could have been created in earlier releases which will give syntax error while executing on a version with this commit. While throwing this syntax error at time of execution of function we have not cleaned up the contexts and aborted well which leads to a crash while executing a subsequent query. To fix this we call terminate_batch for compile errors when we get parser syntax error. In this PR We were crashing due to this in this action and by adding this commit we are not crashing anymore. Issues Resolved BABEL-5455 Signed-Off-By: Kushaal Shroff --- contrib/babelfishpg_tsql/src/pl_handler.c | 7 ++++++- test/JDBC/input/database_metadata.txt | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/contrib/babelfishpg_tsql/src/pl_handler.c b/contrib/babelfishpg_tsql/src/pl_handler.c index 980e277f7a..15d09299dc 100644 --- a/contrib/babelfishpg_tsql/src/pl_handler.c +++ b/contrib/babelfishpg_tsql/src/pl_handler.c @@ -5296,7 +5296,7 @@ Datum pltsql_call_handler(PG_FUNCTION_ARGS) { bool nonatomic; - PLtsql_function *func; + PLtsql_function *func = NULL; PLtsql_execstate *save_cur_estate; Datum retval; int rc; @@ -5417,6 +5417,11 @@ pltsql_call_handler(PG_FUNCTION_ARGS) PG_FINALLY(); { sql_dialect = saved_dialect; + + /* If func is NULL then we have encountered a parser error. */ + if (!func) + terminate_batch(true /* send_error */ , true /* compile_error */ , current_spi_stack_depth); + } PG_END_TRY(); diff --git a/test/JDBC/input/database_metadata.txt b/test/JDBC/input/database_metadata.txt index 0beb77960a..fb6a35c93a 100644 --- a/test/JDBC/input/database_metadata.txt +++ b/test/JDBC/input/database_metadata.txt @@ -1,3 +1,4 @@ +-- sla 120000 -- sla_for_parallel_query_enforced 200000 create table dbmeta_tab1(col1 int primary key, col2 nvarchar(max) not null)