midenok / mariadb

MariaDB server is a community developed fork of MySQL server. Started by core members of the original MySQL team, MariaDB actively works with outside developers to deliver the most featureful, stable, and sanely licensed open SQL server in the industry.
GNU General Public License v2.0
0 stars 0 forks source link

Partitioning features #53

Open midenok opened 5 years ago

midenok commented 5 years ago

Jira tasks

MDEV-19903 Setup default partitions for system versioning MDEV-17554 Auto-create new partition for system versioned tables with history partitioned by INTERVAL

MDEV-19903 Setup default partitions ...

Description

Currently such syntax fails:

create table t1 (i int) with system versioning partition by system_time;

with error message:

ERROR 1492 (HY000): For LIST partitions each partition must be defined

which is by itself incorrect.

Auto-create 1 history partition and 1 working partition for the above syntax. Specify the number of history partitions by the partitions keyword:

create table t1 (i int) with system versioning partition by system_time partitions 2;

This should create 1 history and 1 working partition. The working partition is mandatory, so partitions 1 should fail with error.

Info

create or replace table t1 (x int)
with system versioning
partition by system_time (
    partition p0 history,
    partition pn current);
midenok commented 4 years ago

1. HA registered

#0  0x0000000000c75288 in Ha_trx_info::register_ha (this=0x7ff8040034b8, trans=0x7ff804004320, ht_arg=0x2d99778) at /home/midenok/src/mariadb/10.5/src/sql/handler.h:1918
#1  0x0000000000c5975a in trans_register_ha (thd=0x7ff804000d48, all=false, ht_arg=0x2d99778, trxid=422179462451680) at /home/midenok/src/mariadb/10.5/src/sql/handler.cc:1322
#2  0x0000000001111d44 in innobase_register_trx (hton=0x2d99778, thd=0x7ff804000d48, trx=0x7ff850e411e0) at /home/midenok/src/mariadb/10.5/src/storage/innobase/handler/ha_innodb.cc:2608
#3  0x000000000112f9fd in ha_innobase::external_lock (this=0x7ff804b243c0, thd=0x7ff804000d48, lock_type=1) at /home/midenok/src/mariadb/10.5/src/storage/innobase/handler/ha_innodb.cc:15524
#4  0x0000000000c5f38e in handler::ha_external_lock (this=0x7ff804b243c0, thd=0x7ff804000d48, lock_type=1) at /home/midenok/src/mariadb/10.5/src/sql/handler.cc:6660
#5  0x000000000104f19f in ha_partition::external_lock (this=0x7ff804ada670, thd=0x7ff804000d48, lock_type=1) at /home/midenok/src/mariadb/10.5/src/sql/ha_partition.cc:4026
#6  0x0000000000c5f32c in handler::ha_external_lock (this=0x7ff804ada670, thd=0x7ff804000d48, lock_type=1) at /home/midenok/src/mariadb/10.5/src/sql/handler.cc:6660
#7  0x0000000000de5b91 in lock_external (thd=0x7ff804000d48, tables=0x7ff8040160a0, count=1) at /home/midenok/src/mariadb/10.5/src/sql/lock.cc:393
#8  0x0000000000de56c3 in mysql_lock_tables (thd=0x7ff804000d48, sql_lock=0x7ff804016080, flags=131104) at /home/midenok/src/mariadb/10.5/src/sql/lock.cc:338
#9  0x0000000000de47b2 in mysql_lock_tables (thd=0x7ff804000d48, tables=0x7ff8040158e8, count=1, flags=131104) at /home/midenok/src/mariadb/10.5/src/sql/lock.cc:301
#10 0x00000000007d487e in open_ltable (thd=0x7ff804000d48, table_list=0x7ff8040157f0, lock_type=TL_WRITE, lock_flags=131104) at /home/midenok/src/mariadb/10.5/src/sql/sql_base.cc:5187
#11 0x00000000007d3349 in Open_table_context::recover_from_failed_open (this=0x7ff84805a6e8) at /home/midenok/src/mariadb/10.5/src/sql/sql_base.cc:3258
#12 0x00000000007d5623 in open_tables (thd=0x7ff804000d48, options=..., start=0x7ff84805b2a8, counter=0x7ff84805b25c, flags=0, prelocking_strategy=0x7ff84805a7a8) at /home/midenok/src/mariadb/10.5/src/sql/sql_base.cc:4367
#13 0x00000000007c7ac6 in open_tables (thd=0x7ff804000d48, tables=0x7ff84805b2a8, counter=0x7ff84805b25c, flags=0) at /home/midenok/src/mariadb/10.5/src/sql/sql_base.h:477
#14 0x00000000009d9c13 in mysql_update (thd=0x7ff804000d48, table_list=0x7ff804014b68, fields=..., values=..., conds=0x0, order_num=0, order=0x0, limit=18446744073709551615, ignore=false, found_return=0x7ff84805c178, updated_return=0x7ff84805c170) at /home/midenok/src/mariadb/10.5/src/sql/sql_update.cc:401
#15 0x000000000089bc0a in mysql_execute_command (thd=0x7ff804000d48) at /home/midenok/src/mariadb/10.5/src/sql/sql_parse.cc:4247
#16 0x0000000000892f56 in mysql_parse (thd=0x7ff804000d48, rawbuf=0x7ff804014a90 "update t1 set x= x + 1", length=22, parser_state=0x7ff84805d598) at /home/midenok/src/mariadb/10.5/src/sql/sql_parse.cc:7837

2. Assertion failed

#0  THD_TRANS::is_empty (this=0x7ff804004320) at /home/midenok/src/mariadb/10.5/src/sql/handler.h:1844
#1  0x00000000007d4b0a in close_tables_for_reopen (thd=0x7ff804000d48, tables=0x7ff84805a4f0, start_of_statement_svp=...) at /home/midenok/src/mariadb/10.5/src/sql/sql_base.cc:5725
#2  0x00000000007d3470 in Open_table_context::recover_from_failed_open (this=0x7ff84805a6e8) at /home/midenok/src/mariadb/10.5/src/sql/sql_base.cc:3269
#3  0x00000000007d5623 in open_tables (thd=0x7ff804000d48, options=..., start=0x7ff84805b2a8, counter=0x7ff84805b25c, flags=0, prelocking_strategy=0x7ff84805a7a8) at /home/midenok/src/mariadb/10.5/src/sql/sql_base.cc:4367
#4  0x00000000007c7ac6 in open_tables (thd=0x7ff804000d48, tables=0x7ff84805b2a8, counter=0x7ff84805b25c, flags=0) at /home/midenok/src/mariadb/10.5/src/sql/sql_base.h:477
#5  0x00000000009d9c13 in mysql_update (thd=0x7ff804000d48, table_list=0x7ff804014b68, fields=..., values=..., conds=0x0, order_num=0, order=0x0, limit=18446744073709551615, ignore=false, found_return=0x7ff84805c178, updated_return=0x7ff84805c170) at /home/midenok/src/mariadb/10.5/src/sql/sql_update.cc:401
#6  0x000000000089bc0a in mysql_execute_command (thd=0x7ff804000d48) at /home/midenok/src/mariadb/10.5/src/sql/sql_parse.cc:4247
#7  0x0000000000892f56 in mysql_parse (thd=0x7ff804000d48, rawbuf=0x7ff804014a90 "update t1 set x= x + 1", length=22, parser_state=0x7ff84805d598) at /home/midenok/src/mariadb/10.5/src/sql/sql_parse.cc:7837
midenok commented 4 years ago

Partition added

#0  ha_partition::change_partitions (this=0x7f878cb4e180, create_info=0x7f87c40f51e8, path=0x7f87c40f3e40 "./test/t1", copied=0x7f87c40f4358, deleted=0x7f87c40f4360, pack_frm_data=0x0, pack_frm_len=0) at /home/midenok/src/mariadb/10.5/src/sql/ha_partition.cc:2066
#1  0x0000000000c68fc5 in handler::ha_change_partitions (this=0x7f878cb4e180, create_info=0x7f87c40f51e8, path=0x7f87c40f3e40 "./test/t1", copied=0x7f87c40f4358, deleted=0x7f87c40f4360, pack_frm_data=0x0, pack_frm_len=0) at /home/midenok/src/mariadb/10.5/src/sql/handler.cc:5132
#2  0x0000000000eaac0d in mysql_change_partitions (lpt=0x7f87c40f4350, copy_data=false) at /home/midenok/src/mariadb/10.5/src/sql/sql_partition.cc:6043
#3  0x0000000000ea9533 in fast_alter_partition_table (thd=0x7f878c000d48, table=0x7f876400b1b8, alter_info=0x7f87c40f5118, create_info=0x7f87c40f51e8, table_list=0x7f878c0155d8, db=0x7f878cb67bf0, table_name=0x7f878cb67c00) at /home/midenok/src/mariadb/10.5/src/sql/sql_partition.cc:7300
#4  0x0000000000a39544 in vers_add_auto_parts (thd=0x7f878c000d48, tl=0x7f878c0155d8, num_parts=1) at /home/midenok/src/mariadb/10.5/src/sql/partition_info.cc:1046
#5  0x00000000007d3432 in Open_table_context::recover_from_failed_open (this=0x7f87c40f56e8) at /home/midenok/src/mariadb/10.5/src/sql/sql_base.cc:3268
#6  0x00000000007d5693 in open_tables (thd=0x7f878c000d48, options=..., start=0x7f87c40f62a8, counter=0x7f87c40f625c, flags=0, prelocking_strategy=0x7f87c40f57a8) at /home/midenok/src/mariadb/10.5/src/sql/sql_base.cc:4369
#7  0x00000000007c7ac6 in open_tables (thd=0x7f878c000d48, tables=0x7f87c40f62a8, counter=0x7f87c40f625c, flags=0) at /home/midenok/src/mariadb/10.5/src/sql/sql_base.h:477
#8  0x00000000009d9c83 in mysql_update (thd=0x7f878c000d48, table_list=0x7f878c014b68, fields=..., values=..., conds=0x0, order_num=0, order=0x0, limit=18446744073709551615, ignore=false, found_return=0x7f87c40f7178, updated_return=0x7f87c40f7170) at /home/midenok/src/mariadb/10.5/src/sql/sql_update.cc:401
#9  0x000000000089bc7a in mysql_execute_command (thd=0x7f878c000d48) at /home/midenok/src/mariadb/10.5/src/sql/sql_parse.cc:4247
#10 0x0000000000892fc6 in mysql_parse (thd=0x7f878c000d48, rawbuf=0x7f878c014a90 "update t1 set x= 1", length=18, parser_state=0x7f87c40f8598) at /home/midenok/src/mariadb/10.5/src/sql/sql_parse.cc:7837
#11 0x0000000000890369 in dispatch_command (command=COM_QUERY, thd=0x7f878c000d48, packet=0x7f878c007ef9 "update t1 set x= 1", packet_length=18) at /home/midenok/src/mariadb/10.5/src/sql/sql_parse.cc:1812
midenok commented 4 years ago

Info: trigger executed

#0  0x00000000007d0313 in open_table (thd=0x7ff7d4000d48, table_list=0x7ff7d40c1ba0, ot_ctx=0x7ff7ea9c3e58) at /home/midenok/src/mariadb/10.5/src/sql/sql_base.cc:1795
#1  0x00000000007d6d77 in open_and_process_table (thd=0x7ff7d4000d48, tables=0x7ff7d40c1ba0, counter=0x7ff7ea9c49cc, flags=0, prelocking_strategy=0x7ff7ea9c3f18, has_prelocking_list=false, ot_ctx=0x7ff7ea9c3e58) at /home/midenok/src/mariadb/10.5/src/sql/sql_base.cc:3907
#2  0x00000000007d56c0 in open_tables (thd=0x7ff7d4000d48, options=..., start=0x7ff7ea9c4a18, counter=0x7ff7ea9c49cc, flags=0, prelocking_strategy=0x7ff7ea9c3f18) at /home/midenok/src/mariadb/10.5/src/sql/sql_base.cc:4379
#3  0x00000000007c7a36 in open_tables (thd=0x7ff7d4000d48, tables=0x7ff7ea9c4a18, counter=0x7ff7ea9c49cc, flags=0) at /home/midenok/src/mariadb/10.5/src/sql/sql_base.h:477
#4  0x00000000009d9d63 in mysql_update (thd=0x7ff7d4000d48, table_list=0x7ff7d40c1ba0, fields=..., values=..., conds=0x0, order_num=0, order=0x0, limit=18446744073709551615, ignore=false, found_return=0x7ff7ea9c58e8, updated_return=0x7ff7ea9c58e0) at /home/midenok/src/mariadb/10.5/src/sql/sql_update.cc:401
#5  0x000000000089bd5a in mysql_execute_command (thd=0x7ff7d4000d48) at /home/midenok/src/mariadb/10.5/src/sql/sql_parse.cc:4247
#6  0x0000000000779155 in sp_instr_stmt::exec_core (this=0x7ff7d40c26b0, thd=0x7ff7d4000d48, nextp=0x7ff7ea9c67b8) at /home/midenok/src/mariadb/10.5/src/sql/sp_head.cc:3765
#7  0x00000000007779dc in sp_lex_keeper::reset_lex_and_exec_core (this=0x7ff7d40c26f8, thd=0x7ff7d4000d48, nextp=0x7ff7ea9c67b8, open_tables=false, instr=0x7ff7d40c26b0) at /home/midenok/src/mariadb/10.5/src/sql/sp_head.cc:3492
#8  0x000000000077833f in sp_instr_stmt::execute (this=0x7ff7d40c26b0, thd=0x7ff7d4000d48, nextp=0x7ff7ea9c67b8) at /home/midenok/src/mariadb/10.5/src/sql/sp_head.cc:3671
#9  0x000000000076f3b0 in sp_head::execute (this=0x7ff7d40c0e20, thd=0x7ff7d4000d48, merge_da_on_success=false) at /home/midenok/src/mariadb/10.5/src/sql/sp_head.cc:1435
#10 0x0000000000770a5f in sp_head::execute_trigger (this=0x7ff7d40c0e20, thd=0x7ff7d4000d48, db_name=0x7ff7d40baac0, table_name=0x7ff7d40baad0, grant_info=0x7ff7d40c6f60) at /home/midenok/src/mariadb/10.5/src/sql/sp_head.cc:1913
#11 0x00000000009c8e09 in Table_triggers_list::process_triggers (this=0x7ff7d40c0a20, thd=0x7ff7d4000d48, event=TRG_EVENT_INSERT, time_type=TRG_ACTION_BEFORE, old_row_is_record1=true) at /home/midenok/src/mariadb/10.5/src/sql/sql_trigger.cc:2239
#12 0x00000000007e2d3f in fill_record_n_invoke_before_triggers (thd=0x7ff7d4000d48, table=0x7ff7d40bca38, ptr=0x7ff7d40bce58, values=..., ignore_errors=false, event=TRG_EVENT_INSERT) at /home/midenok/src/mariadb/10.5/src/sql/sql_base.cc:8910
#13 0x000000000083bd51 in mysql_insert (thd=0x7ff7d4000d48, table_list=0x7ff7d4014b70, fields=..., values_list=..., update_fields=..., update_values=..., duplic=DUP_ERROR, ignore=false, result=0x0) at /home/midenok/src/mariadb/10.5/src/sql/sql_insert.cc:1030
#14 0x000000000089c62d in mysql_execute_command (thd=0x7ff7d4000d48) at /home/midenok/src/mariadb/10.5/src/sql/sql_parse.cc:4399
#15 0x00000000008930a6 in mysql_parse (thd=0x7ff7d4000d48, rawbuf=0x7ff7d4014a90 "insert into t2 values (2)", length=25, parser_state=0x7ff7ea9c9598) at /home/midenok/src/mariadb/10.5/src/sql/sql_parse.cc:7837

