mariadb/tests
Dmitry Shulga bd9274faa4 MDEV-16128: Server crash in Item_func::print_op on 2nd execution of PS
For some queries that involve tables with different but convertible
character sets for columns taking part in the query, repeatable
execution of such queries in PS mode or as part of a stored routine
would result in server abnormal termination.

For example,
  CREATE TABLE t1 (a2 varchar(10));
  CREATE TABLE t2 (u1 varchar(10) CHARACTER SET utf8);
  CREATE TABLE t3 (u2 varchar(10) CHARACTER SET utf8);
  PREPARE stmt FROM
    "SELECT t1.* FROM (t1 JOIN t2 ON (t2.u1 = t1.a2))
     WHERE (EXISTS (SELECT 1 FROM t3 WHERE t3.u2 = t1.a2))";

  EXECUTE stmt;
  EXECUTE stmt; <== Running this prepared statement the second time
                    results in server crash.

The reason of server crash is that an instance of the class
Item_func_conv_charset, that created for conversion of a column
from one character set to another, is allocated on execution
memory root but pointer to this instance is stored in an item
placed on prepared statement memory root. Below is calls trace to
the place where an instance of the class Item_func_conv_charset
is created.

setup_conds
 Item_func::fix_fields
  Item_bool_rowready_func2::fix_length_and_dec
   Item_func::setup_args_and_comparator
    Item_func_or_sum::agg_arg_charsets_for_comparison
     Item_func_or_sum::agg_arg_charsets
      Item_func_or_sum::agg_item_set_converter
       Item::safe_charset_converter

And the following trace shows the place where a pointer to
the instance of the class Item_func_conv_charset is passed
to the class Item_func_eq, that is created on a memory root of
the prepared statement.

Prepared_statement::execute
 mysql_execute_command
  execute_sqlcom_select
   handle_select
    mysql_select
     JOIN::optimize
      JOIN::optimize_inner
       convert_join_subqueries_to_semijoins
        convert_subq_to_sj

To fix the issue, switch to the Prepared Statement memory root
before calling the method Item_func::setup_args_and_comparator
in order to place any created Items on permanent memory root.
It may seem that such approach would result in a memory
leakage in case the parameter marker '?' is used in the query
as in the following example
  PREPARE stmt FROM
    "SELECT t1.* FROM (t1 JOIN t2 ON (t2.u1 = t1.a2))
     WHERE (EXISTS (SELECT 1 FROM t3 WHERE t3.u2 = ?))";
  EXECUTE stmt USING convert('A' using latin1);
but it wouldn't since for such case any of the parameter markers
is treated as a constant and no subquery to semijoin optimization
is performed.
2022-10-17 15:05:17 +07:00
..
async_queries.c
auto_increment.res
auto_increment.tst
big_record.pl mtr: use env for perl 2020-06-23 03:24:46 +02:00
bug25714.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
check_async_queries.pl
CMakeLists.txt Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
connect_test.c Update FSF Address 2019-05-11 21:29:06 +03:00
consistent_snapshot.pl
deadlock_test.c Update FSF Address 2019-05-11 21:29:06 +03:00
drop_test.pl MDEV-23697: perl -w -> perl 2020-09-24 08:09:56 +10:00
export.pl mtr: use env for perl 2020-06-23 03:24:46 +02:00
fork2_test.pl MDEV-23697: perl -w -> perl 2020-09-24 08:09:56 +10:00
fork_big.pl MDEV-23697: perl -w -> perl 2020-09-24 08:09:56 +10:00
fork_big2.pl MDEV-23697: perl -w -> perl 2020-09-24 08:09:56 +10:00
function.res
function.tst
grant.res
index_corrupt.pl MDEV-23697: perl -w -> perl 2020-09-24 08:09:56 +10:00
insert_and_repair.pl MDEV-23697: perl -w -> perl 2020-09-24 08:09:56 +10:00
insert_test.c Update FSF Address 2019-05-11 21:29:06 +03:00
list_test.c Update FSF Address 2019-05-11 21:29:06 +03:00
lock_test.pl mtr: use env for perl 2020-06-23 03:24:46 +02:00
lock_test.res
mail_to_db.pl MDEV-23697: perl -w -> perl 2020-09-24 08:09:56 +10:00
myisam-big-rows.tst
mysql_client_fw.c Merge branch '10.2' into 10.3 2022-05-03 10:59:54 +02:00
mysql_client_test.c MDEV-16128: Server crash in Item_func::print_op on 2nd execution of PS 2022-10-17 15:05:17 +07:00
nonblock-wrappers.h
pmail.pl MDEV-23697: perl -w -> perl 2020-09-24 08:09:56 +10:00
rename_test.pl MDEV-23697: perl -w -> perl 2020-09-24 08:09:56 +10:00
restore-lock.smack
select_test.c Update FSF Address 2019-05-11 21:29:06 +03:00
showdb_test.c Update FSF Address 2019-05-11 21:29:06 +03:00
ssl_test.c Update FSF Address 2019-05-11 21:29:06 +03:00
table_types.pl mtr: use env for perl 2020-06-23 03:24:46 +02:00
test_delayed_insert.pl MDEV-23697: perl -w -> perl 2020-09-24 08:09:56 +10:00
thread_test.c Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
truncate.pl MDEV-23697: perl -w -> perl 2020-09-24 08:09:56 +10:00