summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Shulga <dmitry.shulga@mariadb.com>2022-12-19 17:37:21 +0700
committerDmitry Shulga <dmitry.shulga@mariadb.com>2022-12-19 17:37:21 +0700
commitbda2ce67959c5f6063ceb1f0ac6e3ce7d436f3d5 (patch)
treefed33e327c1a8d537f084940feeeb5728d5e5cbd
parentc194db34d93d8d94bd52b17349063fa401e3f942 (diff)
downloadmariadb-git-bda2ce67959c5f6063ceb1f0ac6e3ce7d436f3d5.tar.gz
MDEV-5816: Stored programs: validation of stored program statements
This is the prerequisite patch to make interface of the class Reprepare_observer more like the one used by MySQL. This patch adds the method can_retry() to the class Reprepare_observer that returns true in case max. number of attempts to re-run a failing statement is not yet reached. To control a number of re-run attempts already done the data member m_attempt has been introduced. Doing this way, we encapsulate activity with incrementing a counter on every statement run and checking whether it reaches a limit or not inside implementation of the class Reprepare_observer instead duplicating such boiler plate code in every place where controlling for reaching a limit of max. number attempts for re-running failed statement is required.
-rw-r--r--sql/sql_prepare.cc9
-rw-r--r--sql/sql_prepare.h13
2 files changed, 15 insertions, 7 deletions
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index c57e76da52c..523a95d7746 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -4026,6 +4026,7 @@ Reprepare_observer::report_error(THD *thd)
*/
thd->get_stmt_da()->set_error_status(ER_NEED_REPREPARE);
m_invalidated= TRUE;
+ m_attempt++;
return TRUE;
}
@@ -4591,7 +4592,6 @@ Prepared_statement::set_parameters(String *expanded_query,
@retval FALSE successfully executed the statement, perhaps
after having reprepared it a few times.
*/
-const static int MAX_REPREPARE_ATTEMPTS= 3;
bool
Prepared_statement::execute_loop(String *expanded_query,
@@ -4600,7 +4600,6 @@ Prepared_statement::execute_loop(String *expanded_query,
uchar *packet_end)
{
Reprepare_observer reprepare_observer;
- int reprepare_attempt= 0;
bool error;
iterations= FALSE;
@@ -4653,7 +4652,7 @@ reexecute:
(sql_command_flags[lex->sql_command] & CF_REEXECUTION_FRAGILE) &&
!thd->is_fatal_error && !thd->killed &&
reprepare_observer.is_invalidated() &&
- reprepare_attempt++ < MAX_REPREPARE_ATTEMPTS)
+ reprepare_observer.can_retry())
{
DBUG_ASSERT(thd->get_stmt_da()->sql_errno() == ER_NEED_REPREPARE);
thd->clear_error();
@@ -4782,8 +4781,6 @@ Prepared_statement::execute_bulk_loop(String *expanded_query,
// iterations changed by set_bulk_parameters
while ((iterations || start_param) && !error && !thd->is_error())
{
- int reprepare_attempt= 0;
-
/*
Here we set parameters for not optimized commands,
optimized commands do it inside thier internal loop.
@@ -4843,7 +4840,7 @@ reexecute:
(sql_command_flags[lex->sql_command] & CF_REEXECUTION_FRAGILE) &&
!thd->is_fatal_error && !thd->killed &&
reprepare_observer.is_invalidated() &&
- reprepare_attempt++ < MAX_REPREPARE_ATTEMPTS)
+ reprepare_observer.can_retry())
{
DBUG_ASSERT(thd->get_stmt_da()->sql_errno() == ER_NEED_REPREPARE);
thd->clear_error();
diff --git a/sql/sql_prepare.h b/sql/sql_prepare.h
index 1a96df85a19..73966d9f6f9 100644
--- a/sql/sql_prepare.h
+++ b/sql/sql_prepare.h
@@ -65,8 +65,19 @@ public:
bool report_error(THD *thd);
bool is_invalidated() const { return m_invalidated; }
void reset_reprepare_observer() { m_invalidated= FALSE; }
+
+ bool can_retry() const
+ {
+ // The method must be called only for a statement that is invalidated
+ assert(is_invalidated());
+ return m_attempt <= MAX_REPREPARE_ATTEMPTS;
+ }
+
private:
- bool m_invalidated;
+ bool m_invalidated{false};
+ int m_attempt{0};
+
+ static const int MAX_REPREPARE_ATTEMPTS= 3;
};