Info: hang in wait_for_refs()

If we don't do tc_release_table() on request_backoff_action().

#0  futex_wait_cancelable (private=<optimized out>, expected=0, futex_word=0x7fffc4b0f638) at ../sysdeps/unix/sysv/linux/futex-internal.h:80
#1  __pthread_cond_wait_common (abstime=0x0, clockid=0, mutex=0x7fffc4b0f588, cond=0x7fffc4b0f610) at pthread_cond_wait.c:508
#2  __pthread_cond_wait (cond=0x7fffc4b0f610, mutex=0x7fffc4b0f588) at pthread_cond_wait.c:638
#3  0x00000000016ac979 in safe_cond_wait (cond=0x7fffc4b0f610, mp=0x7fffc4b0f560, file=0x175364a "/home/midenok/src/mariadb/10.5/src/include/mysql/psi/mysql_thread.h", line=1220) at /home/midenok/src/mariadb/10.5/src/mysys/thr_mutex.c:492
#4  0x0000000000b62814 in inline_mysql_cond_wait (that=0x7fffc4b0f610, mutex=0x7fffc4b0f560, src_file=0x17cc940 "/home/midenok/src/mariadb/10.5/src/sql/table_cache.cc", src_line=1236) at /home/midenok/src/mariadb/10.5/src/include/mysql/psi/mysql_thread.h:1220
#5  0x0000000000b67b56 in TDC_element::wait_for_refs (this=0x7fffc4b0f3c8, my_refs=1) at /home/midenok/src/mariadb/10.5/src/sql/table_cache.cc:1236
#6  0x0000000000b65a50 in tdc_remove_referenced_share (thd=0x7fffc4000d48, share=0x7fffc4ac5550) at /home/midenok/src/mariadb/10.5/src/sql/table_cache.cc:1006
#7  0x0000000000b65f8e in tdc_remove_table (thd=0x7fffc4000d48, db=0x7fffc4015238 "test", table_name=0x7fffc4014b30 "t1") at /home/midenok/src/mariadb/10.5/src/sql/table_cache.cc:1061
#8  0x00000000007d30b1 in Open_table_context::recover_from_failed_open (this=0x7ffff06666e8) at /home/midenok/src/mariadb/10.5/src/sql/sql_base.cc:3235
#9  0x00000000007d55d3 in open_tables (thd=0x7fffc4000d48, options=..., start=0x7ffff06672a8, counter=0x7ffff066725c, flags=0, prelocking_strategy=0x7ffff06667a8) at /home/midenok/src/mariadb/10.5/src/sql/sql_base.cc:4378
#10 0x00000000007c7a36 in open_tables (thd=0x7fffc4000d48, tables=0x7ffff06672a8, counter=0x7ffff066725c, flags=0) at /home/midenok/src/mariadb/10.5/src/sql/sql_base.h:477
#11 0x00000000009d9bc3 in mysql_update (thd=0x7fffc4000d48, table_list=0x7fffc4014b68, fields=..., values=..., conds=0x0, order_num=0, order=0x0, limit=18446744073709551615, ignore=false, found_return=0x7ffff0668178, updated_return=0x7ffff0668170) at /home/midenok/src/mariadb/10.5/src/sql/sql_update.cc:401

Without MYSQL_UNBIND_TABLE():

#7  0x00007fa00aa23006 in __GI___assert_fail (assertion=0x196de1f "pfs->m_thread_owner == __null", file=0x196d990 "/home/midenok/src/mariadb/10.5/src/storage/perfschema/pfs.cc", line=2007, function=0x196de3d "PSI_table *pfs_rebind_table_v1(PSI_table_share *, const void *, PSI_table *)") at assert.c:101
#8  0x000000000106ec18 in pfs_rebind_table_v1 (share=0x343d540, identity=0x7f9fc8c62e70, table=0x7f9fc83a7700) at /home/midenok/src/mariadb/10.5/src/storage/perfschema/pfs.cc:2007
#9  0x0000000000c5f3ce in handler::rebind_psi (this=0x7f9fc8c62e70) at /home/midenok/src/mariadb/10.5/src/sql/handler.cc:2918
#10 0x00000000007d0d95 in open_table (thd=0x7f9fb8000d48, table_list=0x7f9fb8011508, ot_ctx=0x7f9fffd656e8) at /home/midenok/src/mariadb/10.5/src/sql/sql_base.cc:2019
#11 0x00000000007d6be7 in open_and_process_table (thd=0x7f9fb8000d48, tables=0x7f9fb8011508, counter=0x7f9fffd6625c, flags=0, prelocking_strategy=0x7f9fffd657a8, has_prelocking_list=false, ot_ctx=0x7f9fffd656e8) at /home/midenok/src/mariadb/10.5/src/sql/sql_base.cc:3876
#12 0x00000000007d5530 in open_tables (thd=0x7f9fb8000d48, options=..., start=0x7f9fffd662a8, counter=0x7f9fffd6625c, flags=0, prelocking_strategy=0x7f9fffd657a8) at /home/midenok/src/mariadb/10.5/src/sql/sql_base.cc:4348
#13 0x00000000007c7a36 in open_tables (thd=0x7f9fb8000d48, tables=0x7f9fffd662a8, counter=0x7f9fffd6625c, flags=0) at /home/midenok/src/mariadb/10.5/src/sql/sql_base.h:477
#14 0x00000000009d9bd3 in mysql_update (thd=0x7f9fb8000d48, table_list=0x7f9fb8011508, fields=..., values=..., conds=0x7f9fb80121f8, order_num=0, order=0x0, limit=18446744073709551615, ignore=false, found_return=0x7f9fffd67178, updated_return=0x7f9fffd67170) at /home/midenok/src/mariadb/10.5/src/sql/sql_update.cc:401
#15 0x000000000089bbca in mysql_execute_command (thd=0x7f9fb8000d48) at /home/midenok/src/mariadb/10.5/src/sql/sql_parse.cc:4247
#16 0x0000000000892f16 in mysql_parse (thd=0x7f9fb8000d48, rawbuf=0x7f9fb8011410 "update t1 set x= x + 122 where x = 1", length=36, parser_state=0x7f9fffd68598) at /home/midenok/src/mariadb/10.5/src/sql/sql_parse.cc:7837
midenok commented 3 years ago

MDEV-12483 Add foreign keys support for partitioned tables

  1. Per each TABLE_SHARE foreign key make a set of InnoDB foreign keys for each partition.
  2. To achieve 1. InnoDB must know partition names. Currently part_info is available for TABLE object but not for TABLE_SHARE. TABLE_SHARE stores unparsed sql string of partitions definition. We must move part_info initialization from TABLE to TABLE_SHARE by mysql_unpack_partition() refactoring.

mysql_unpack_partition() refactoring

  1. Currently mysql_unpack_partition() is called for each TABLE initialization in open_table_from_share(). This is done because local lex is initialized with TABLE object by init_lex_with_single_table(). But the fact is TABLE is not used much for parsing partitioning part of table definition. We can easily omit TABLE parameter and make init_lex_with_single_share() instead.

  2. Another problem is is_create_table_ind flag and if (is_create_table_ind && old_lex->sql_command == SQLCOM_CREATE_TABLE) branch which is a dirty hack to solve the case:

create table t2 (b int);
--error ER_BAD_FIELD_ERROR
create table t1 (b int)
PARTITION BY RANGE (t2.b) (
  PARTITION p1 VALUES LESS THAN (10),
  PARTITION p2 VALUES LESS THAN (20)
) select * from t2;

The problem is that reconstructed partitioning definition is missing "t2.b" qualification and instead contains "b":

#0  mysql_unpack_partition (thd=0x7fb6f4000d48, part_buf=0x7fb6f4946d30 " PARTITION BY RANGE (`b`)\n(PARTITION `p1` VALUES LESS THAN (10) ENGINE = MyISAM,\n PARTITION `p2` VALUES LESS THAN (20) ENGINE = MyISAM)", part_info_len=135, table=0x7fb72404d198, is_create_table_ind=true, default_db_type=0x32a8818, work_part_info_used=0x7fb72404c863) at /home/midenok/src/mariadb/10.6/src/sql/sql_partition.cc:4450
#1  0x0000000000a4d260 in open_table_from_share (thd=0x7fb6f4000d48, share=0x7fb72404c9f8, alias=0x1e08d38 <empty_clex_str>, db_stat=0, prgflag=1, ha_open_flags=0, outparam=0x7fb72404d198, is_create_table=true, partitions_to_open=0x0) at /home/midenok/src/mariadb/10.6/src/sql/table.cc:4119
#2  0x0000000000cbb185 in ha_create_table (thd=0x7fb6f4000d48, path=0x7fb72404e4f0 "./test/t1", db=0x7fb6f4016788 "test", table_name=0x7fb6f4016080 "t1", create_info=0x7fb72404ff38, frm=0x7fb72404e4e0) at /home/midenok/src/mariadb/10.6/src/sql/handler.cc:5549
#3  0x00000000009f125a in create_table_impl (thd=0x7fb6f4000d48, orig_db=..., orig_table_name=..., db=..., table_name=..., path=0x7fb72404e4f0 "./test/t1", options=..., create_info=0x7fb72404ff38, alter_info=0x7fb72404fe68, create_table_mode=1, is_trans=0x0, key_info=0x7fb72404e700, key_count=0x7fb72404e6fc, frm=0x7fb72404e4e0) at /home/midenok/src/mariadb/10.6/src/sql/sql_table.cc:5376
#4  0x00000000009f0348 in mysql_create_table_no_lock (thd=0x7fb6f4000d48, db=0x7fb6f40160d0, table_name=0x7fb6f40160e0, create_info=0x7fb72404ff38, alter_info=0x7fb72404fe68, is_trans=0x0, create_table_mode=1, table_list=0x7fb6f40160b8) at /home/midenok/src/mariadb/10.6/src/sql/sql_table.cc:5460
#5  0x00000000008932f2 in select_create::create_table_from_items (this=0x7fb6f4018c68, thd=0x7fb6f4000d48, items=0x7fb72404f428, lock=0x7fb72404f420, hooks=0x7fb72404f3c8) at /home/midenok/src/mariadb/10.6/src/sql/sql_insert.cc:4466
#6  0x0000000000893b16 in select_create::prepare (this=0x7fb6f4018c68, _values=..., u=0x7fb6f4004f00) at /home/midenok/src/mariadb/10.6/src/sql/sql_insert.cc:4663
#7  0x000000000093a102 in JOIN::prepare (this=0x7fb6f4018d68, tables_init=0x7fb6f4017580, conds_init=0x0, og_num=0, order_init=0x0, skip_order_by=false, group_init=0x0, having_init=0x0, proc_param_init=0x0, select_lex_arg=0x7fb6f4016f90, unit_arg=0x7fb6f4004f00) at /home/midenok/src/mariadb/10.6/src/sql/sql_select.cc:1503
#8  0x00000000009342e2 in mysql_select (thd=0x7fb6f4000d48, tables=0x7fb6f4017580, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2201171004160, result=0x7fb6f4018c68, unit=0x7fb6f4004f00, select_lex=0x7fb6f4016f90) at /home/midenok/src/mariadb/10.6/src/sql/sql_select.cc:4705
#9  0x0000000000933c2d in handle_select (thd=0x7fb6f4000d48, lex=0x7fb6f4004e38, result=0x7fb6f4018c68, setup_tables_done_option=0) at /home/midenok/src/mariadb/10.6/src/sql/sql_select.cc:417
#10 0x0000000000a08423 in Sql_cmd_create_table_like::execute (this=0x7fb6f4016058, thd=0x7fb6f4000d48) at /home/midenok/src/mariadb/10.6/src/sql/sql_table.cc:12104
#11 0x00000000008ed255 in mysql_execute_command (thd=0x7fb6f4000d48) at /home/midenok/src/mariadb/10.6/src/sql/sql_parse.cc:5946
#12 0x00000000008dde16 in mysql_parse (thd=0x7fb6f4000d48, rawbuf=0x7fb6f4015ee0 "create table t1 (b int)\nPARTITION BY RANGE (t2.b) (\nPARTITION p1 VALUES LESS THAN (10),\nPARTITION p2 VALUES LESS THAN (20)\n) select * from t2", length=141, parser_state=0x7fb7240524c8) at /home/midenok/src/mariadb/10.6/src/sql/sql_parse.cc:7975
(rr) pitem thd->work_part_info->part_expr
$9 = 0x21826f0 <dbug_item_print_buf> "t2.b"
(rr) pitem part_info->part_expr
$10 = 0x21826f0 <dbug_item_print_buf> "b"

The hack fixed this by overwriting part_info with thd->work_part_info which caused some unpretty extra code and arguments.

midenok commented 3 years ago

Good: ER_BAD_FIELD_ERROR thrown

#0  my_error (nr=1054, MyFlags=0) at /home/midenok/src/mariadb/10.6/src/mysys/my_error.c:113
#1  0x0000000000826602 in find_field_in_tables (thd=0x7f8b7c000d48, item=0x7f8b7c016af0, first_table=0x7f8b7c01b778, last_table=0x0, ref=0x7f8b90b06480, report_error=REPORT_ALL_ERRORS, check_privileges=true, register_tree_change=true) at /home/midenok/src/mariadb/10.6/src/sql/sql_base.cc:6512
#2  0x0000000000ce1e2a in Item_field::fix_fields (this=0x7f8b7c016af0, thd=0x7f8b7c000d48, reference=0x7f8b90b06480) at /home/midenok/src/mariadb/10.6/src/sql/item.cc:5844
#3  0x000000000078ff83 in Item::fix_fields_if_needed (this=0x7f8b7c016af0, thd=0x7f8b7c000d48, ref=0x7f8b90b06480) at /home/midenok/src/mariadb/10.6/src/sql/item.h:988
#4  0x0000000000ef0d73 in fix_fields_part_func (thd=0x7f8b7c000d48, func_expr=0x7f8b7c016af0, table=0x7f8b90b07198, is_sub_part=false, is_create_table_ind=true) at /home/midenok/src/mariadb/10.6/src/sql/sql_partition.cc:866
#5  0x0000000000ef025a in fix_partition_func (thd=0x7f8b7c000d48, table=0x7f8b90b07198, is_create_table_ind=true) at /home/midenok/src/mariadb/10.6/src/sql/sql_partition.cc:2018
#6  0x0000000000a4d5ac in open_table_from_share (thd=0x7f8b7c000d48, share=0x7f8b90b069f8, alias=0x1e09d38 <empty_clex_str>, db_stat=0, prgflag=1, ha_open_flags=0, outparam=0x7f8b90b07198, is_create_table=true, partitions_to_open=0x0) at /home/midenok/src/mariadb/10.6/src/sql/table.cc:4146
#7  0x0000000000cbb485 in ha_create_table (thd=0x7f8b7c000d48, path=0x7f8b90b084f0 "./test/t1", db=0x7f8b7c016788 "test", table_name=0x7f8b7c016080 "t1", create_info=0x7f8b90b09f38, frm=0x7f8b90b084e0) at /home/midenok/src/mariadb/10.6/src/sql/handler.cc:5549
#8  0x00000000009f138a in create_table_impl (thd=0x7f8b7c000d48, orig_db=..., orig_table_name=..., db=..., table_name=..., path=0x7f8b90b084f0 "./test/t1", options=..., create_info=0x7f8b90b09f38, alter_info=0x7f8b90b09e68, create_table_mode=1, is_trans=0x0, key_info=0x7f8b90b08700, key_count=0x7f8b90b086fc, frm=0x7f8b90b084e0) at /home/midenok/src/mariadb/10.6/src/sql/sql_table.cc:5376
#9  0x00000000009f0478 in mysql_create_table_no_lock (thd=0x7f8b7c000d48, db=0x7f8b7c0160d0, table_name=0x7f8b7c0160e0, create_info=0x7f8b90b09f38, alter_info=0x7f8b90b09e68, is_trans=0x0, create_table_mode=1, table_list=0x7f8b7c0160b8) at /home/midenok/src/mariadb/10.6/src/sql/sql_table.cc:5460
#10 0x00000000008936d2 in select_create::create_table_from_items (this=0x7f8b7c018c68, thd=0x7f8b7c000d48, items=0x7f8b90b09428, lock=0x7f8b90b09420, hooks=0x7f8b90b093c8) at /home/midenok/src/mariadb/10.6/src/sql/sql_insert.cc:4464
#11 0x0000000000893ef6 in select_create::prepare (this=0x7f8b7c018c68, _values=..., u=0x7f8b7c004f00) at /home/midenok/src/mariadb/10.6/src/sql/sql_insert.cc:4661
#12 0x000000000093a2b5 in JOIN::prepare (this=0x7f8b7c018d68, tables_init=0x7f8b7c017580, conds_init=0x0, og_num=0, order_init=0x0, skip_order_by=false, group_init=0x0, having_init=0x0, proc_param_init=0x0, select_lex_arg=0x7f8b7c016f90, unit_arg=0x7f8b7c004f00) at /home/midenok/src/mariadb/10.6/src/sql/sql_select.cc:1504
#13 0x0000000000934492 in mysql_select (thd=0x7f8b7c000d48, tables=0x7f8b7c017580, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2201171004160, result=0x7f8b7c018c68, unit=0x7f8b7c004f00, select_lex=0x7f8b7c016f90) at /home/midenok/src/mariadb/10.6/src/sql/sql_select.cc:4706
#14 0x0000000000933ddd in handle_select (thd=0x7f8b7c000d48, lex=0x7f8b7c004e38, result=0x7f8b7c018c68, setup_tables_done_option=0) at /home/midenok/src/mariadb/10.6/src/sql/sql_select.cc:417
#15 0x0000000000a08553 in Sql_cmd_create_table_like::execute (this=0x7f8b7c016058, thd=0x7f8b7c000d48) at /home/midenok/src/mariadb/10.6/src/sql/sql_table.cc:12104
#16 0x00000000008ed408 in mysql_execute_command (thd=0x7f8b7c000d48) at /home/midenok/src/mariadb/10.6/src/sql/sql_parse.cc:5946
#17 0x00000000008ddfd6 in mysql_parse (thd=0x7f8b7c000d48, rawbuf=0x7f8b7c015ee0 "create table t1 (b int)\nPARTITION BY RANGE (t2.b) (\nPARTITION p1 VALUES LESS THAN (10),\nPARTITION p2 VALUES LESS THAN (20)\n) select * from t2", length=141, parser_state=0x7f8b90b0c4c8) at /home/midenok/src/mariadb/10.6/src/sql/sql_parse.cc:7972

