diff options
author | Alexey Botchkov <holyfoot@askmonty.org> | 2022-02-10 10:56:51 +0400 |
---|---|---|
committer | Alexey Botchkov <holyfoot@askmonty.org> | 2022-02-10 10:56:51 +0400 |
commit | e4b28314fe84d73988845034dd4cae111a9e2118 (patch) | |
tree | 7d4c50e9d28c117b6a9d187e9ba3070429201560 | |
parent | a6925e6358573dce0b784a1422d57c410c06377f (diff) | |
download | mariadb-git-bb-10.7-mdev-27159-hf.tar.gz |
ha_partition::open_part2() implemented.bb-10.7-mdev-27159-hf
-rw-r--r-- | sql/ha_partition.cc | 127 | ||||
-rw-r--r-- | sql/ha_partition.h | 1 | ||||
-rw-r--r-- | sql/sql_base.h | 8 | ||||
-rw-r--r-- | sql/sql_select.cc | 3 |
4 files changed, 86 insertions, 53 deletions
diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index af9aefe0565..52075ee9e73 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -2956,17 +2956,23 @@ bool ha_partition::create_handler_file(const char *name) } +void ha_partition::clear_engines() +{ + if (m_engine_array) + plugin_unlock_list(NULL, m_engine_array, m_tot_parts); + m_engine_array= NULL; +} + + /** Clear handler variables and free some memory */ void ha_partition::clear_handler_file() { - if (m_engine_array) - plugin_unlock_list(NULL, m_engine_array, m_tot_parts); + clear_engines(); free_root(&m_mem_root, MYF(MY_KEEP_PREALLOC)); m_file_buffer= NULL; - m_engine_array= NULL; m_connect_string= NULL; } @@ -3602,9 +3608,7 @@ SYNOPSIS int ha_partition::open(const char *name, int mode, uint test_if_locked) { int error= HA_ERR_INITIALIZATION; - handler **file; char name_buff[FN_REFLEN + 1]; - ulonglong check_table_flags; DBUG_ENTER("ha_partition::open"); DBUG_ASSERT(table->s == table_share); @@ -3666,6 +3670,7 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked) { uint i, alloc_len; char *name_buffer_ptr; + handler **file; DBUG_ASSERT(m_clone_mem_root); /* Allocate an array of handler pointers for the partitions handlers. */ alloc_len= (m_tot_parts + 1) * sizeof(handler*); @@ -3706,8 +3711,9 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked) else { check_insert_autoincrement(); - if (unlikely((error= open_read_partitions(name_buff, sizeof(name_buff))))) - goto err_handler; +// if (unlikely((error= open_read_partitions(name_buff, sizeof(name_buff))))) +// goto err_handler; + m_file_sample= m_file[0]; m_num_locks= m_file_sample->lock_count(); } /* @@ -3717,6 +3723,69 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked) in get_lock_data(). */ m_num_locks*= m_tot_parts; + ref_length= get_open_file_sample()->ref_length; + + clear_engines(); + + DBUG_ASSERT(part_share); + lock_shared_ha_data(); + /* Protect against cloned file, for which we don't need engine name */ + if (m_file[0]) + part_share->partition_engine_name= real_table_type(); + else + part_share->partition_engine_name= 0; // Checked in ha_table_exists() + unlock_shared_ha_data(); + + DBUG_RETURN(0); + +err_handler: + DEBUG_SYNC(ha_thd(), "partition_open_error"); + DBUG_ASSERT(m_tot_parts > 0); + for (uint i= m_tot_parts - 1; ; --i) + { + if (bitmap_is_set(&m_opened_partitions, i)) + m_file[i]->ha_close(); + if (!i) + break; + } +err_alloc: + free_partition_bitmaps(); + my_free(m_range_info); + m_range_info= 0; + + DBUG_RETURN(error); +} + + +int ha_partition::open_part2() +{ + char name_buff[FN_REFLEN + 1]; + int error; + ulonglong check_table_flags; + handler **file; + + DBUG_ENTER("ha_partition::open_part2"); + DBUG_ASSERT(m_is_clone_of == NULL); + + bitmap_union(&m_part_info->read_partitions, &m_part_info->lock_partitions); + + if ((error= open_read_partitions(name_buff, sizeof(name_buff)))) + goto err_handler; + + m_num_locks= m_file_sample->lock_count() * m_tot_parts; + /* + Some handlers update statistics as part of the open call. This will in + some cases corrupt the statistics of the partition handler and thus + to ensure we have correct statistics we call info from open after + calling open on all individual handlers. + */ + m_handler_status= handler_opened; + if (m_part_info->part_expr) + m_part_func_monotonicity_info= + m_part_info->part_expr->get_monotonicity_info(); + else if (m_part_info->list_of_part_fields) + m_part_func_monotonicity_info= MONOTONIC_STRICT_INCREASING; + info(HA_STATUS_VARIABLE | HA_STATUS_CONST | HA_STATUS_OPEN); file= m_file; ref_length= get_open_file_sample()->ref_length; @@ -3758,56 +3827,12 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked) */ clear_handler_file(); - DBUG_ASSERT(part_share); - lock_shared_ha_data(); - /* Protect against cloned file, for which we don't need engine name */ - if (m_file[0]) - part_share->partition_engine_name= real_table_type(); - else - part_share->partition_engine_name= 0; // Checked in ha_table_exists() - unlock_shared_ha_data(); - - /* - Some handlers update statistics as part of the open call. This will in - some cases corrupt the statistics of the partition handler and thus - to ensure we have correct statistics we call info from open after - calling open on all individual handlers. - */ - m_handler_status= handler_opened; - if (m_part_info->part_expr) - m_part_func_monotonicity_info= - m_part_info->part_expr->get_monotonicity_info(); - else if (m_part_info->list_of_part_fields) - m_part_func_monotonicity_info= MONOTONIC_STRICT_INCREASING; - info(HA_STATUS_VARIABLE | HA_STATUS_CONST | HA_STATUS_OPEN); - DBUG_RETURN(0); err_handler: - DEBUG_SYNC(ha_thd(), "partition_open_error"); - DBUG_ASSERT(m_tot_parts > 0); - for (uint i= m_tot_parts - 1; ; --i) - { - if (bitmap_is_set(&m_opened_partitions, i)) - m_file[i]->ha_close(); - if (!i) - break; - } -err_alloc: - free_partition_bitmaps(); - my_free(m_range_info); - m_range_info= 0; - DBUG_RETURN(error); } -int ha_partition::open_part2() -{ - DBUG_ENTER("ha_partition::open_part2"); - DBUG_RETURN(0); -} - - /* Disabled since it is not possible to prune yet. without pruning, it need to rebind/unbind every partition in every diff --git a/sql/ha_partition.h b/sql/ha_partition.h index 7087b8bc411..08b85665b27 100644 --- a/sql/ha_partition.h +++ b/sql/ha_partition.h @@ -585,6 +585,7 @@ private: bool is_clone); bool new_handlers_from_part_info(MEM_ROOT *mem_root); bool create_handlers(MEM_ROOT *mem_root); + void clear_engines(); void clear_handler_file(); int set_up_table_before_create(TABLE *table_arg, const char *partition_name_with_path, diff --git a/sql/sql_base.h b/sql/sql_base.h index ae3fb622b77..422782eddc7 100644 --- a/sql/sql_base.h +++ b/sql/sql_base.h @@ -259,6 +259,8 @@ bool open_tables(THD *thd, const DDL_options_st &options, TABLE_LIST **tables, uint *counter, uint flags, Prelocking_strategy *prelocking_strategy); +bool open_tables_part2(THD *thd, TABLE_LIST *tables); + static inline bool open_tables(THD *thd, TABLE_LIST **tables, uint *counter, uint flags, Prelocking_strategy *prelocking_strategy) @@ -484,7 +486,8 @@ open_tables(THD *thd, const DDL_options_st &options, DML_prelocking_strategy prelocking_strategy; return open_tables(thd, options, tables, counter, flags, - &prelocking_strategy); + &prelocking_strategy) || + open_tables_part2(thd, *tables); } inline bool open_tables(THD *thd, TABLE_LIST **tables, uint *counter, uint flags) @@ -492,7 +495,8 @@ open_tables(THD *thd, TABLE_LIST **tables, uint *counter, uint flags) DML_prelocking_strategy prelocking_strategy; return open_tables(thd, thd->lex->create_info, tables, counter, flags, - &prelocking_strategy); + &prelocking_strategy) || + open_tables_part2(thd, *tables); } inline TABLE *open_n_lock_single_table(THD *thd, TABLE_LIST *table_l, diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 47ac7c85375..4b58fe49d9e 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -30226,6 +30226,9 @@ bool Sql_cmd_dml::execute(THD *thd) partitions. As a consequence, in such a case, prepare stage can rely only on metadata about tables used and not data from them. */ + if (open_tables_part2(thd, lex->query_tables)) + goto err; + if (!is_empty_query()) { if (lock_tables(thd, lex->query_tables, table_count, 0)) |