[Commits] af735cd52e5: Postreview part 1 (v1)
revision-id: af735cd52e54959dedc542acd23b89551cccf19b (mariadb-10.4.0-39-gaf735cd52e5) parent(s): 2fef5d8d8e5b5781a71ff6305c0eb7a3de555509 author: Oleksandr Byelkin committer: Oleksandr Byelkin timestamp: 2018-12-03 15:05:49 +0100 message: Postreview part 1 (v1) --- sql/protocol.h | 1 + sql/sql_class.cc | 154 +++++++++++++++++++++++++------------------------------ sql/sql_class.h | 7 +-- 3 files changed, 75 insertions(+), 87 deletions(-) diff --git a/sql/protocol.h b/sql/protocol.h index bf74f52fa98..2b9f1a592e4 100644 --- a/sql/protocol.h +++ b/sql/protocol.h @@ -34,6 +34,7 @@ struct insert_id_desc { ulonglong first_id; ulonglong sequence; + ulong collect_auto_increment_increment; }; class Protocol diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 87b83e60bd9..1f8f011bfa6 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -638,9 +638,8 @@ THD::THD(my_thread_id id, bool is_wsrep_applier, bool skip_global_sys_var_lock) m_stmt_da(&main_da), tdc_hash_pins(0), xid_hash_pins(0), - m_tmp_tables_locked(false) + m_tmp_tables_locked(false), #ifdef WITH_WSREP - , wsrep_applier(is_wsrep_applier), wsrep_applier_closing(false), wsrep_client_thread(false), @@ -648,8 +647,9 @@ THD::THD(my_thread_id id, bool is_wsrep_applier, bool skip_global_sys_var_lock) wsrep_po_handle(WSREP_PO_INITIALIZER), wsrep_po_cnt(0), wsrep_apply_format(0), - wsrep_ignore_table(false) + wsrep_ignore_table(false), #endif + insert_id_info(NULL) { ulong tmp; bzero(&variables, sizeof(variables)); @@ -1261,7 +1261,7 @@ void THD::init(bool skip_lock) #endif //EMBEDDED_LIBRARY apc_target.init(&LOCK_thd_kill); - insert_ids= NULL; + insert_id_info= NULL; DBUG_VOID_RETURN; } @@ -7695,113 +7695,99 @@ bool Qualified_column_ident::append_to(THD *thd, String *str) const bool THD::init_collecting_insert_id() { - if (!insert_ids) - { - void *buff; - if (!(my_multi_malloc(MYF(MY_WME), &insert_ids, sizeof(DYNAMIC_ARRAY), - &buff, sizeof(insert_id_desc) * 10, - NullS)) || - my_init_dynamic_array2(insert_ids, sizeof(insert_id_desc), - buff, 10, 100, MYF(MY_WME))) - { - if (insert_ids) - my_free(insert_ids); - insert_ids= NULL; + List<Item> field_list; + + // it should not be done on statement memory) + DBUG_ASSERT(stmt_arena->is_conventional() || + mem_root != stmt_arena->mem_root); + + DBUG_ASSERT(insert_id_info == NULL); + if ((insert_id_info= (insert_id_desc*) calloc(sizeof(insert_id_desc)))) + return TRUE; + + field_list.push_back(new (mem_root) + Item_int(this, "Id", 0, MY_INT64_NUM_DECIMAL_DIGITS), + mem_root); + field_list.push_back(new (mem_root) + Item_int(this, "Len", 0, MY_INT64_NUM_DECIMAL_DIGITS), + mem_root); + field_list.push_back(new (mem_root) + Item_return_int(this, "Inc", 0, MYSQL_TYPE_LONG), + mem_root); + + if (protocol_binary.send_result_set_metadata(&field_list, + Protocol::SEND_NUM_ROWS | + Protocol::SEND_EOF)) return TRUE; - } - collect_auto_increment_increment= variables.auto_increment_increment; - } + + return FALSE; } -void THD::stop_collecting_insert_id() + +bool THD::send_collected_insert_id() { - if (insert_ids) - { - delete_dynamic(insert_ids); - my_free(insert_ids); - insert_ids= NULL; - } + DBUG_ASSERT(insert_id_info->collect_auto_increment_increment); + protocol_binary.prepare_for_resend(); + protocol_binary.store_longlong(insert_id_info->first_id, TRUE); + protocol_binary.store_longlong(insert_id_info->sequence, TRUE); + protocol_binary.store_long(insert_id_info-> + collect_auto_increment_increment); + if (protocol_binary.write()) + return TRUE; + return FALSE; } + bool THD::collect_insert_id(ulonglong id) { - if (insert_ids) + if (insert_id_info) { - if (insert_ids->elements) + if (insert_id_info->collect_auto_increment_increment) { - insert_id_desc *last= - (insert_id_desc *)dynamic_array_ptr(insert_ids, - insert_ids->elements - 1); - if (id == last->first_id) + if (id == insert_id_info->first_id) { return FALSE; // no new insert id } - if (id == last->first_id + (last->sequence * - collect_auto_increment_increment)) + if (id == insert_id_info->first_id + (insert_id_info->sequence * + insert_id_info-> + collect_auto_increment_increment)) { - last->sequence++; + insert_id_info->sequence++; return FALSE; } + + if (send_collected_insert_id()) + return TRUE; } - insert_id_desc el; - el.first_id= id; - el.sequence= 1; - if (insert_dynamic(insert_ids, &el)) - { - return TRUE; - } + else + insert_id_info->collect_auto_increment_increment= + variables.auto_increment_increment; + + insert_id_info->first_id= id; + insert_id_info->sequence= 1; } return FALSE; } +/** + Check is insert ID data was connected and push out rest of it and stop + collecting + + @retval TRUE insert IDs was colleted + @retval FALSE insert IDs was not colleted +*/ bool THD::report_collected_insert_id() { - if (insert_ids) + if (insert_id_info) { - List<Item> field_list; - MEM_ROOT tmp_mem_root; - Query_arena arena(&tmp_mem_root, Query_arena::STMT_INITIALIZED), backup; - - init_alloc_root(arena.mem_root, " THD::report_collected_insert_i", - 2048, 4096, MYF(MY_THREAD_SPECIFIC)); - set_n_backup_active_arena(&arena, &backup); - DBUG_ASSERT(mem_root == &tmp_mem_root); - - field_list.push_back(new (mem_root) - Item_int(this, "Id", 0, MY_INT64_NUM_DECIMAL_DIGITS), - mem_root); - field_list.push_back(new (mem_root) - Item_int(this, "Len", 0, MY_INT64_NUM_DECIMAL_DIGITS), - mem_root); - field_list.push_back(new (mem_root) - Item_return_int(this, "Inc", 0, MYSQL_TYPE_LONG), - mem_root); - - if (protocol_binary.send_result_set_metadata(&field_list, - Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - goto error; + /* + No need to check an error it will be done on after exit from this + method + */ + send_collected_insert_id(); - for (ulonglong i= 0; i < insert_ids->elements; i++) - { - insert_id_desc *last= - (insert_id_desc *)dynamic_array_ptr(insert_ids, i); - if (insert_ids->elements == 1 && last->first_id == 0 && - get_stmt_da()->affected_rows() != 1) - continue; // No insert IDs - protocol_binary.prepare_for_resend(); - protocol_binary.store_longlong(last->first_id, TRUE); - protocol_binary.store_longlong(last->sequence, TRUE); - protocol_binary.store_long(collect_auto_increment_increment); - if (protocol_binary.write()) - goto error; - } -error: - restore_active_arena(&arena, &backup); - DBUG_ASSERT(arena.mem_root == &tmp_mem_root); - // no need free Items because they was only constants - free_root(arena.mem_root, MYF(0)); stop_collecting_insert_id(); return TRUE; } diff --git a/sql/sql_class.h b/sql/sql_class.h index 5fb6a6c575e..b583c53013e 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -4903,12 +4903,13 @@ class THD :public Statement, } /* Data and methods for buld INSERT IDs reporting */ - DYNAMIC_ARRAY *insert_ids; - ulong collect_auto_increment_increment; + //DYNAMIC_ARRAY *insert_ids; + insert_id_desc *insert_id_info; bool init_collecting_insert_id(); + bool send_collected_insert_id(); bool collect_insert_id(ulonglong id); bool report_collected_insert_id(); - void stop_collecting_insert_id(); + void stop_collecting_insert_id() { insert_id_info= NULL; } }; inline void add_to_active_threads(THD *thd)
participants (1)
-
Oleksandr Byelkin