frame 5

(rr) pitem part_info->part_expr
$4 = 0x21837f0 <dbug_item_print_buf> "t2.b"

part_info->part_expr set

#0  0x0000000000a8a5b3 in partition_info::set_part_expr (this=0x7f8b7c0168a0, thd=0x7f8b7c000d48, item_ptr=0x7f8b7c016af0, is_subpart=false) at /home/midenok/src/mariadb/10.6/src/sql/partition_info.cc:1428
#1  0x0000000000bce6a9 in MYSQLparse (thd=0x7f8b7c000d48) at /home/midenok/src/mariadb/10.6/src/sql/sql_yacc.yy:4856
#2  0x00000000008f496d in parse_sql (thd=0x7f8b7c000d48, parser_state=0x7f8b90b0c4c8, creation_ctx=0x0, do_pfs_digest=true) at /home/midenok/src/mariadb/10.6/src/sql/sql_parse.cc:10306
#3  0x00000000008dddac in mysql_parse (thd=0x7f8b7c000d48, rawbuf=0x7f8b7c015ee0 "create table t1 (b int)\nPARTITION BY RANGE (t2.b) (\nPARTITION p1 VALUES LESS THAN (10),\nPARTITION p2 VALUES LESS THAN (20)\n) select * from t2", length=141, parser_state=0x7f8b90b0c4c8) at /home/midenok/src/mariadb/10.6/src/sql/sql_parse.cc:7924
(rr) pitem item_ptr
$7 = 0x21837f0 <dbug_item_print_buf> "t2.b"

Cause

In good part_expr is set directly from parser expression because of this hack:

  if (is_create_table_ind && old_lex->sql_command == SQLCOM_CREATE_TABLE)
  {
    /*
      When we come here we are doing a create table. In this case we
      have already done some preparatory work on the old part_info
      object. We don't really need this new partition_info object.
      Thus we go back to the old partition info object.
      We need to free any memory objects allocated on item_free_list
      by the parser since we are keeping the old info from the first
      parser call in CREATE TABLE.

      This table object can not be used any more. However, since
      this is CREATE TABLE, we know that it will be destroyed by the
      caller, and rely on that.
    */
    thd->free_items();
    part_info= thd->work_part_info;
    *work_part_info_used= true;
  }

The goal is to remove this hack.

Bad

#0  TABLE_SHARE::unpack_partition (this=0x7f3ee00e9800, thd=0x7f3eb8000d48, default_db_type=0x3c7e688) at /home/midenok/src/mariadb/10.6b/src/sql/sql_partition.cc:4387
#1  0x0000000000a82909 in TABLE_SHARE::init_from_binary_frm_image (this=0x7f3ee00e9800, thd=0x7f3eb8000d48, write=true, frm_image=0x7f3eb8948728 "\376\001\n\024\032", frm_length=578, par_image=0x0, par_length=0) at /home/midenok/src/mariadb/10.6b/src/sql/table.cc:1955
#2  0x0000000000d08944 in ha_create_table (thd=0x7f3eb8000d48, path=0x7f3ee00eb450 "./test/t1", db=0x7f3eb80139a0 "test", table_name=0x7f3eb80140b0 "t1", create_info=0x7f3ee00ecf38, alter_info=0x7f3ee00ece48, frm=0x7f3ee00eb430, fk_update_refs=true) at /home/midenok/src/mariadb/10.6b/src/sql/handler.cc:5560
#3  0x0000000000a11273 in create_table_impl (thd=0x7f3eb8000d48, ddl_log_state_create=0x7f3eb8017880, ddl_log_state_rm=0x7f3eb8017890, orig_db=..., orig_table_name=..., db=..., table_name=..., new_name=..., path=..., options=..., create_info=0x7f3ee00ecf38, alter_info=0x7f3ee00ece48, create_table_mode=1, is_trans=0x0, key_info=0x7f3ee00eb660, key_count=0x7f3ee00eb65c, foreign_keys=..., referenced_keys=..., frm=0x7f3ee00eb430) at /home/midenok/src/mariadb/10.6b/src/sql/sql_table.cc:4465
#4  0x0000000000a10139 in mysql_create_table_no_lock (thd=0x7f3eb8000d48, ddl_log_state_create=0x7f3eb8017880, ddl_log_state_rm=0x7f3eb8017890, db=0x7f3eb8023708, table_name=0x7f3eb8023718, create_info=0x7f3ee00ecf38, alter_info=0x7f3ee00ece48, is_trans=0x0, create_table_mode=1, table_list=0x7f3eb80236f0) at /home/midenok/src/mariadb/10.6b/src/sql/sql_table.cc:4565
#5  0x00000000008af8f5 in select_create::create_table_from_items (this=0x7f3eb8017780, thd=0x7f3eb8000d48, items=0x7f3ee00ec3e8, lock=0x7f3ee00ec3e0, hooks=0x7f3ee00ec388) at /home/midenok/src/mariadb/10.6b/src/sql/sql_insert.cc:4493
#6  0x00000000008b0186 in select_create::prepare (this=0x7f3eb8017780, _values=..., u=0x7f3eb8004f08) at /home/midenok/src/mariadb/10.6b/src/sql/sql_insert.cc:4695
#7  0x00000000009594d7 in JOIN::prepare (this=0x7f3eb8945be0, tables_init=0x7f3eb801bfa0, conds_init=0x0, og_num=0, order_init=0x0, skip_order_by=false, group_init=0x0, having_init=0x0, proc_param_init=0x0, select_lex_arg=0x7f3eb8012600, unit_arg=0x7f3eb8004f08) at /home/midenok/src/mariadb/10.6b/src/sql/sql_select.cc:1519
#8  0x00000000009535f2 in mysql_select (thd=0x7f3eb8000d48, tables=0x7f3eb801bfa0, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2201171004160, result=0x7f3eb8017780, unit=0x7f3eb8004f08, select_lex=0x7f3eb8012600) at /home/midenok/src/mariadb/10.6b/src/sql/sql_select.cc:4672
#9  0x0000000000952f3d in handle_select (thd=0x7f3eb8000d48, lex=0x7f3eb8004e40, result=0x7f3eb8017780, setup_tables_done_option=0) at /home/midenok/src/mariadb/10.6b/src/sql/sql_select.cc:429
#10 0x0000000000a2e721 in Sql_cmd_create_table_like::execute (this=0x7f3eb801a600, thd=0x7f3eb8000d48) at /home/midenok/src/mariadb/10.6b/src/sql/sql_table.cc:11540
#11 0x000000000090a93e in mysql_execute_command (thd=0x7f3eb8000d48) at /home/midenok/src/mariadb/10.6b/src/sql/sql_parse.cc:5876
#12 0x00000000008fb5f1 in mysql_parse (thd=0x7f3eb8000d48, rawbuf=0x7f3eb8017540 "create table t1 (b int)\nPARTITION BY RANGE (t2.b) (\nPARTITION p1 VALUES LESS THAN (10),\nPARTITION p2 VALUES LESS THAN (20)\n) select * from t2", length=141, parser_state=0x7f3ee00ef4f8) at /home/midenok/src/mariadb/10.6b/src/sql/sql_parse.cc:7902
(rr) p part_sql.str
$2 = 0x7f3eb801a890 " PARTITION BY RANGE (`b`)\n(PARTITION `p1` VALUES LESS THAN (10) ENGINE = MyISAM,\n PARTITION `p2` VALUES LESS THAN (20) ENGINE = MyISAM)"

part_sql already corrected the expression from t2.b to b.

part_sql written to frm

#0  build_frm_image (thd=0x7f3eb8000d48, table=..., create_info=0x7f3ee00ecf38, create_fields=..., keys=0, key_info=0x7f3eb8946e10, foreign_keys=..., referenced_keys=..., db_file=0x7f3eb8946e50) at /home/midenok/src/mariadb/10.6b/src/sql/unireg.cc:584
#1  0x0000000000a0fd57 in mysql_create_frm_image (thd=0x7f3eb8000d48, db=..., table_name=..., new_db=..., new_table_name=..., create_info=0x7f3ee00ecf38, alter_info=0x7f3ee00ece48, create_table_mode=1, key_info=0x7f3ee00eb660, key_count=0x7f3ee00eb65c, foreign_keys=..., referenced_keys=..., frm=0x7f3ee00eb430) at /home/midenok/src/mariadb/10.6b/src/sql/sql_table.cc:4138
#2  0x0000000000a1115a in create_table_impl (thd=0x7f3eb8000d48, ddl_log_state_create=0x7f3eb8017880, ddl_log_state_rm=0x7f3eb8017890, orig_db=..., orig_table_name=..., db=..., table_name=..., new_name=..., path=..., options=..., create_info=0x7f3ee00ecf38, alter_info=0x7f3ee00ece48, create_table_mode=1, is_trans=0x0, key_info=0x7f3ee00eb660, key_count=0x7f3ee00eb65c, foreign_keys=..., referenced_keys=..., frm=0x7f3ee00eb430) at /home/midenok/src/mariadb/10.6b/src/sql/sql_table.cc:4441
#3  0x0000000000a10139 in mysql_create_table_no_lock (thd=0x7f3eb8000d48, ddl_log_state_create=0x7f3eb8017880, ddl_log_state_rm=0x7f3eb8017890, db=0x7f3eb8023708, table_name=0x7f3eb8023718, create_info=0x7f3ee00ecf38, alter_info=0x7f3ee00ece48, is_trans=0x0, create_table_mode=1, table_list=0x7f3eb80236f0) at /home/midenok/src/mariadb/10.6b/src/sql/sql_table.cc:4565
#4  0x00000000008af8f5 in select_create::create_table_from_items (this=0x7f3eb8017780, thd=0x7f3eb8000d48, items=0x7f3ee00ec3e8, lock=0x7f3ee00ec3e0, hooks=0x7f3ee00ec388) at /home/midenok/src/mariadb/10.6b/src/sql/sql_insert.cc:4493
#5  0x00000000008b0186 in select_create::prepare (this=0x7f3eb8017780, _values=..., u=0x7f3eb8004f08) at /home/midenok/src/mariadb/10.6b/src/sql/sql_insert.cc:4695
#6  0x00000000009594d7 in JOIN::prepare (this=0x7f3eb8945be0, tables_init=0x7f3eb801bfa0, conds_init=0x0, og_num=0, order_init=0x0, skip_order_by=false, group_init=0x0, having_init=0x0, proc_param_init=0x0, select_lex_arg=0x7f3eb8012600, unit_arg=0x7f3eb8004f08) at /home/midenok/src/mariadb/10.6b/src/sql/sql_select.cc:1519
#7  0x00000000009535f2 in mysql_select (thd=0x7f3eb8000d48, tables=0x7f3eb801bfa0, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2201171004160, result=0x7f3eb8017780, unit=0x7f3eb8004f08, select_lex=0x7f3eb8012600) at /home/midenok/src/mariadb/10.6b/src/sql/sql_select.cc:4672
#8  0x0000000000952f3d in handle_select (thd=0x7f3eb8000d48, lex=0x7f3eb8004e40, result=0x7f3eb8017780, setup_tables_done_option=0) at /home/midenok/src/mariadb/10.6b/src/sql/sql_select.cc:429
#9  0x0000000000a2e721 in Sql_cmd_create_table_like::execute (this=0x7f3eb801a600, thd=0x7f3eb8000d48) at /home/midenok/src/mariadb/10.6b/src/sql/sql_table.cc:11540
#10 0x000000000090a93e in mysql_execute_command (thd=0x7f3eb8000d48) at /home/midenok/src/mariadb/10.6b/src/sql/sql_parse.cc:5876
#11 0x00000000008fb5f1 in mysql_parse (thd=0x7f3eb8000d48, rawbuf=0x7f3eb8017540 "create table t1 (b int)\nPARTITION BY RANGE (t2.b) (\nPARTITION p1 VALUES LESS THAN (10),\nPARTITION p2 VALUES LESS THAN (20)\n) select * from t2", length=141, parser_state=0x7f3ee00ef4f8) at /home/midenok/src/mariadb/10.6b/src/sql/sql_parse.cc:7902
579       if (part_info)
580       {
581         char auto_partitioned= part_info->is_auto_partitioned ? 1 : 0;
582         int4store(pos, part_info->part_info_len);
583         pos+= 4;
584         memcpy(pos, part_info->part_info_string, part_info->part_info_len + 1);
585         pos+= part_info->part_info_len + 1;
586         *pos++= auto_partitioned;
587       }

part_info_string generated

