Skip to content

Commit dd7a090

Browse files
obdevwyfanxiaoLINxiansheng
authored andcommitted
pass secondary_namespace to PLPrepareCtx in spi_parse_prepare to avoid crash on trigger referencing dropped column
Co-authored-by: wyfanxiao <wyfanxiao@163.com> Co-authored-by: LINxiansheng <wangzelin19961202@gmail.com>
1 parent e75cbf0 commit dd7a090

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/sql/ob_spi.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "sql/engine/expr/ob_expr_pl_integer_checker.h"
2727
#include "sql/engine/expr/ob_expr_lob_utils.h"
2828
#include "pl/ob_pl_package.h"
29+
#include "share/schema/ob_trigger_info.h"
2930
#include "sql/engine/expr/ob_expr_obj_access.h"
3031
#include "pl/ob_pl_exception_handling.h"
3132
#include "sql/dblink/ob_tm_service.h"
@@ -2081,7 +2082,16 @@ int ObSPIService::spi_parse_prepare(common::ObIAllocator &allocator,
20812082
} else if (OB_FAIL(ob_write_string(allocator, ObString(parse_result.no_param_sql_len_, parse_result.no_param_sql_), prepare_result.route_sql_))) {
20822083
LOG_WARN("failed to write string", K(sql), K(ret));
20832084
} else {
2084-
PLPrepareCtx pl_prepare_ctx(session, NULL, false, false, false);
2085+
// Pass secondary_namespace for trigger packages so that SQL in trigger body
2086+
// is fully resolved at compile time, catching references to dropped columns
2087+
// early instead of crashing at runtime. For non-trigger PL, keep using simple
2088+
// PS protocol (NULL) to allow deferred resolution of dynamic SQL constructs.
2089+
pl::ObPLBlockNS *ns_for_prepare = NULL;
2090+
if (OB_NOT_NULL(secondary_namespace)
2091+
&& ObTriggerInfo::is_trigger_package_id(secondary_namespace->get_package_id())) {
2092+
ns_for_prepare = secondary_namespace;
2093+
}
2094+
PLPrepareCtx pl_prepare_ctx(session, ns_for_prepare, false, false, false);
20852095
SMART_VAR(PLPrepareResult, pl_prepare_result) {
20862096
CK (OB_NOT_NULL(GCTX.sql_engine_));
20872097
OZ (pl_prepare_result.init(session));

0 commit comments

Comments
 (0)