[Commits] 805fcc4c202: MDEV-9750: Quick memory exhaustion with 'extended_keys=on' ...
revision-id: 805fcc4c202d601b6bf4f2a39aa15c1859c6f4db (mariadb-10.4.11-421-g805fcc4c202) parent(s): 8f7e4642c56bd03327947043c5d93a7cbfaaaed3 author: Sergei Petrunia committer: Sergei Petrunia timestamp: 2020-12-15 18:24:16 +0300 message: MDEV-9750: Quick memory exhaustion with 'extended_keys=on' ... Part #2: Add debug code to verify SEL_ARG graph weight --- sql/opt_range.cc | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- sql/opt_range.h | 3 +++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/sql/opt_range.cc b/sql/opt_range.cc index eb093e39011..aef9654c646 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -9930,11 +9930,53 @@ get_range(SEL_ARG **e1,SEL_ARG **e2,SEL_ARG *root1) return 0; } +#ifndef DBUG_OFF +/* + Verify SEL_TREE's weight. + + Recompute the weight and compare +*/ +uint SEL_ARG::verify_weight() +{ + uint computed_weight= 0; + SEL_ARG *first_arg= first(); + + if (first_arg) + { + for (SEL_ARG *arg= first_arg; arg; arg= arg->next) + { + computed_weight += 1; + if (arg->next_key_part) + computed_weight+= arg->next_key_part->verify_weight(); + } + } + else + { + // first()=NULL means this is a special kind of SEL_ARG, e.g. + // SEL_ARG with type=MAYBE_KEY + computed_weight= 1; + if (next_key_part) + computed_weight += next_key_part->verify_weight(); + } + + if (computed_weight != weight) + { + sql_print_error("SEL_ARG weight mismatch: computed %u have %u\n", + computed_weight, weight); + } + return computed_weight; +} +#endif static SEL_ARG *key_or_with_limit(RANGE_OPT_PARAM *param, SEL_ARG *key1, SEL_ARG *key2) { - return enforce_sel_arg_weight_limit(key_or(param, key1, key2)); + SEL_ARG *res= enforce_sel_arg_weight_limit(key_or(param, key1, key2)); +#ifndef DBUG_OFF + if (res) + res->verify_weight(); +#endif + return res; } @@ -9942,7 +9984,12 @@ static SEL_ARG *key_and_with_limit(RANGE_OPT_PARAM *param, SEL_ARG *key1, SEL_ARG *key2, uint clone_flag) { - return enforce_sel_arg_weight_limit(key_and(param, key1, key2, clone_flag)); + SEL_ARG *res= enforce_sel_arg_weight_limit(key_and(param, key1, key2, clone_flag)); +#ifndef DBUG_OFF + if (res) + res->verify_weight(); +#endif + return res; } diff --git a/sql/opt_range.h b/sql/opt_range.h index d37339707b8..14b52d358b0 100644 --- a/sql/opt_range.h +++ b/sql/opt_range.h @@ -309,6 +309,9 @@ class SEL_ARG :public Sql_alloc */ uint weight; enum { MAX_WEIGHT = 32000 }; +#ifndef DBUG_OFF + uint verify_weight(); +#endif /* See RANGE_OPT_PARAM::alloced_sel_args */ enum { MAX_SEL_ARGS = 16000 };
participants (1)
-
psergey