#0  Item::print_for_table_def (this=0x7f3eb8010f80, str=0x7f3ee00e9998) at /home/midenok/src/mariadb/10.6b/src/sql/item.h:1883
#1  0x0000000000f4282a in generate_partition_syntax (thd=0x7f3eb8000d48, part_info=0x7f3eb80195b0, buf_length=0x7f3ee00ea32c, show_partition_options=true, create_info=0x7f3ee00ecf38, alter_info=0x7f3ee00ece48) at /home/midenok/src/mariadb/10.6b/src/sql/sql_partition.cc:2587
#2  0x0000000000f41fd1 in generate_partition_syntax_for_frm (thd=0x7f3eb8000d48, part_info=0x7f3eb80195b0, buf_length=0x7f3ee00ea32c, create_info=0x7f3ee00ecf38, alter_info=0x7f3ee00ece48) at /home/midenok/src/mariadb/10.6b/src/sql/sql_partition.cc:2473
#3  0x0000000000a0f6cb in mysql_create_frm_image (thd=0x7f3eb8000d48, db=..., table_name=..., new_db=..., new_table_name=..., create_info=0x7f3ee00ecf38, alter_info=0x7f3ee00ece48, create_table_mode=1, key_info=0x7f3ee00eb660, key_count=0x7f3ee00eb65c, foreign_keys=..., referenced_keys=..., frm=0x7f3ee00eb430) at /home/midenok/src/mariadb/10.6b/src/sql/sql_table.cc:4063
#4  0x0000000000a1115a in create_table_impl (thd=0x7f3eb8000d48, ddl_log_state_create=0x7f3eb8017880, ddl_log_state_rm=0x7f3eb8017890, orig_db=..., orig_table_name=..., db=..., table_name=..., new_name=..., path=..., options=..., create_info=0x7f3ee00ecf38, alter_info=0x7f3ee00ece48, create_table_mode=1, is_trans=0x0, key_info=0x7f3ee00eb660, key_count=0x7f3ee00eb65c, foreign_keys=..., referenced_keys=..., frm=0x7f3ee00eb430) at /home/midenok/src/mariadb/10.6b/src/sql/sql_table.cc:4441
#5  0x0000000000a10139 in mysql_create_table_no_lock (thd=0x7f3eb8000d48, ddl_log_state_create=0x7f3eb8017880, ddl_log_state_rm=0x7f3eb8017890, db=0x7f3eb8023708, table_name=0x7f3eb8023718, create_info=0x7f3ee00ecf38, alter_info=0x7f3ee00ece48, is_trans=0x0, create_table_mode=1, table_list=0x7f3eb80236f0) at /home/midenok/src/mariadb/10.6b/src/sql/sql_table.cc:4565
#6  0x00000000008af8f5 in select_create::create_table_from_items (this=0x7f3eb8017780, thd=0x7f3eb8000d48, items=0x7f3ee00ec3e8, lock=0x7f3ee00ec3e0, hooks=0x7f3ee00ec388) at /home/midenok/src/mariadb/10.6b/src/sql/sql_insert.cc:4493
#7  0x00000000008b0186 in select_create::prepare (this=0x7f3eb8017780, _values=..., u=0x7f3eb8004f08) at /home/midenok/src/mariadb/10.6b/src/sql/sql_insert.cc:4695
#8  0x00000000009594d7 in JOIN::prepare (this=0x7f3eb8945be0, tables_init=0x7f3eb801bfa0, conds_init=0x0, og_num=0, order_init=0x0, skip_order_by=false, group_init=0x0, having_init=0x0, proc_param_init=0x0, select_lex_arg=0x7f3eb8012600, unit_arg=0x7f3eb8004f08) at /home/midenok/src/mariadb/10.6b/src/sql/sql_select.cc:1519
#9  0x00000000009535f2 in mysql_select (thd=0x7f3eb8000d48, tables=0x7f3eb801bfa0, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2201171004160, result=0x7f3eb8017780, unit=0x7f3eb8004f08, select_lex=0x7f3eb8012600) at /home/midenok/src/mariadb/10.6b/src/sql/sql_select.cc:4672
#10 0x0000000000952f3d in handle_select (thd=0x7f3eb8000d48, lex=0x7f3eb8004e40, result=0x7f3eb8017780, setup_tables_done_option=0) at /home/midenok/src/mariadb/10.6b/src/sql/sql_select.cc:429
#11 0x0000000000a2e721 in Sql_cmd_create_table_like::execute (this=0x7f3eb801a600, thd=0x7f3eb8000d48) at /home/midenok/src/mariadb/10.6b/src/sql/sql_table.cc:11540
#12 0x000000000090a93e in mysql_execute_command (thd=0x7f3eb8000d48) at /home/midenok/src/mariadb/10.6b/src/sql/sql_parse.cc:5876
#13 0x00000000008fb5f1 in mysql_parse (thd=0x7f3eb8000d48, rawbuf=0x7f3eb8017540 "create table t1 (b int)\nPARTITION BY RANGE (t2.b) (\nPARTITION p1 VALUES LESS THAN (10),\nPARTITION p2 VALUES LESS THAN (20)\n) select * from t2", length=141, parser_state=0x7f3ee00ef4f8) at /home/midenok/src/mariadb/10.6b/src/sql/sql_parse.cc:7902
1873      /**
1874        This helper is used to print expressions as a part of a table definition,
1875        in particular for
1876          - generated columns
1877          - check constraints
1878          - default value expressions
1879          - partitioning expressions
1880      */
1881      void print_for_table_def(String *str)
1882      {
1883        print_parenthesised(str,
1884                         (enum_query_type)(QT_ITEM_ORIGINAL_FUNC_NULLIF |
1885                                           QT_ITEM_IDENT_SKIP_DB_NAMES |
1886                                           QT_ITEM_IDENT_SKIP_TABLE_NAMES |
1887                                           QT_NO_DATA_EXPANSION |
1888                                           QT_TO_SYSTEM_CHARSET),
1889                         LOWEST_PRECEDENCE);
1890      }

Cause

print_for_table_def() uses flag QT_ITEM_IDENT_SKIP_TABLE_NAMES.

midenok commented 3 years ago

Tests failing so far

innodb_zip.restart main.partition_exchange main.foreign_key innodb.alter_partitioned \
main.partition_explicit_prune vcol.vcol_partition_myisam main.partition_range \
main.partition_innodb_plugin parts.longname parts.partition_alter_instant \
parts.partition_exchange_innodb parts.percona_nonflushing_analyze_debug \
vcol.vcol_partition_innodb main.partition_bug18198 main.partition_error \
main.partition_pruning parts.partition_exchange_memory parts.partition_exchange_myisam \
innodb.instant_alter_crash

Partitioning tests failing

Due to a bug:

vcol.vcol_partition_myisam main.partition_bug18198 \
main.partition_range main.partition_error parts.percona_nonflushing_analyze_debug \
main.partition_innodb_plugin main.partition_explicit_prune vcol.vcol_partition_innodb

Due to foreign keys:

innodb.alter_partitioned parts.longname
midenok commented 3 years ago

Info

