diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 496ae461d2f..2f3425a2320 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -3039,6 +3039,19 @@ reexecute: if (!check_parameter_types()) { // Only one reprepare is required in case of parameter mismatch assert(!reprepared_for_types); + /** + * Infinite loop protection mechanism. + * + * When prepared statement parameter types mismatch, re-preparation should be triggered. + * However, if types still mismatch after re-preparation, it may lead to infinite loops. + * + * DEBUG mode: Assert failure to generate core dump for development debugging + * RELEASE mode: Return error code to ensure service stability + */ + if (unlikely(reprepared_for_types)) { + my_error(ER_UNKNOWN_ERROR, MYF(0)); + return true; + } reprepared_for_types = true; if (reprepare(thd)) return true; goto reexecute;