Skip to content

Commit

Permalink
Fix error handling for already created functions that could give synt…
Browse files Browse the repository at this point in the history
…ax 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 <[email protected]>
  • Loading branch information
KushaalShroff authored Dec 18, 2024
1 parent f756df1 commit 7d485a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion contrib/babelfishpg_tsql/src/pl_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down
1 change: 1 addition & 0 deletions test/JDBC/input/database_metadata.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit 7d485a1

Please sign in to comment.