int TABLE_SHARE::read_frm_image(const uchar **frm, size_t *len)
{
  if (IF_PARTITIONING(part_sql.str, 0))   // cannot discover a partition
  {
    DBUG_ASSERT(db_type()->discover_table == 0);
    return 1;
  }

Was made for

commit e06cb31719ce31fb1cd7944d1de86d4de9e3eca6
Author: Sergei Golubchik <sergii@pisem.net>
Date:   Tue Apr 9 15:57:09 2013 +0200

    CREATE TABLE and frm-less discovering engines.
    Now CREATE TABLE does not write the frm file on disk,
    if the engine can discover it

Tests affected

archive.archive
midenok commented 3 years ago

Bug: connect.part_table fails

Result

CURRENT_TEST: connect.part_table
mysqltest: At line 76: query 'UPDATE t1 SET msg = 'number' WHERE id in (60,72)' failed: 1105: xt3: (1105) Index is not unique

Warning pushed

#3  0x0000000000888a56 in Diagnostics_area::push_warning (this=0x7f82580069e8, thd=0x7f8258000d88, sql_errno_arg=1105, sqlstate=0x18c893a "HY000", level=Sql_state_errno_level::WARN_LEVEL_WARN, ucid=..., msg=0x7f825806e9e8 "Index is not unique") at /home/midenok/src/mariadb/10.6b/src/sql/sql_error.h:1176
#4  0x000000000086fd8f in THD::raise_condition (this=0x7f8258000d88, sql_errno=1105, sqlstate=0x18c893a "HY000", level=Sql_state_errno_level::WARN_LEVEL_WARN, ucid=..., msg=0x7f825806e9e8 "Index is not unique") at /home/midenok/src/mariadb/10.6b/src/sql/sql_class.cc:1186
#5  0x0000000000789d6d in THD::raise_condition (this=0x7f8258000d88, sql_errno=0, sqlstate=0x0, level=Sql_state_errno_level::WARN_LEVEL_WARN, msg=0x7f825806e9e8 "Index is not unique") at /home/midenok/src/mariadb/10.6b/src/sql/sql_class.h:5053
#6  0x000000000089fea1 in push_warning (thd=0x7f8258000d88, level=Sql_state_errno_level::WARN_LEVEL_WARN, code=0, msg=0x7f825806e9e8 "Index is not unique") at /home/midenok/src/mariadb/10.6b/src/sql/sql_error.cc:714
#7  0x000000000116f62b in ha_connect::external_lock (this=0x7f825401d060, thd=0x7f8258000d88, lock_type=2) at /home/midenok/src/mariadb/10.6b/src/storage/connect/ha_connect.cc:4960
#8  0x0000000000d02e5c in handler::ha_external_lock (this=0x7f825401d060, thd=0x7f8258000d88, lock_type=2) at /home/midenok/src/mariadb/10.6b/src/sql/handler.cc:6723
#9  0x0000000000a42ed2 in handler::ha_external_unlock (this=0x7f825401d060, thd=0x7f8258000d88) at /home/midenok/src/mariadb/10.6b/src/sql/handler.h:3423
#10 0x0000000000e8dda4 in unlock_external (thd=0x7f8258000d88, table=0x7f826802a290, count=1) at /home/midenok/src/mariadb/10.6b/src/sql/lock.cc:727
#11 0x0000000000e8df27 in mysql_unlock_tables (thd=0x7f8258000d88, sql_lock=0x7f826802a260, free_lock=false) at /home/midenok/src/mariadb/10.6b/src/sql/lock.cc:432
#12 0x0000000000e8e1be in mysql_unlock_tables (thd=0x7f8258000d88, sql_lock=0x7f826802a260) at /home/midenok/src/mariadb/10.6b/src/sql/lock.cc:415
#13 0x00000000008388ff in close_thread_tables (thd=0x7f8258000d88) at /home/midenok/src/mariadb/10.6b/src/sql/sql_base.cc:910
#14 0x000000000091050a in mysql_execute_command (thd=0x7f8258000d88) at /home/midenok/src/mariadb/10.6b/src/sql/sql_parse.cc:5942
#15 0x0000000000900c81 in mysql_parse (thd=0x7f8258000d88, rawbuf=0x7f8258011110 "UPDATE xt3 SET msg = 'number' WHERE id in (60,72)", length=49, parser_state=0x7f827857d4f8) at /home/midenok/src/mariadb/10.6b/src/sql/sql_parse.cc:7902

frame 7

4957        if (CloseTable(g)) {
4958          // This is an error while builing index
4959          // Make it a warning to avoid crash
4960          push_warning(thd, Sql_condition::WARN_LEVEL_WARN, 0, g->Message);
midenok commented 3 years ago

Return status for CloseTable() set to true

#0  XINDEX::Make (this=0x7f824c003848, g=0x7f825806e9d0, sxp=0x0) at /home/midenok/src/mariadb/10.6b/src/storage/connect/xindex.cpp:565
#1  0x00000000011a0d0b in TDBDOS::MakeIndex (this=0x7f824bfff480, g=0x7f825806e9d0, pxdf=0x7f824bfff188, add=false) at /home/midenok/src/mariadb/10.6b/src/storage/connect/tabdos.cpp:1774
#2  0x000000000119cdfc in TDBDOS::ResetTableOpt (this=0x7f824bfff480, g=0x7f825806e9d0, dop=true, dox=true) at /home/midenok/src/mariadb/10.6b/src/storage/connect/tabdos.cpp:628
#3  0x000000000117b583 in CntCloseTable (g=0x7f825806e9d0, tdbp=0x7f824bfff480, nox=false, abort=false) at /home/midenok/src/mariadb/10.6b/src/storage/connect/connect.cc:598
#4  0x000000000116502d in ha_connect::CloseTable (this=0x7f825401d060, g=0x7f825806e9d0) at /home/midenok/src/mariadb/10.6b/src/storage/connect/ha_connect.cc:2135
#5  0x000000000116f5f6 in ha_connect::external_lock (this=0x7f825401d060, thd=0x7f8258000d88, lock_type=2) at /home/midenok/src/mariadb/10.6b/src/storage/connect/ha_connect.cc:4957
#6  0x0000000000d02e5c in handler::ha_external_lock (this=0x7f825401d060, thd=0x7f8258000d88, lock_type=2) at /home/midenok/src/mariadb/10.6b/src/sql/handler.cc:6723
#7  0x0000000000a42ed2 in handler::ha_external_unlock (this=0x7f825401d060, thd=0x7f8258000d88) at /home/midenok/src/mariadb/10.6b/src/sql/handler.h:3423
#8  0x0000000000e8dda4 in unlock_external (thd=0x7f8258000d88, table=0x7f826802a290, count=1) at /home/midenok/src/mariadb/10.6b/src/sql/lock.cc:727
#9  0x0000000000e8df27 in mysql_unlock_tables (thd=0x7f8258000d88, sql_lock=0x7f826802a260, free_lock=false) at /home/midenok/src/mariadb/10.6b/src/sql/lock.cc:432
#10 0x0000000000e8e1be in mysql_unlock_tables (thd=0x7f8258000d88, sql_lock=0x7f826802a260) at /home/midenok/src/mariadb/10.6b/src/sql/lock.cc:415
#11 0x00000000008388ff in close_thread_tables (thd=0x7f8258000d88) at /home/midenok/src/mariadb/10.6b/src/sql/sql_base.cc:910
#12 0x000000000091050a in mysql_execute_command (thd=0x7f8258000d88) at /home/midenok/src/mariadb/10.6b/src/sql/sql_parse.cc:5942
#13 0x0000000000900c81 in mysql_parse (thd=0x7f8258000d88, rawbuf=0x7f8258011110 "UPDATE xt3 SET msg = 'number' WHERE id in (60,72)", length=49, parser_state=0x7f827857d4f8) at /home/midenok/src/mariadb/10.6b/src/sql/sql_parse.cc:7902
560       // Check whether the unique index is unique indeed
561       if (!Mul)
562       {
563         if (Ndif < Num_K) {
564           strcpy(g->Message, MSG(INDEX_NOT_UNIQ));
565           brc = true;
566           goto err;
(rr) p Ndif
$32 = 3
(rr) p Num_K
$33 = 6

Good

Num_K is 3

midenok commented 3 years ago

Num_K assigned

518       if ((Num_K = nkey) < n) {
519         PlgDBrealloc(g, NULL, Record, Num_K * sizeof(int));
(rr) p nkey
$34 = 6

Good

nkey is 3

nkey changed

441       /*********************************************************************/
442       /*  Standard init: read the file and construct the index table.      */
443       /*  Note: reading will be sequential as To_Kindex is not set.        */
444       /*********************************************************************/
445       for (i = nkey = 0; rc != RC_EF; i++) {
...
452
453         /*******************************************************************/
454         /*  Read a valid record from table file.                           */
455         /*******************************************************************/
456         rc = Tdbp->ReadDB(g);
...
507         nkey++;                    // A new valid key was found
508         } // endfor i
midenok commented 3 years ago

First failure in test

--- /home/midenok/src/mariadb/10.6b/src/storage/connect/mysql-test/connect/r/part_table.result  2019-09-06 11:31:16.836801815 +0300
+++ /home/midenok/src/mariadb/10.6b/src/storage/connect/mysql-test/connect/r/part_table.reject  2021-03-13 16:38:21.378733432 +0300
@@ -48,7 +48,10 @@
 partition_name table_rows
 1      4
 2      4
-3      3
+3      0
+Warnings:
+Warning        1105    Open(rb) error 2 on /home/midenok/src/mariadb/10.6b/build/mysql-test/var/mysqld.1/data/./test/3.csv: No such file or directory
+Warning        1105    Open(rb) error 2 on /home/midenok/src/mariadb/10.6b/build/mysql-test/var/mysqld.1/data/./test/3.csv: No such file or directory
 SELECT * FROM t1;
 id     msg
 4      four
CREATE TABLE t1 (
id INT NOT NULL,
msg VARCHAR(32))
ENGINE=CONNECT TABLE_TYPE=PROXY TABNAME='xt%s'
PARTITION BY RANGE COLUMNS(id) (
PARTITION `1` VALUES LESS THAN(10),
PARTITION `2` VALUES LESS THAN(50),
PARTITION `3` VALUES LESS THAN(MAXVALUE));
Warnings:
Warning 1105    Data repartition in 1 is unchecked
Warning 1105    Data repartition in 2 is unchecked
Warning 1105    Data repartition in 3 is unchecked
SELECT partition_name, table_rows FROM information_schema.partitions WHERE table_name = 't1';
partition_name  table_rows
1   4
2   4
3   3
midenok commented 3 years ago

Bad

#0  DOSFAM::OpenTableFile (this=0x7fe387726700, g=0x7fe39007ebc0) at /home/midenok/src/mariadb/10.6b/src/storage/connect/filamtxt.cpp:605
#1  0x00000000011a277a in TDBDOS::OpenDB (this=0x7fe3877267f0, g=0x7fe39007ebc0) at /home/midenok/src/mariadb/10.6b/src/storage/connect/tabdos.cpp:2178
#2  0x00000000011af32a in TDBCSV::OpenDB (this=0x7fe3877267f0, g=0x7fe39007ebc0) at /home/midenok/src/mariadb/10.6b/src/storage/connect/tabfmt.cpp:825
#3  0x00000000011d32a7 in TDBPRX::OpenDB (this=0x7fe387726378, g=0x7fe39007ebc0) at /home/midenok/src/mariadb/10.6b/src/storage/connect/tabutil.cpp:595
#4  0x000000000117a73f in CntOpenTable (g=0x7fe39007ebc0, tdbp=0x7fe387726378, mode=MODE_READ, c1=0x7fe387727080 "id", c2=0x0, del=false) at /home/midenok/src/mariadb/10.6b/src/storage/connect/connect.cc:349
#5  0x0000000001164af1 in ha_connect::OpenTable (this=0x7fe3900a7620, g=0x7fe39007ebc0, del=false) at /home/midenok/src/mariadb/10.6b/src/storage/connect/ha_connect.cc:2056
#6  0x000000000116c7d5 in ha_connect::rnd_init (this=0x7fe3900a7620, scan=true) at /home/midenok/src/mariadb/10.6b/src/storage/connect/ha_connect.cc:4109
#7  0x00000000008a6a38 in handler::ha_rnd_init (this=0x7fe3900a7620, scan=true) at /home/midenok/src/mariadb/10.6b/src/sql/handler.h:3389
#8  0x00000000010b80ae in ha_partition::rnd_init (this=0x7fe3900a59f0, scan=true) at /home/midenok/src/mariadb/10.6b/src/sql/ha_partition.cc:5113
#9  0x00000000008a6a38 in handler::ha_rnd_init (this=0x7fe3900a59f0, scan=true) at /home/midenok/src/mariadb/10.6b/src/sql/handler.h:3389
#10 0x0000000000d072c9 in handler::ha_rnd_init_with_error (this=0x7fe3900a59f0, scan=true) at /home/midenok/src/mariadb/10.6b/src/sql/handler.cc:3299
#11 0x0000000000f13f8e in init_read_record (info=0x7fe390085518, thd=0x7fe390000d48, table=0x7fe3900a55e8, select=0x7fe39001cc10, filesort=0x0, use_record_cache=1, print_error=true, disable_rr_cache=false) at /home/midenok/src/mariadb/10.6b/src/sql/records.cc:328
#12 0x000000000097f30b in join_init_read_record (tab=0x7fe390085450) at /home/midenok/src/mariadb/10.6b/src/sql/sql_select.cc:21603
#13 0x00000000009a3745 in sub_select (join=0x7fe39008b7a0, join_tab=0x7fe390085450, end_of_records=false) at /home/midenok/src/mariadb/10.6b/src/sql/sql_select.cc:20639
#14 0x0000000000983826 in do_select (join=0x7fe39008b7a0, procedure=0x0) at /home/midenok/src/mariadb/10.6b/src/sql/sql_select.cc:20189
#15 0x00000000009824d5 in JOIN::exec_inner (this=0x7fe39008b7a0) at /home/midenok/src/mariadb/10.6b/src/sql/sql_select.cc:4500
#16 0x0000000000981225 in JOIN::exec (this=0x7fe39008b7a0) at /home/midenok/src/mariadb/10.6b/src/sql/sql_select.cc:4278
#17 0x0000000000958dcb in mysql_select (thd=0x7fe390000d48, tables=0x7fe390088cb0, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147748608, result=0x7fe39008fe30, unit=0x7fe390004f08, select_lex=0x7fe390023670) at /home/midenok/src/mariadb/10.6b/src/sql/sql_select.cc:4696
#18 0x00000000009585cd in handle_select (thd=0x7fe390000d48, lex=0x7fe390004e40, result=0x7fe39008fe30, setup_tables_done_option=0) at /home/midenok/src/mariadb/10.6b/src/sql/sql_select.cc:429
#19 0x00000000009122be in execute_sqlcom_select (thd=0x7fe390000d48, all_tables=0x7fe390088cb0) at /home/midenok/src/mariadb/10.6b/src/sql/sql_parse.cc:6134
#20 0x0000000000907e7c in mysql_execute_command (thd=0x7fe390000d48) at /home/midenok/src/mariadb/10.6b/src/sql/sql_parse.cc:3830
#21 0x0000000000900c81 in mysql_parse (thd=0x7fe390000d48, rawbuf=0x7fe390068480 "SELECT * FROM t1", length=16, parser_state=0x7fe3a044b4f8) at /home/midenok/src/mariadb/10.6b/src/sql/sql_parse.cc:7902
(rr) p filename
$16 = "/home/midenok/src/mariadb/10.6b/build/mysql-test/var/mysqld.1/data/./test/3.csv", '\000' <repeats 4016 times>

Good

(rr) p filename
$8 = "/home/midenok/src/mariadb/10.5b/build/mysql-test/var/mysqld.1/data/./test/xt3.csv", '\000' <repeats
 4014 times>

Cause

Wrong filename "3.csv" instead of "xt3.csv".

midenok commented 3 years ago

Bad: IsPartitioned() returns true

#0  ha_connect::IsPartitioned (this=0x7fe3900a7620) at /home/midenok/src/mariadb/10.6b/src/storage/connect/ha_connect.cc:1854
#1  0x0000000001164379 in ha_connect::GetPartName (this=0x7fe3900a7620) at /home/midenok/src/mariadb/10.6b/src/storage/connect/ha_connect.cc:1875
\#2  0x0000000001197bd2 in RELDEF::GetStringCatInfo (this=0x7fe387726448, g=0x7fe39007ebc0, what=0x1ab4e66 "Filename", sdef=0x0) at /home/midenok/src/mariadb/10.6b/src/storage/connect/reldef.cpp:278
#3  0x000000000119a7cc in DOSDEF::DefineAM (this=0x7fe387726448, g=0x7fe39007ebc0, am=0x1ac308b "CSV") at /home/midenok/src/mariadb/10.6b/src/storage/connect/tabdos.cpp:147
#4  0x00000000011ad990 in CSVDEF::DefineAM (this=0x7fe387726448, g=0x7fe39007ebc0, am=0x7fe3900902d0 "CSV", poff=0) at /home/midenok/src/mariadb/10.6b/src/storage/connect/tabfmt.cpp:480
#5  0x0000000001197fea in TABDEF::Define (this=0x7fe387726448, g=0x7fe39007ebc0, cat=0x7fe3900153d0, name=0x7fe387726438 "xt3", schema=0x7fe387726440 "test", am=0x7fe3900902d0 "CSV") at /home/midenok/src/mariadb/10.6b/src/storage/connect/reldef.cpp:369
#6  0x000000000117e2c0 in MYCAT::MakeTableDesc (this=0x7fe3900153d0, g=0x7fe39007ebc0, tablep=0x7fe3877261a0, am=0x7fe3900902d0 "CSV") at /home/midenok/src/mariadb/10.6b/src/storage/connect/mycat.cc:488
#7  0x000000000117d720 in MYCAT::GetTableDesc (this=0x7fe3900153d0, g=0x7fe39007ebc0, tablep=0x7fe3877261a0, type=0x0) at /home/midenok/src/mariadb/10.6b/src/storage/connect/mycat.cc:403
#8  0x000000000117e380 in MYCAT::GetTable (this=0x7fe3900153d0, g=0x7fe39007ebc0, tablep=0x7fe3877261a0, mode=MODE_READ, type=0x0) at /home/midenok/src/mariadb/10.6b/src/storage/connect/mycat.cc:510
#9  0x00000000011d2c16 in TDBPRX::GetSubTable (this=0x7fe387726378, g=0x7fe39007ebc0, tabp=0x7fe3877261a0, b=false) at /home/midenok/src/mariadb/10.6b/src/storage/connect/tabutil.cpp:458
#10 0x00000000011d2dd3 in TDBPRX::InitTable (this=0x7fe387726378, g=0x7fe39007ebc0) at /home/midenok/src/mariadb/10.6b/src/storage/connect/tabutil.cpp:490
#11 0x00000000011d2f16 in TDBPRX::Cardinality (this=0x7fe387726378, g=0x7fe39007ebc0) at /home/midenok/src/mariadb/10.6b/src/storage/connect/tabutil.cpp:513
#12 0x000000000117991b in CntInfo (g=0x7fe39007ebc0, tp=0x7fe387726378, info=0x7fe3900a7ea8) at /home/midenok/src/mariadb/10.6b/src/storage/connect/connect.cc:173
#13 0x000000000116a77b in ha_connect::info (this=0x7fe3900a7620, flag=18) at /home/midenok/src/mariadb/10.6b/src/storage/connect/ha_connect.cc:4359
#14 0x00000000010c4983 in ha_partition::info (this=0x7fe3900a59f0, flag=18) at /home/midenok/src/mariadb/10.6b/src/sql/ha_partition.cc:8397
#15 0x0000000000aa6c66 in TABLE_LIST::fetch_number_of_rows (this=0x7fe390088cb0) at /home/midenok/src/mariadb/10.6b/src/sql/table.cc:9238
#16 0x000000000096a746 in make_join_statistics (join=0x7fe39008b7a0, tables_list=..., keyuse_array=0x7fe39008ba98) at /home/midenok/src/mariadb/10.6b/src/sql/sql_select.cc:4924
#17 0x0000000000966f0e in JOIN::optimize_inner (this=0x7fe39008b7a0) at /home/midenok/src/mariadb/10.6b/src/sql/sql_select.cc:2277
#18 0x0000000000961851 in JOIN::optimize (this=0x7fe39008b7a0) at /home/midenok/src/mariadb/10.6b/src/sql/sql_select.cc:1643
#19 0x0000000000958ce0 in mysql_select (thd=0x7fe390000d48, tables=0x7fe390088cb0, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147748608, result=0x7fe39008fe30, unit=0x7fe390004f08, select_lex=0x7fe390023670) at /home/midenok/src/mariadb/10.6b/src/sql/sql_select.cc:4682
#20 0x00000000009585cd in handle_select (thd=0x7fe390000d48, lex=0x7fe390004e40, result=0x7fe39008fe30, setup_tables_done_option=0) at /home/midenok/src/mariadb/10.6b/src/sql/sql_select.cc:429
#21 0x00000000009122be in execute_sqlcom_select (thd=0x7fe390000d48, all_tables=0x7fe390088cb0) at /home/midenok/src/mariadb/10.6b/src/sql/sql_parse.cc:6134
#22 0x0000000000907e7c in mysql_execute_command (thd=0x7fe390000d48) at /home/midenok/src/mariadb/10.6b/src/sql/sql_parse.cc:3830
#23 0x0000000000900c81 in mysql_parse (thd=0x7fe390000d48, rawbuf=0x7fe390068480 "SELECT * FROM t1", length=16, parser_state=0x7fe3a044b4f8) at /home/midenok/src/mariadb/10.6b/src/sql/sql_parse.cc:7902
1849    bool ha_connect::IsPartitioned(void)
1850    {
1851    #ifdef WITH_PARTITION_STORAGE_ENGINE
1852      if ((tshp && tshp->part_info) ||
1853          (table && table->part_info))
1854        return true;
1855      else
1856    #endif
(rr) p tshp
$26 = (TABLE_SHARE *) 0x7fe390085450
(rr) p tshp->part_info
$27 = (partition_info *) 0x0
(rr) p table
$28 = (TABLE *) 0x7fe3900a55e8
(rr) p table->part_info
$29 = (partition_info *) 0x7fe390084270

Good

1849    bool ha_connect::IsPartitioned(void)
1850    {
1851    #ifdef WITH_PARTITION_STORAGE_ENGINE
1852            if (tshp)
1853        return tshp->partition_info_str_len > 0;
1854      else if (table && table->part_info)
1855        return true;
1856      else
1857    #endif

Cause

Wrong if() conditions in IsPartitioned().

midenok commented 3 years ago

Bug: memory not freed

Warning: Memory not freed: 304
==642256== 32 bytes in 1 blocks are definitely lost in loss record 1 of 3
==642256==    at 0x483C7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==642256==    by 0x17D2D44: my_malloc (my_malloc.c:88)
==642256==    by 0xA01B8B: Binary_string::real_alloc(unsigned long) (sql_string.cc:46)
==642256==    by 0x79D00D: Binary_string::alloc(unsigned long) (sql_string.h:681)
==642256==    by 0xA02542: String::copy(char const*, unsigned long, charset_info_st const*, charset_info_st const*, unsigned int*) (sql_string.cc:463)
==642256==    by 0xA056C3: String::copy(String const*, charset_info_st const*, unsigned int*) (sql_string.h:902)
==642256==    by 0xD47F8F: Item_string::Item_string(THD*, String const*, charset_info_st const*, unsigned int*, Derivation, enum_repertoire_t) (item.h:4578)
==642256==    by 0xD23F67: Item::const_charset_converter(THD*, charset_info_st const*, bool, char const*) (item.cc:1360)
==642256==    by 0x7A3718: Item::const_charset_converter(THD*, charset_info_st const*, bool) (item.h:2475)
==642256==    by 0x7A3294: Item_string::safe_charset_converter(THD*, charset_info_st const*) (item.h:4625)
==642256==    by 0xF443AA: convert_charset_partition_constant(Item*, charset_info_st const*) (sql_partition.cc:148)
==642256==    by 0xAD9782: partition_info::get_column_item(Item*, Field*) (partition_info.cc:2030)
==642256==    by 0xAD992C: partition_info::fix_column_value_functions(THD*, p_elem_val*, unsigned int) (partition_info.cc:2087)
==642256==    by 0xF587C3: check_list_constants(THD*, partition_info*) (sql_partition.cc:1460)
==642256==    by 0xF4563E: fix_partition_func(THD*, TABLE*) (sql_partition.cc:2001)
==642256==    by 0xA94405: open_table_from_share(THD*, TABLE_SHARE*, st_mysql_const_lex_string const*, unsigned int, unsigned int, unsigned int, TABLE*, List<String>*) (table.cc:4072)
==642256==    by 0x83B263: open_table(THD*, TABLE_LIST*, Open_table_context*) (sql_base.cc:2000)
==642256==    by 0x840996: open_and_process_table(THD*, TABLE_LIST*, unsigned int*, unsigned int, Prelocking_strategy*, bool, Open_table_context*) (sql_base.cc:3849)
==642256==    by 0x83F2DF: open_tables(THD*, DDL_options_st const&, TABLE_LIST**, unsigned int*, unsigned int, Prelocking_strategy*) (sql_base.cc:4323)
==642256==    by 0x831ED5: open_tables(THD*, TABLE_LIST**, unsigned int*, unsigned int) (sql_base.h:477)
==642256==    by 0x9CC988: mysqld_show_create_get_fields(THD*, TABLE_LIST*, List<Item>*, String*) (sql_show.cc:1201)
==642256==    by 0x9CDC06: mysqld_show_create(THD*, TABLE_LIST*) (sql_show.cc:1308)
==642256==    by 0x9095B6: mysql_execute_command(THD*) (sql_parse.cc:4254)
==642256==    by 0x900C80: mysql_parse(THD*, char*, unsigned int, Parser_state*) (sql_parse.cc:7902)

==642256== 40 bytes in 1 blocks are definitely lost in loss record 2 of 3
==642256==    at 0x483C7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==642256==    by 0x17D2D44: my_malloc (my_malloc.c:88)
==642256==    by 0xA01B8B: Binary_string::real_alloc(unsigned long) (sql_string.cc:46)
==642256==    by 0x79D00D: Binary_string::alloc(unsigned long) (sql_string.h:681)
==642256==    by 0xA02542: String::copy(char const*, unsigned long, charset_info_st const*, charset_info_st const*, unsigned int*) (sql_string.cc:463)
==642256==    by 0xA056C3: String::copy(String const*, charset_info_st const*, unsigned int*) (sql_string.h:902)
==642256==    by 0xD47F8F: Item_string::Item_string(THD*, String const*, charset_info_st const*, unsigned int*, Derivation, enum_repertoire_t) (item.h:4578)
==642256==    by 0xD23F67: Item::const_charset_converter(THD*, charset_info_st const*, bool, char const*) (item.cc:1360)
==642256==    by 0x7A3718: Item::const_charset_converter(THD*, charset_info_st const*, bool) (item.h:2475)
==642256==    by 0x7A3294: Item_string::safe_charset_converter(THD*, charset_info_st const*) (item.h:4625)
==642256==    by 0xF443AA: convert_charset_partition_constant(Item*, charset_info_st const*) (sql_partition.cc:148)
==642256==    by 0xAD9782: partition_info::get_column_item(Item*, Field*) (partition_info.cc:2030)
==642256==    by 0xAD992C: partition_info::fix_column_value_functions(THD*, p_elem_val*, unsigned int) (partition_info.cc:2087)
==642256==    by 0xF587C3: check_list_constants(THD*, partition_info*) (sql_partition.cc:1460)
==642256==    by 0xF4563E: fix_partition_func(THD*, TABLE*) (sql_partition.cc:2001)
==642256==    by 0xA94405: open_table_from_share(THD*, TABLE_SHARE*, st_mysql_const_lex_string const*, unsigned int, unsigned int, unsigned int, TABLE*, List<String>*) (table.cc:4072)
==642256==    by 0x83B263: open_table(THD*, TABLE_LIST*, Open_table_context*) (sql_base.cc:2000)
==642256==    by 0x840996: open_and_process_table(THD*, TABLE_LIST*, unsigned int*, unsigned int, Prelocking_strategy*, bool, Open_table_context*) (sql_base.cc:3849)
==642256==    by 0x83F2DF: open_tables(THD*, DDL_options_st const&, TABLE_LIST**, unsigned int*, unsigned int, Prelocking_strategy*) (sql_base.cc:4323)
==642256==    by 0x8447E4: open_tables(THD*, TABLE_LIST**, unsigned int*, unsigned int, Prelocking_strategy*) (sql_base.h:263)
==642256==    by 0x844543: open_normal_and_derived_tables(THD*, TABLE_LIST*, unsigned int, unsigned int) (sql_base.cc:5364)
==642256==    by 0x844891: open_tables_only_view_structure(THD*, TABLE_LIST*, bool) (sql_base.cc:5415)
==642256==    by 0x9DA09C: fill_schema_table_by_open(THD*, st_mem_root*, bool, TABLE*, st_schema_table*, st_mysql_const_lex_string*, st_mysql_const_lex_string*, Open_tables_backup*, bool) (sql_show.cc:4700)
==642256==    by 0x9D9B2B: get_all_tables(THD*, TABLE_LIST*, Item*) (sql_show.cc:5336)
==642256==    by 0x9E5125: get_schema_tables_result(JOIN*, enum_schema_table_state) (sql_show.cc:8751)
==642256==    by 0x9820F6: JOIN::exec_inner() (sql_select.cc:4457)
==642256==    by 0x981224: JOIN::exec() (sql_select.cc:4278)
==642256==    by 0x958DCA: mysql_select(THD*, TABLE_LIST*, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*) (sql_select.cc:4696)
==642256==    by 0x9585CC: handle_select(THD*, LEX*, select_result*, unsigned long) (sql_select.cc:429)
==642256==    by 0x9122BD: execute_sqlcom_select(THD*, TABLE_LIST*) (sql_parse.cc:6134)
==642256==    by 0x907E7B: mysql_execute_command(THD*) (sql_parse.cc:3830)
==642256==    by 0x900C80: mysql_parse(THD*, char*, unsigned int, Parser_state*) (sql_parse.cc:7902)

==642256== 232 bytes in 7 blocks are definitely lost in loss record 3 of 3
==642256==    at 0x483C7F3: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==642256==    by 0x17D2D44: my_malloc (my_malloc.c:88)
==642256==    by 0xA01B8B: Binary_string::real_alloc(unsigned long) (sql_string.cc:46)
==642256==    by 0x79D00D: Binary_string::alloc(unsigned long) (sql_string.h:681)
==642256==    by 0xA02542: String::copy(char const*, unsigned long, charset_info_st const*, charset_info_st const*, unsigned int*) (sql_string.cc:463)
==642256==    by 0xA056C3: String::copy(String const*, charset_info_st const*, unsigned int*) (sql_string.h:902)
==642256==    by 0xD47F8F: Item_string::Item_string(THD*, String const*, charset_info_st const*, unsigned int*, Derivation, enum_repertoire_t) (item.h:4578)
==642256==    by 0xD23F67: Item::const_charset_converter(THD*, charset_info_st const*, bool, char const*) (item.cc:1360)
==642256==    by 0x7A3718: Item::const_charset_converter(THD*, charset_info_st const*, bool) (item.h:2475)
==642256==    by 0x7A3294: Item_string::safe_charset_converter(THD*, charset_info_st const*) (item.h:4625)
==642256==    by 0xF443AA: convert_charset_partition_constant(Item*, charset_info_st const*) (sql_partition.cc:148)
==642256==    by 0xAD9782: partition_info::get_column_item(Item*, Field*) (partition_info.cc:2030)
==642256==    by 0xAD992C: partition_info::fix_column_value_functions(THD*, p_elem_val*, unsigned int) (partition_info.cc:2087)
==642256==    by 0xF587C3: check_list_constants(THD*, partition_info*) (sql_partition.cc:1460)
==642256==    by 0xF4563E: fix_partition_func(THD*, TABLE*) (sql_partition.cc:2001)
==642256==    by 0xA94405: open_table_from_share(THD*, TABLE_SHARE*, st_mysql_const_lex_string const*, unsigned int, unsigned int, unsigned int, TABLE*, List<String>*) (table.cc:4072)
==642256==    by 0xD0E4D2: ha_create_table(THD*, char const*, char const*, char const*, HA_CREATE_INFO*, Alter_info*, st_mysql_const_unsigned_lex_string*, bool) (handler.cc:5581)
==642256==    by 0xA16BA2: create_table_impl(THD*, st_ddl_log_state*, st_ddl_log_state*, st_mysql_const_lex_string const&, st_mysql_const_lex_string const&, st_mysql_const_lex_string const&, st_mysql_const_lex_string const&, st_mysql_const_lex_string const&, st_mysql_const_lex_string const&, DDL_options_st, HA_CREATE_INFO*, Alter_info*, int, bool*, st_key**, unsigned int*, FK_list&, FK_list&, st_mysql_const_unsigned_lex_string*) (sql_table.cc:4482)
==642256==    by 0xA15A68: mysql_create_table_no_lock(THD*, st_ddl_log_state*, st_ddl_log_state*, st_mysql_const_lex_string const*, st_mysql_const_lex_string const*, Table_specification_st*, Alter_info*, bool*, int, TABLE_LIST*) (sql_table.cc:4582)
==642256==    by 0xA1725E: mysql_create_table(THD*, TABLE_LIST*, Table_specification_st*, Alter_info*) (sql_table.cc:4693)
==642256==    by 0xA34640: Sql_cmd_create_table_like::execute(THD*) (sql_table.cc:11641)
==642256==    by 0x90FFCD: mysql_execute_command(THD*) (sql_parse.cc:5876)
==642256==    by 0x900C80: mysql_parse(THD*, char*, unsigned int, Parser_state*) (sql_parse.cc:7902)

Tests affected

main.partition_utf8-debug main.partition_ucs2 main.partition_utf8

Smallest test is: partition_ucs2

diff --git a/sql/item.cc b/sql/item.cc
index b7e285f7096..764f27be70e 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -1334,6 +1334,7 @@ Item *Item::const_charset_converter(THD *thd, CHARSET_INFO *tocs,
 {
   DBUG_ASSERT(const_item());
   DBUG_ASSERT(fixed());
+  DBUG_ASSERT(!thd->fpf);
   StringBuffer<64>tmp;
   String *s= val_str(&tmp);
   MEM_ROOT *mem_root= thd->mem_root;
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 6692b98dc5e..365af24ebc2 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -2802,6 +2802,7 @@ class THD: public THD_count, /* this must be first */
   { DBUG_ASSERT(0); return Statement::is_conventional(); }

 public:
+  bool fpf;
   MDL_context mdl_context;

   /* Used to execute base64 coded binlog events in MySQL server */
diff --git a/sql/table.cc b/sql/table.cc
index 36fcb511cae..06e40d13b15 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -4069,7 +4069,9 @@ enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share,
     if (share->part_info->subpart_expr)
       outparam->part_info->subpart_expr= share->part_info->subpart_expr->build_clone(thd);

+    thd->fpf= true;
     err= fix_partition_func(thd, outparam);
+    thd->fpf= false;
     thd->stmt_arena= backup_stmt_arena_ptr;
     DBUG_ASSERT(!part_func_arena.free_list);
     thd->restore_active_arena(&part_func_arena, &backup_arena);

Fix

--- a/sql/table.cc
+++ b/sql/table.cc
@@ -4071,8 +4071,8 @@ enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share,

     err= fix_partition_func(thd, outparam);
     thd->stmt_arena= backup_stmt_arena_ptr;
-    DBUG_ASSERT(!part_func_arena.free_list);
     thd->restore_active_arena(&part_func_arena, &backup_arena);
+    outparam->part_info->item_free_list= part_func_arena.free_list;

     if (err)
       goto err;

thd->free_list is not empty after constructed new items but part_func_arena.free_list is empty. part_func_arena.free_list is assigned from thd->free_list after restore_active_arena().

midenok commented 3 years ago

Bug: archive.partition_archive fails

Bad

#0  0x00007f40d1cd0a91 in read_header (s=0x7f40d00b2b20, buffer=0x7f40d00b28d0 "\376\003\001\020") at /home/midenok/src/mariadb/10.6b/src/storage/archive/azio.c:385
#1  0x00007f40d1cd100b in check_header (s=0x7f40d00b2b20) at /home/midenok/src/mariadb/10.6b/src/storage/archive/azio.c:356
#2  0x00007f40d1cd045a in az_open (s=0x7f40d00b2b20, path=0x7f40b805a7b0 "./db99/t1#P#p0.ARZ", Flags=0, fd=-1) at /home/midenok/src/mariadb/10.6b/src/storage/archive/azio.c:178
#3  0x00007f40d1cd1088 in azopen (s=0x7f40d00b2b20, path=0x7f40b805a7b0 "./db99/t1#P#p0.ARZ", Flags=0) at /home/midenok/src/mariadb/10.6b/src/storage/archive/azio.c:233
#4  0x00007f40d1cd4557 in ha_archive::get_share (this=0x7f40b80e5ce0, table_name=0x7f40d00bf080 "./db99/t1#P#p0", rc=0x7f40d00bed0c) at /home/midenok/src/mariadb/10.6b/src/storage/archive/ha_archive.cc:500
#5  0x00007f40d1cd4e0e in ha_archive::open (this=0x7f40b80e5ce0, name=0x7f40d00bf080 "./db99/t1#P#p0", mode=2, open_options=9234) at /home/midenok/src/mariadb/10.6b/src/storage/archive/ha_archive.cc:606
#6  0x0000000000d02624 in handler::ha_open (this=0x7f40b80e5ce0, table_arg=0x7f40b8027088, name=0x7f40d00bf080 "./db99/t1#P#p0", mode=2, test_if_locked=9234, mem_root=0x0, partitions_to_open=0x0) at /home/midenok/src/mariadb/10.6b/src/sql/handler.cc:2998
#7  0x00000000010b3e15 in ha_partition::open_read_partitions (this=0x7f40b810be30, name_buff=0x7f40d00bf080 "./db99/t1#P#p0", name_buff_size=513) at /home/midenok/src/mariadb/10.6b/src/sql/ha_partition.cc:8617
#8  0x00000000010b3490 in ha_partition::open (this=0x7f40b810be30, name=0x7f40b801e2a0 "./db99/t1", mode=2, test_if_locked=8210) at /home/midenok/src/mariadb/10.6b/src/sql/ha_partition.cc:3690
#9  0x0000000000d02624 in handler::ha_open (this=0x7f40b810be30, table_arg=0x7f40b8027088, name=0x7f40b801e2a0 "./db99/t1", mode=2, test_if_locked=8210, mem_root=0x0, partitions_to_open=0x0) at /home/midenok/src/mariadb/10.6b/src/sql/handler.cc:2998
#10 0x0000000000a94a9b in open_table_from_share (thd=0x7f40b8000d48, share=0x7f40b801dcc0, alias=0x7f40b8020eb8, db_stat=33, prgflag=8, ha_open_flags=8210, outparam=0x7f40b8027088, partitions_to_open=0x0) at /home/midenok/src/mariadb/10.6b/src/sql/table.cc:4137
#11 0x000000000083b264 in open_table (thd=0x7f40b8000d48, table_list=0x7f40b8020e70, ot_ctx=0x7f40d00bff28) at /home/midenok/src/mariadb/10.6b/src/sql/sql_base.cc:2000
#12 0x0000000000840997 in open_and_process_table (thd=0x7f40b8000d48, tables=0x7f40b8020e70, counter=0x7f40d00c25d4, flags=0, prelocking_strategy=0x7f40d00c1fd0, has_prelocking_list=false, ot_ctx=0x7f40d00bff28) at /home/midenok/src/mariadb/10.6b/src/sql/sql_base.cc:3849
#13 0x000000000083f2e0 in open_tables (thd=0x7f40b8000d48, options=..., start=0x7f40d00c2618, counter=0x7f40d00c25d4, flags=0, prelocking_strategy=0x7f40d00c1fd0) at /home/midenok/src/mariadb/10.6b/src/sql/sql_base.cc:4323
#14 0x0000000000a26585 in open_tables (thd=0x7f40b8000d48, tables=0x7f40d00c2618, counter=0x7f40d00c25d4, flags=0, prelocking_strategy=0x7f40d00c1fd0) at /home/midenok/src/mariadb/10.6b/src/sql/sql_base.h:263
#15 0x0000000000a21cbf in mysql_alter_table (thd=0x7f40b8000d48, new_db=0x7f40b8005778, new_name=0x7f40b8005b68, create_info=0x7f40d00c2f98, table_list=0x7f40b8020e70, alter_info=0x7f40d00c2ea8, order_num=0, order=0x0, ignore=false, if_exists=false) at /home/midenok/src/mariadb/10.6b/src/sql/sql_table.cc:9423
#16 0x0000000000b0fc4b in Sql_cmd_alter_table::execute (this=0x7f40b810b120, thd=0x7f40b8000d48) at /home/midenok/src/mariadb/10.6b/src/sql/sql_alter.cc:542
#17 0x000000000090ffce in mysql_execute_command (thd=0x7f40b8000d48) at /home/midenok/src/mariadb/10.6b/src/sql/sql_parse.cc:5876
#18 0x0000000000900c81 in mysql_parse (thd=0x7f40b8000d48, rawbuf=0x7f40b801a510 "alter table t1 drop partition p2", length=32, parser_state=0x7f40d00c54f8) at /home/midenok/src/mariadb/10.6b/src/sql/sql_parse.cc:7902
370       if (buffer[0] == az_magic[0]  && buffer[1] == az_magic[1])
371       {
372         uchar tmp[AZ_FRMVER_LEN + 2];
373
374         s->version= (unsigned int)buffer[AZ_VERSION_POS];
375         s->minor_version= (unsigned int)buffer[AZ_MINOR_VERSION_POS];
376         s->block_size= 1024 * buffer[AZ_BLOCK_POS];
377         s->start= (unsigned long long)uint8korr(buffer + AZ_START_POS);
378         s->rows= (unsigned long long)uint8korr(buffer + AZ_ROW_POS);
379         s->check_point= (unsigned long long)uint8korr(buffer + AZ_CHECK_POS);
380         s->forced_flushes= (unsigned long long)uint8korr(buffer + AZ_FLUSH_POS);
381         s->auto_increment= (unsigned long long)uint8korr(buffer + AZ_AUTOINCREMENT_POS);
382         s->longest_row= (unsigned int)uint4korr(buffer + AZ_LONGEST_POS);
383         s->shortest_row= (unsigned int)uint4korr(buffer + AZ_SHORTEST_POS);
384         s->frm_start_pos= (unsigned int)uint4korr(buffer + AZ_FRM_POS);
(rr)  p s->frm_length
$15 = 564

Good

(rr) p s->frm_length
$12 = 0

Bad: TABLE_SHARE::read_frm_image() returns false

#0  TABLE_SHARE::read_frm_image (this=0x7f40b8028210, frm=0x7f40d00b2e20, len=0x7f40d00b2e18) at /home/midenok/src/mariadb/10.6b/src/sql/table.cc:3414
#1  0x00007f40d1cd59c5 in ha_archive::create (this=0x7f40b8196040, name=0x7f40d00bf6b0 "./db99/t1#P#p2", table_arg=0x7f40b8027088, create_info=0x7f40d00c2f98) at /home/midenok/src/mariadb/10.6b/src/storage/archive/ha_archive.cc:832
#2  0x0000000000d0c9d1 in handler::ha_create (this=0x7f40b8196040, name=0x7f40d00bf6b0 "./db99/t1#P#p2", form=0x7f40b8027088, info_arg=0x7f40d00c2f98) at /home/midenok/src/mariadb/10.6b/src/sql/handler.cc:5117
#3  0x00000000010ac8c1 in ha_partition::prepare_new_partition (this=0x7f40b8020e70, tbl=0x7f40b8027088, create_info=0x7f40d00c2f98, file=0x7f40b8196040, part_name=0x7f40d00bf6b0 "./db99/t1#P#p2", p_elem=0x7f40b81136f0, disable_non_uniq_indexes=0) at /home/midenok/src/mariadb/10.6b/src/sql/ha_partition.cc:1650
#4  0x00000000010ade47 in ha_partition::change_partitions (this=0x7f40b8020e70, create_info=0x7f40d00c2f98, path=0x7f40d00bfa20 "./db99/t1", copied=0x7f40d00bff38, deleted=0x7f40d00bff40, pack_frm_data=0x0, pack_frm_len=0) at /home/midenok/src/mariadb/10.6b/src/sql/ha_partition.cc:2048
#5  0x0000000000d0ce05 in handler::ha_change_partitions (this=0x7f40b8020e70, create_info=0x7f40d00c2f98, path=0x7f40d00bfa20 "./db99/t1", copied=0x7f40d00bff38, deleted=0x7f40d00bff40, pack_frm_data=0x0, pack_frm_len=0) at /home/midenok/src/mariadb/10.6b/src/sql/handler.cc:5173
#6  0x0000000000f5306b in mysql_change_partitions (lpt=0x7f40d00bff30) at /home/midenok/src/mariadb/10.6b/src/sql/sql_partition.cc:5972
#7  0x0000000000f5198f in fast_alter_partition_table (thd=0x7f40b8000d48, table=0x7f40b8027088, alter_info=0x7f40d00c2ea8, create_info=0x7f40d00c2f98, table_list=0x7f40b810a6a0, db=0x7f40d00c13b0, table_name=0x7f40d00c13c0) at /home/midenok/src/mariadb/10.6b/src/sql/sql_partition.cc:7233
#8  0x0000000000a2373d in mysql_alter_table (thd=0x7f40b8000d48, new_db=0x7f40b8005778, new_name=0x7f40b8005b68, create_info=0x7f40d00c2f98, table_list=0x7f40b810a6a0, alter_info=0x7f40d00c2ea8, order_num=0, order=0x0, ignore=false, if_exists=false) at /home/midenok/src/mariadb/10.6b/src/sql/sql_table.cc:9889
#9  0x0000000000b0fc4b in Sql_cmd_alter_table::execute (this=0x7f40b801fa50, thd=0x7f40b8000d48) at /home/midenok/src/mariadb/10.6b/src/sql/sql_alter.cc:542
#10 0x000000000090ffce in mysql_execute_command (thd=0x7f40b8000d48) at /home/midenok/src/mariadb/10.6b/src/sql/sql_parse.cc:5876
#11 0x0000000000900c81 in mysql_parse (thd=0x7f40b8000d48, rawbuf=0x7f40b801be90 "alter table t1 add partition (partition p2 values in (3))", length=57, parser_state=0x7f40d00c54f8) at /home/midenok/src/mariadb/10.6b/src/sql/sql_parse.cc:7902
3412    int TABLE_SHARE::read_frm_image(const uchar **frm, size_t *len)
3413    {
3414      if (frm_image)
3415      {
3416        *frm= frm_image->str;
3417        *len= frm_image->length;
3418        frm_image->str= 0; // pass the ownership to the caller
3419        frm_image= 0;
3420        return 0;
3421      }
3422      return readfrm(normalized_path.str, frm, len);
3423    }

frame 2

829       /*
830         Here is where we open up the frm and pass it to archive to store
831       */
832       if (!table_arg->s->read_frm_image(&frm_ptr, &frm_len))
833       {
834         azwrite_frm(&create_stream, frm_ptr, frm_len);
835         table_arg->s->free_frm_image(frm_ptr);
836       }

Good: read_frm_image() returns true because of that condition:

3463    bool TABLE_SHARE::read_frm_image(const uchar **frm, size_t *len)
3464    {
3465      if (IF_PARTITIONING(partition_info_str, 0))   // cannot discover a partition
3466      {
3467        DBUG_ASSERT(db_type()->discover_table == 0);
3468        return 1;
3469      }

Cause

azwrite_frm() here must not be called.

midenok commented 3 years ago

Info

/**
  @brief Explain a path name by split it to database, table etc.

  @details Break down the path name to its logic parts
  (database, table, partition, subpartition).
  filename_to_tablename cannot be used on partitions, due to the #P# part.
  There can be up to 6 '#', #P# for partition, #SP# for subpartition
  and #TMP# or #REN# for temporary or renamed partitions.
  This should be used when something should be presented to a user in a
  diagnostic, error etc. when it would be useful to know what a particular
  file [and directory] means. Such as SHOW ENGINE STATUS, error messages etc.

  Examples:

    t1#P#p1                 table t1 partition p1
    t1#P#p1#SP#sp1          table t1 partition p1 subpartition sp1
    t1#P#p1#SP#sp1#TMP#     table t1 partition p1 subpartition sp1 temporary
    t1#P#p1#SP#sp1#REN#     table t1 partition p1 subpartition sp1 renamed

   @param      thd          Thread handle
   @param      from         Path name in my_charset_filename
                            Null terminated in my_charset_filename, normalized
                            to use '/' as directory separation character.
   @param      to           Explained name in system_charset_info
   @param      to_length    Size of to buffer
   @param      explain_mode Requested output format.
                            EXPLAIN_ALL_VERBOSE ->
                            [Database `db`, ]Table `tbl`[,[ Temporary| Renamed]
                            Partition `p` [, Subpartition `sp`]]
                            EXPLAIN_PARTITIONS_VERBOSE -> `db`.`tbl`
                            [[ Temporary| Renamed] Partition `p`
                            [, Subpartition `sp`]]
                            EXPLAIN_PARTITIONS_AS_COMMENT -> `db`.`tbl` |*
                            [,[ Temporary| Renamed] Partition `p`
                            [, Subpartition `sp`]] *|
                            (| is really a /, and it is all in one line)

   @retval     Length of returned string
*/

uint explain_filename(THD* thd,
              const char *from,
                      char *to,
                      uint to_length,
                      enum_explain_filename_mode explain_mode)
/*
  Create partition names

  SYNOPSIS
    create_partition_name()
    out:out                   The buffer for the created partition name string
                              must be *at least* of FN_REFLEN+1 bytes
    in1                       First part
    in2                       Second part
    name_variant              Normal, temporary or renamed partition name

  RETURN VALUE
    0 if ok, error if name too long

  DESCRIPTION
    This method is used to calculate the partition name, service routine to
    the del_ren_cre_table method.
*/

int create_partition_name(char *out, size_t outlen, const char *in1,
                          const char *in2, uint name_variant, bool translate)
{
  char transl_part_name[FN_REFLEN];
  const char *transl_part, *end;
  DBUG_ASSERT(outlen >= FN_REFLEN + 1); // consistency! same limit everywhere

  if (translate)
  {
    tablename_to_filename(in2, transl_part_name, FN_REFLEN);
    transl_part= transl_part_name;
  }
  else
    transl_part= in2;

  if (name_variant == NORMAL_PART_NAME)
    end= strxnmov(out, outlen-1, in1, "#P#", transl_part, NullS);
  else if (name_variant == TEMP_PART_NAME)
    end= strxnmov(out, outlen-1, in1, "#P#", transl_part, "#TMP#", NullS);
  else
  {
    DBUG_ASSERT(name_variant == RENAMED_PART_NAME);
    end= strxnmov(out, outlen-1, in1, "#P#", transl_part, "#REN#", NullS);
  }
  if (end - out == static_cast<ptrdiff_t>(outlen-1))
  {
    my_error(ER_PATH_LENGTH, MYF(0), longest_str(in1, transl_part));
    return HA_WRONG_CREATE_OPTION;
  }
  return 0;
}

/**
  Create subpartition name. This method is used to calculate the
  subpartition name, service routine to the del_ren_cre_table method.
  The output buffer size should be FN_REFLEN + 1(terminating '\0').

    @param [out] out          Created partition name string
    @param in1                First part
    @param in2                Second part
    @param in3                Third part
    @param name_variant       Normal, temporary or renamed partition name

    @retval true              Error.
    @retval false             Success.
*/

int create_subpartition_name(char *out, size_t outlen,
                             const char *in1, const char *in2,
                             const char *in3, uint name_variant)
{
  char transl_part_name[FN_REFLEN], transl_subpart_name[FN_REFLEN], *end;
  DBUG_ASSERT(outlen >= FN_REFLEN + 1); // consistency! same limit everywhere

  tablename_to_filename(in2, transl_part_name, FN_REFLEN);
  tablename_to_filename(in3, transl_subpart_name, FN_REFLEN);

  if (name_variant == NORMAL_PART_NAME)
    end= strxnmov(out, outlen-1, in1, "#P#", transl_part_name,
                  "#SP#", transl_subpart_name, NullS);
  else if (name_variant == TEMP_PART_NAME)
    end= strxnmov(out, outlen-1, in1, "#P#", transl_part_name,
                  "#SP#", transl_subpart_name, "#TMP#", NullS);
  else
  {
    DBUG_ASSERT(name_variant == RENAMED_PART_NAME);
    end= strxnmov(out, outlen-1, in1, "#P#", transl_part_name,
                  "#SP#", transl_subpart_name, "#REN#", NullS);
  }
  if (end - out == static_cast<ptrdiff_t>(outlen-1))
  {
    my_error(ER_PATH_LENGTH, MYF(0),
             longest_str(in1, transl_part_name, transl_subpart_name));
    return HA_WRONG_CREATE_OPTION;
  }
  return 0;
}
midenok commented 3 years ago

Tests to check

main.partition innodb.alter_partitioned innodb.alter_partitioned_xa innodb.innodb-lock innodb.innodb-mdev7046 parts.longname innodb.multi_repair-7404
midenok commented 3 years ago

Bug: auto-create adds extra partition on multi-update

Reproduce

-- source include/have_partition.inc

--echo # Multiple increments in single command
set timestamp= unix_timestamp('2000-01-01 00:00:00');
create or replace table t1 (x int) with system versioning
partition by system_time interval 1 hour auto partitions 3;

create or replace table t2 (y int) with system versioning
partition by system_time interval 1 hour auto;

insert into t1 values (1);
insert into t2 values (2);

set timestamp= unix_timestamp('2000-01-01 01:00:00');
update t1, t2 set x= x + 1, y= y + 1;
show create table t1;
show create table t2;

set timestamp= unix_timestamp('2000-01-01 02:00:00');
update t1, t2 set x= x + 1, y= y + 1;
show create table t1;
show create table t2;

--echo # Here t2 is incremented too, but not updated
set timestamp= unix_timestamp('2000-01-01 03:00:00');
update t1, t2 set t1.x= 0 where t1.x< t2.y;
show create table t1;
# Multiupdate_prelocking_strategy::handle_end() is processed after table open.
# For PS it is possible to skip unneeded auto-creation because the above happens at
# prepare stage and auto-creation is done at execute stage.
show create table t2;

drop tables t1, t2;

1. vers_need_hist_part() called

#0  TABLE::vers_need_hist_part (this=0x7fe654081198, thd=0x7fe654000d48, table_list=0x7fe65408f5d0) at /home/midenok/src/mariadb/10.6b/src/sql/sql_base.cc:1631
#1  0x00000000008655fd in open_table (thd=0x7fe654000d48, table_list=0x7fe65408f5d0, ot_ctx=0x7fe66560d1e8) at /home/midenok/src/mariadb/10.6b/src/sql/sql_base.cc:2087
#2  0x000000000086b527 in open_and_process_table (thd=0x7fe654000d48, tables=0x7fe65408f5d0, counter=0x7fe66560d3a4, flags=0, prelocking_strategy=0x7fe66560d3a8, has_prelocking_list=false, ot_ctx=0x7fe66560d1e8) at /home/midenok/src/mariadb/10.6b/src/sql/sql_base.cc:3896
#3  0x0000000000869bb0 in open_tables (thd=0x7fe654000d48, options=..., start=0x7fe66560d3c0, counter=0x7fe66560d3a4, flags=0, prelocking_strategy=0x7fe66560d3a8) at /home/midenok/src/mariadb/10.6b/src/sql/sql_base.cc:4370
#4  0x0000000000a86c05 in open_tables (thd=0x7fe654000d48, tables=0x7fe66560d3c0, counter=0x7fe66560d3a4, flags=0, prelocking_strategy=0x7fe66560d3a8) at ../src/sql/sql_base.h:263
#5  0x0000000000a8673f in mysql_multi_update_prepare (thd=0x7fe654000d48) at ../src/sql/sql_update.cc:1868
#6  0x000000000093844d in mysql_execute_command (thd=0x7fe654000d48) at ../src/sql/sql_parse.cc:4433
#7  0x000000000092d026 in mysql_parse (thd=0x7fe654000d48, rawbuf=0x7fe654012920 "update t1, t2 set t1.x= 0 where t1.x< t2.y", length=42, parser_state=0x7fe66560f458) at ../src/sql/sql_parse.cc:8005

2. DML detects table is RW or not

#0  Multiupdate_prelocking_strategy::handle_end (this=0x7fe66560d3a8, thd=0x7fe654000d48) at ../src/sql/sql_update.cc:1739
#1  0x000000000086a03c in open_tables (thd=0x7fe654000d48, options=..., start=0x7fe66560d3c0, counter=0x7fe66560d3a4, flags=0, prelocking_strategy=0x7fe66560d3a8) at /home/midenok/src/mariadb/10.6b/src/sql/sql_base.cc:4481
#2  0x0000000000a86c05 in open_tables (thd=0x7fe654000d48, tables=0x7fe66560d3c0, counter=0x7fe66560d3a4, flags=0, prelocking_strategy=0x7fe66560d3a8) at ../src/sql/sql_base.h:263
#3  0x0000000000a8673f in mysql_multi_update_prepare (thd=0x7fe654000d48) at ../src/sql/sql_update.cc:1868
#4  0x000000000093844d in mysql_execute_command (thd=0x7fe654000d48) at ../src/sql/sql_parse.cc:4433
#5  0x000000000092d026 in mysql_parse (thd=0x7fe654000d48, rawbuf=0x7fe654012920 "update t1, t2 set t1.x= 0 where t1.x< t2.y", length=42, parser_state=0x7fe66560f458) at ../src/sql/sql_parse.cc:8005
1739      table_map tables_for_update= thd->table_map_for_update= get_table_map(fields);

Divergence is open_tables(): 4370 vs 4481

Notes

+# Multiupdate_prelocking_strategy::handle_end() is processed after table open. +# For PS it is possible to skip unneeded auto-creation because the above happens at +# prepare stage and auto-creation is done at execute stage. +--replace_result $default_engine DEFAULT_ENGINE 'PARTITIONS 4' 'PARTITIONS ok' 'PARTITIONS 5' 'PARTITIONS ok'

eh... I don't think this is really "ok". As far as I remember, Multiupdate_prelocking_strategy knows what tables should be opened for writing and what for reading. Why would a new partition be created for t2?

It knows this after tables are opened. Look at handle_end(), specifically mysql_handle_derived(), handle_derived(), setup_fields_with_no_wrap() and check_fields(). I believe all these calls are required to get proper get_table_map(). To get this working properly there must be 2-staged open tables, something like PS does.

midenok commented 3 years ago

Continuous concurrency test

--source include/have_partition.inc

#SET GLOBAL debug_dbug = "d,block_add_history_part";
--disable_query_log
--disable_result_log
--connect con6, localhost, root
select 1;
--connect con5, localhost, root
select 1;
--connect con4, localhost, root
select 1;
--connect con3, localhost, root
select 1;
--connect con2, localhost, root
select 1;
--connect con1, localhost, root
select 1;
--enable_result_log
--connection default
let $i= 500;
let $t= `select unix_timestamp('2000-01-01 02:00:00')`;

set timestamp= unix_timestamp('2000-01-01 00:00:00');
create or replace table t1 (x int) with system versioning
partition by system_time interval 1 hour auto partitions 3;

insert into t1 values (1);

while ($i)
{
--connection con1
eval set timestamp= $t;
send update t1 set x= x + 10;
--connection con2
eval set timestamp= $t;
send update t1 set x= x + 20;
--connection con3
eval set timestamp= $t;
send update t1 set x= x + 30;
--connection con4
eval set timestamp= $t;
send update t1 set x= x + 40;
--connection con5
eval set timestamp= $t;
send update t1 set x= x + 50;
--connection con6
eval set timestamp= $t;
send update t1 set x= x + 60;
--connection con1
reap;
--connection con2
reap;
--connection con3
reap;
--connection con4
reap;
--connection con5
reap;
--connection con6
reap;
--let $t= `select $t + 3600`
--dec $i
}
--enable_query_log
--disconnect con1
--disconnect con2
--disconnect con3
--disconnect con4
--disconnect con5
--disconnect con6
--connection default
show create table t1;

drop tables t1;
set timestamp= default;

#--connection con8
#--sleep 1
#SET DEBUG_SYNC= 'now SIGNAL continue_add_history_part';

#set GLOBAL debug_dbug= default;
midenok commented 2 years ago

MDEV-25477 Auto-create breaks replication when triggering event was not replicated

Reverted

--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -4215,7 +4215,8 @@ bool select_insert::prepare_eof()
     ha_autocommit_or_rollback() is issued below.
   */
   if ((WSREP_EMULATE_BINLOG(thd) || mysql_bin_log.is_open()) &&
-      (likely(!error) || thd->transaction->stmt.modified_non_trans_table))
+      (likely(!error) || thd->transaction->stmt.modified_non_trans_table ||
+       thd->log_current_statement))
   {
     int errcode= 0;
     int res;
@@ -4223,6 +4224,7 @@ bool select_insert::prepare_eof()
       thd->clear_error();
     else
       errcode= query_error_code(thd, killed_status == NOT_KILLED);
+    StatementBinlog stmt_binlog(thd, thd->binlog_need_stmt_format(trans_table));
     res= thd->binlog_query(THD::ROW_QUERY_TYPE,
                            thd->query(), thd->query_length(),
                            trans_table, FALSE, FALSE, errcode);
@@ -4343,6 +4345,7 @@ void select_insert::abort_result_set()

         if(WSREP_EMULATE_BINLOG(thd) || mysql_bin_log.is_open())
         {
+          StatementBinlog stmt_binlog(thd, thd->binlog_need_stmt_format(transactional_table));
           int errcode= query_error_code(thd, thd->killed == NOT_KILLED);
           int res;
           /* error of writing binary log is ignored */

Failing tests

rpl.create_or_replace_mix rpl.create_or_replace_row rpl.create_or_replace_statement
midenok commented 2 years ago

Bug: concurrency failure

Reproduce

y.test.txt

Result 1

#12 0x00007ffaa5d07e96 in __GI___assert_fail (assertion=0x559a62825fe5 "!table->in_use", file=0x559a62825f8c "/home/midenok/src/mariadb/10.6b/src/sql/table_cache.cc", line=396, function=0x559a62825ff4 "TABLE *tc_acquire_table(THD *, TDC_element *)") at ./assert/assert.c:101
#13 0x0000559a61ca820f in tc_acquire_table (thd=0x7ffa10000d58, element=0x7ffa14035568) at /home/midenok/src/mariadb/10.6b/src/sql/table_cache.cc:396
#14 0x0000559a61caa08d in tdc_acquire_share (thd=0x7ffa10000d58, tl=0x7ffa10012db0, flags=3, out_table=0x7ffa7e4bf878) at /home/midenok/src/mariadb/10.6b/src/sql/table_cache.cc:862
#15 0x0000559a618da9f0 in open_table (thd=0x7ffa10000d58, table_list=0x7ffa10012db0, ot_ctx=0x7ffa7e4bfb88) at /home/midenok/src/mariadb/10.6b/src/sql/sql_base.cc:2011
#16 0x0000559a618e1047 in open_and_process_table (thd=0x7ffa10000d58, tables=0x7ffa10012db0, counter=0x7ffa7e4c062c, flags=0, prelocking_strategy=0x7ffa7e4bfc38, has_prelocking_list=false, ot_ctx=0x7ffa7e4bfb88) at /home/midenok/src/mariadb/10.6b/src/sql/sql_base.cc:4090
#17 0x0000559a618dfa48 in open_tables (thd=0x7ffa10000d58, options=..., start=0x7ffa7e4c0678, counter=0x7ffa7e4c062c, flags=0, prelocking_strategy=0x7ffa7e4bfc38) at /home/midenok/src/mariadb/10.6b/src/sql/sql_base.cc:4577
#18 0x0000559a618d20c8 in open_tables (thd=0x7ffa10000d58, tables=0x7ffa7e4c0678, counter=0x7ffa7e4c062c, flags=0) at /home/midenok/src/mariadb/10.6b/src/sql/sql_base.h:480
#19 0x0000559a61b08db9 in mysql_update (thd=0x7ffa10000d58, table_list=0x7ffa10012db0, fields=..., values=..., conds=0x0, order_num=0, order=0x0, limit=18446744073709551615, ignore=false, found_return=0x7ffa7e4c1158, updated_return=0x7ffa7e4c1150) at /home/midenok/src/mariadb/10.6b/src/sql/sql_update.cc:410
#20 0x0000559a619a94cf in mysql_execute_command (thd=0x7ffa10000d58, is_called_from_prepared_stmt=false) at /home/midenok/src/mariadb/10.6b/src/sql/sql_parse.cc:4424
#21 0x0000559a619a0b6a in mysql_parse (thd=0x7ffa10000d58, rawbuf=0x7ffa10012ce0 "update t1 set x= x + 20", length=23, parser_state=0x7ffa7e4c2348) at /home/midenok/src/mariadb/10.6b/src/sql/sql_parse.cc:8047

Result 2

#12 0x00007feda47b1e96 in __GI___assert_fail (assertion=0x55b3cfaa5fe6 "table->in_use", file=0x55b3cfaa5f8c "/home/midenok/src/mariadb/10.6b/src/sql/table_cache.cc", line=439, function=0x55b3cfaa6073 "void tc_release_table(TABLE *)") at ./assert/assert.c:101
#13 0x000055b3cef28496 in tc_release_table (table=0x7fed3801e088) at /home/midenok/src/mariadb/10.6b/src/sql/table_cache.cc:439
#14 0x000055b3ceb5a0e5 in TABLE::vers_switch_partition (this=0x7fed3801e088, thd=0x7fed2c000d58, table_list=0x7fed2c012db0, ot_ctx=0x7fed98422b88) at /home/midenok/src/mariadb/10.6b/src/sql/sql_base.cc:1772
#15 0x000055b3ceb5b283 in open_table (thd=0x7fed2c000d58, table_list=0x7fed2c012db0, ot_ctx=0x7fed98422b88) at /home/midenok/src/mariadb/10.6b/src/sql/sql_base.cc:2199
#16 0x000055b3ceb61047 in open_and_process_table (thd=0x7fed2c000d58, tables=0x7fed2c012db0, counter=0x7fed9842362c, flags=0, prelocking_strategy=0x7fed98422c38, has_prelocking_list=false, ot_ctx=0x7fed98422b88) at /home/midenok/src/mariadb/10.6b/src/sql/sql_base.cc:4090
#17 0x000055b3ceb5fa48 in open_tables (thd=0x7fed2c000d58, options=..., start=0x7fed98423678, counter=0x7fed9842362c, flags=0, prelocking_strategy=0x7fed98422c38) at /home/midenok/src/mariadb/10.6b/src/sql/sql_base.cc:4577
#18 0x000055b3ceb520c8 in open_tables (thd=0x7fed2c000d58, tables=0x7fed98423678, counter=0x7fed9842362c, flags=0) at /home/midenok/src/mariadb/10.6b/src/sql/sql_base.h:480
#19 0x000055b3ced88db9 in mysql_update (thd=0x7fed2c000d58, table_list=0x7fed2c012db0, fields=..., values=..., conds=0x0, order_num=0, order=0x0, limit=18446744073709551615, ignore=false, found_return=0x7fed98424158, updated_return=0x7fed98424150) at /home/midenok/src/mariadb/10.6b/src/sql/sql_update.cc:410
#20 0x000055b3cec294cf in mysql_execute_command (thd=0x7fed2c000d58, is_called_from_prepared_stmt=false) at /home/midenok/src/mariadb/10.6b/src/sql/sql_parse.cc:4424
#21 0x000055b3cec20b6a in mysql_parse (thd=0x7fed2c000d58, rawbuf=0x7fed2c012ce0 "update t1 set x= x + 80", length=23, parser_state=0x7fed98425348) at /home/midenok/src/mariadb/10.6b/src/sql/sql_parse.cc:8047
midenok commented 1 year ago

MDEV-25495 Auto-drop old history partition for system-versioned tables that use auto-creation

Partition dropped

--source include/have_partition.inc

create or replace table t1 (x int)
partition by range columns (x) (
  partition p0 values less than (10),
  partition p1 values less than (20),
  partition pn values less than maxvalue);

insert into t1 values (11);
alter table t1 drop partition p1;
drop table t1;
#0  ha_partition::drop_partitions (this=0x7f2260025df0, path=0x7f22780bc7c0 "./test/t1") at ../src/sql/ha_partition.cc:924
#1  0x000055ce287f0c15 in handler::ha_drop_partitions (this=0x7f2260025df0, path=0x7f22780bc7c0 "./test/t1") at ../src/sql/handler.cc:5730
#2  0x000055ce28c8c1f7 in mysql_drop_partitions (lpt=0x7f22780bcc38) at ../src/sql/sql_partition.cc:6249
#3  0x000055ce28c889c1 in fast_alter_partition_table (thd=0x7f2260000d58, table=0x7f22600255d8, alter_info=0x7f22780c0248, alter_ctx=0x7f22780be238, create_info=0x7f22780c0330, table_list=0x7f2260016578) at ../src/sql/sql_partition.cc:7597
#4  0x000055ce28da2ac3 in mysql_alter_table (thd=0x7f2260000d58, new_db=0x7f2260005a50, new_name=0x7f2260005ea0, create_info=0x7f22780c0330, table_list=0x7f2260016578, recreate_info=0x7f22780bfad0, alter_info=0x7f22780c0248, order_num=0, order=0x0, ignore=false, if_exists=false) at ../src/sql/sql_table.cc:10547
#5  0x000055ce28e8e003 in Sql_cmd_alter_table::execute (this=0x7f2260016cb8, thd=0x7f2260000d58) at ../src/sql/sql_alter.cc:558
#6  0x000055ce28c68c10 in mysql_execute_command (thd=0x7f2260000d58, is_called_from_prepared_stmt=false) at ../src/sql/sql_parse.cc:5760
#7  0x000055ce28c5b1af in mysql_parse (thd=0x7f2260000d58, rawbuf=0x7f2260016490 "alter table t1 drop partition p1", length=32, parser_state=0x7f22780c2288) at ../src/sql/sql_parse.cc:7760

Flag PART_TO_BE_DROPPED set

#0  0x000055ce28c85d36 in prep_alter_part_table (thd=0x7f2260000d58, table=0x7f22600255d8, alter_info=0x7f22780c0248, create_info=0x7f22780c0330, partition_changed=0x7f22780bf92f, fast_alter_table=0x7f22780bf92e) at ../src/sql/sql_partition.cc:5524
#1  0x000055ce28da25c6 in mysql_alter_table (thd=0x7f2260000d58, new_db=0x7f2260005a50, new_name=0x7f2260005ea0, create_info=0x7f22780c0330, table_list=0x7f2260016578, recreate_info=0x7f22780bfad0, alter_info=0x7f22780c0248, order_num=0, order=0x0, ignore=false, if_exists=false) at ../src/sql/sql_table.cc:10458

Flag is set for partitions in alter_info->partition_names

      do
      {
        partition_element *part_elem= part_it++;
        if (is_name_in_list(part_elem->partition_name,
                            alter_info->partition_names))
        {
          ...
          /*
            Set state to indicate that the partition is to be dropped.
          */
          num_parts_found++;
          part_elem->part_state= PART_TO_BE_DROPPED;
        }
      } while (++part_count < tab_part_info->num_parts);