You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-30 19:23:07 +03:00
MCOL-5943: MCOL-4740 update rows counter for multi-table update (#3555)
* fix(plugin): MCOL-4740: This fixes update rows counter for multi-table update For UPDATEs involving a single table, the server call to handler::direct_update_rows() is used to correctly set the count for the number of updated rows in the UPDATE statement. However, for UPDATEs involving multi-tables, the server does not call handler::direct_update_rows(). This patch adds support to correctly report the number of updated rows to the client by setting multi_update::updated and multi_update::found in handler::rnd_end(). * fix(plugin): MCOL-4740: this is to addres the original patch QA found in the original patch --------- Co-authored-by: Roman Nozdrin <rnozdrin@mariadb.com> Co-authored-by: drrtuy <roman.nozdrin@mariadb.com>
This commit is contained in:
@ -17,8 +17,40 @@
|
||||
#include <typeinfo>
|
||||
#include <string>
|
||||
|
||||
// This makes specific MDB classes' attributes public to implement
|
||||
// MCOL-4740 temporary solution. Search for MCOL-4740
|
||||
// to get the actual place where it is used.
|
||||
#define updated_leaves \
|
||||
updated_leaves; \
|
||||
\
|
||||
public:
|
||||
|
||||
#include "ha_mcs_pushdown.h"
|
||||
|
||||
void update_counters_on_multi_update()
|
||||
{
|
||||
if (ha_mcs_common::isMultiUpdateStatement(current_thd->lex->sql_command) &&
|
||||
!ha_mcs_common::isForeignTableUpdate(current_thd))
|
||||
{
|
||||
SELECT_LEX_UNIT* unit = ¤t_thd->lex->unit;
|
||||
SELECT_LEX* select_lex = unit->first_select();
|
||||
auto* multi = (select_lex->join) ? reinterpret_cast<multi_update*>(select_lex->join->result) : nullptr;
|
||||
|
||||
if (multi)
|
||||
{
|
||||
multi->table_to_update = multi->update_tables ? multi->update_tables->table : 0;
|
||||
|
||||
cal_impl_if::cal_connection_info* ci =
|
||||
reinterpret_cast<cal_impl_if::cal_connection_info*>(get_fe_conn_info_ptr());
|
||||
|
||||
if (ci)
|
||||
{
|
||||
multi->updated = multi->found = ci->affectedRows;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void check_walk(const Item* item, void* arg);
|
||||
|
||||
void restore_query_state(ha_columnstore_select_handler* handler)
|
||||
@ -391,7 +423,7 @@ derived_handler* create_columnstore_derived_handler(THD* thd, TABLE_LIST* table_
|
||||
|
||||
// MCOL-1482 Disable derived_handler if the multi-table update
|
||||
// statement contains a non-columnstore table.
|
||||
if (cal_impl_if::isUpdateHasForeignTable(thd))
|
||||
if (ha_mcs_common::isUpdateHasForeignTable(thd))
|
||||
{
|
||||
return handler;
|
||||
}
|
||||
@ -551,18 +583,18 @@ void ha_columnstore_derived_handler::print_error(int, unsigned long)
|
||||
|
||||
/*@brief create_columnstore_select_handler_- Creates handler
|
||||
************************************************************
|
||||
* DESCRIPTION:
|
||||
* Creates a select handler if there is no non-equi JOIN, e.g
|
||||
* t1.c1 > t2.c2 and logical OR in the filter predicates.
|
||||
* More details in server/sql/select_handler.h
|
||||
* PARAMETERS:
|
||||
* thd - THD pointer.
|
||||
* sel_lex - SELECT_LEX* that describes the query.
|
||||
* sel_unit - SELECT_LEX_UNIT* that describes the query.
|
||||
* RETURN:
|
||||
* select_handler if possible
|
||||
* NULL in other case
|
||||
***********************************************************/
|
||||
* DESCRIPTION:
|
||||
* Creates a select handler if there is no non-equi JOIN, e.g
|
||||
* t1.c1 > t2.c2 and logical OR in the filter predicates.
|
||||
* More details in server/sql/select_handler.h
|
||||
* PARAMETERS:
|
||||
* thd - THD pointer.
|
||||
* sel_lex - SELECT_LEX* that describes the query.
|
||||
* sel_unit - SELECT_LEX_UNIT* that describes the query.
|
||||
* RETURN:
|
||||
* select_handler if possible
|
||||
* NULL in other case
|
||||
***********************************************************/
|
||||
select_handler* create_columnstore_select_handler_(THD* thd, SELECT_LEX* sel_lex, SELECT_LEX_UNIT* sel_unit)
|
||||
{
|
||||
mcs_select_handler_mode_t select_handler_mode = get_select_handler_mode(thd);
|
||||
@ -578,7 +610,7 @@ select_handler* create_columnstore_select_handler_(THD* thd, SELECT_LEX* sel_lex
|
||||
// MCOL-1482 Disable select_handler for a multi-table update
|
||||
// with a non-columnstore table as the target table of the update
|
||||
// operation.
|
||||
if (cal_impl_if::isForeignTableUpdate(thd))
|
||||
if (ha_mcs_common::isForeignTableUpdate(thd))
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
@ -646,15 +678,15 @@ select_handler* create_columnstore_select_handler_(THD* thd, SELECT_LEX* sel_lex
|
||||
// or unsupported feature.
|
||||
ha_columnstore_select_handler* handler;
|
||||
|
||||
if (sel_unit && sel_lex) // partial pushdown of the SELECT_LEX_UNIT
|
||||
if (sel_unit && sel_lex) // partial pushdown of the SELECT_LEX_UNIT
|
||||
{
|
||||
handler = new ha_columnstore_select_handler(thd, sel_lex, sel_unit);
|
||||
}
|
||||
else if (sel_unit) // complete pushdown of the SELECT_LEX_UNIT
|
||||
else if (sel_unit) // complete pushdown of the SELECT_LEX_UNIT
|
||||
{
|
||||
handler = new ha_columnstore_select_handler(thd, sel_unit);
|
||||
}
|
||||
else // Query only has a SELECT_LEX, no SELECT_LEX_UNIT
|
||||
else // Query only has a SELECT_LEX, no SELECT_LEX_UNIT
|
||||
{
|
||||
handler = new ha_columnstore_select_handler(thd, sel_lex);
|
||||
}
|
||||
@ -749,8 +781,7 @@ select_handler* create_columnstore_select_handler_(THD* thd, SELECT_LEX* sel_lex
|
||||
select_lex != select_lex->master_unit()->fake_select_lex) // (2)
|
||||
thd->lex->set_limit_rows_examined();
|
||||
|
||||
if ((!sel_unit || sel_lex) && !join->tables_list &&
|
||||
(join->table_count || !select_lex->with_sum_func) &&
|
||||
if ((!sel_unit || sel_lex) && !join->tables_list && (join->table_count || !select_lex->with_sum_func) &&
|
||||
!select_lex->have_window_funcs())
|
||||
{
|
||||
if (!thd->is_error())
|
||||
@ -1010,6 +1041,11 @@ int ha_columnstore_select_handler::end_scan()
|
||||
|
||||
scan_ended = true;
|
||||
|
||||
// MCOL-4740 multi_update::send_eof(), which outputs the affected
|
||||
// number of rows to the client, is called after handler::rnd_end().
|
||||
// So we set multi_update::updated and multi_update::found here.
|
||||
update_counters_on_multi_update();
|
||||
|
||||
int rc = ha_mcs_impl_rnd_end(table, true);
|
||||
|
||||
DBUG_RETURN(rc);
|
||||
|
Reference in New Issue
Block a user