diff --git a/src/pl/ob_pl_type.cpp b/src/pl/ob_pl_type.cpp index 2ec36ecc18..fac2f74343 100644 --- a/src/pl/ob_pl_type.cpp +++ b/src/pl/ob_pl_type.cpp @@ -2224,13 +2224,19 @@ int ObPLCursorInfo::prepare_spi_result(ObPLExecCtx *ctx, ObSPIResultSet *&spi_re CK (OB_NOT_NULL(ctx)); CK (OB_NOT_NULL(ctx->exec_ctx_)); CK (OB_NOT_NULL(ctx->exec_ctx_->get_my_session())); - if (OB_ISNULL(spi_cursor_)) { + if (OB_ISNULL(spi_cursor_) || !last_stream_cursor_) { OV (OB_NOT_NULL(get_allocator())); + if (OB_SUCC(ret) && OB_NOT_NULL(spi_cursor_) && OB_NOT_NULL(static_cast(spi_cursor_))) { + static_cast(spi_cursor_)->~ObSPICursor(); + get_allocator()->free(spi_cursor_); + spi_cursor_ = NULL; + } OX (spi_cursor_ = get_allocator()->alloc(sizeof(ObSPIResultSet))); OV (OB_NOT_NULL(spi_cursor_), OB_ALLOCATE_MEMORY_FAILED); } OX (spi_result = new (spi_cursor_) ObSPIResultSet()); OZ (spi_result->init(*ctx->exec_ctx_->get_my_session())); + OX (last_stream_cursor_ = true); return ret; } @@ -2252,6 +2258,7 @@ int ObPLCursorInfo::prepare_spi_cursor(ObSPICursor *&spi_cursor, OV (OB_NOT_NULL(spi_cursor_), OB_ALLOCATE_MEMORY_FAILED); } OX (spi_cursor = new (spi_cursor_) ObSPICursor(*spi_allocator)); + OX (last_stream_cursor_ = false); if (OB_SUCC(ret)) { if (OB_INVALID_SIZE == mem_limit) { mem_limit = GCONF._chunk_row_store_mem_limit; diff --git a/src/pl/ob_pl_type.h b/src/pl/ob_pl_type.h index 6920ad44ab..0232ed05f8 100644 --- a/src/pl/ob_pl_type.h +++ b/src/pl/ob_pl_type.h @@ -778,7 +778,8 @@ public: cursor_flag_(CURSOR_FLAG_UNDEF), ref_count_(0), is_scrollable_(false), - last_execute_time_(0) + last_execute_time_(0), + last_stream_cursor_(false) { reset(); } @@ -796,7 +797,8 @@ public: is_scrollable_(false), snapshot_(), is_need_check_snapshot_(false), - last_execute_time_(0) + last_execute_time_(0), + last_stream_cursor_(false) { reset(); } @@ -1043,6 +1045,7 @@ protected: transaction::ObTxReadSnapshot snapshot_; bool is_need_check_snapshot_; int64_t last_execute_time_; // 记录上一次cursor操作的时间点 + bool last_stream_cursor_; // cursor复用场景下,记录上一次是否是流式cursor }; class ObPLGetCursorAttrInfo