107
106
sql_command_flags[SQLCOM_DROP_INDEX]= CF_CHANGES_DATA;
109
108
sql_command_flags[SQLCOM_UPDATE]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT;
109
sql_command_flags[SQLCOM_UPDATE_MULTI]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT;
110
110
sql_command_flags[SQLCOM_INSERT]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT;
111
111
sql_command_flags[SQLCOM_INSERT_SELECT]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT;
112
112
sql_command_flags[SQLCOM_DELETE]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT;
113
sql_command_flags[SQLCOM_DELETE_MULTI]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT;
113
114
sql_command_flags[SQLCOM_REPLACE]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT;
114
115
sql_command_flags[SQLCOM_REPLACE_SELECT]= CF_CHANGES_DATA | CF_HAS_ROW_COUNT;
789
790
unit->select_limit_cnt,
790
791
lex->duplicates, lex->ignore);
793
case SQLCOM_UPDATE_MULTI:
795
assert(first_table == all_tables && first_table != 0);
796
if ((res= update_precheck(session, all_tables)))
799
if ((res= mysql_multi_update_prepare(session)))
802
res= mysql_multi_update(session, all_tables,
803
&select_lex->item_list,
807
lex->duplicates, lex->ignore, unit, select_lex);
792
810
case SQLCOM_REPLACE:
793
811
case SQLCOM_INSERT:
886
904
res= mysql_truncate(session, first_table, 0);
909
assert(first_table == all_tables && first_table != 0);
910
assert(select_lex->offset_limit == 0);
911
unit->set_limit(select_lex);
913
if (!(need_start_waiting= !wait_if_global_read_lock(session, 0, 1)))
919
res = mysql_delete(session, all_tables, select_lex->where,
920
&select_lex->order_list,
921
unit->select_limit_cnt, select_lex->options,
925
case SQLCOM_DELETE_MULTI:
927
assert(first_table == all_tables && first_table != 0);
928
TableList *aux_tables=
929
(TableList *)session->lex->auxiliary_table_list.first;
930
multi_delete *del_result;
932
if (!(need_start_waiting= !wait_if_global_read_lock(session, 0, 1)))
938
if ((res= multi_delete_precheck(session, all_tables)))
941
/* condition will be true on SP re-excuting */
942
if (select_lex->item_list.elements != 0)
943
select_lex->item_list.empty();
944
if (session->add_item_to_list(new Item_null()))
947
session->set_proc_info("init");
948
if ((res= session->open_and_lock_tables(all_tables)))
951
if ((res= mysql_multi_delete_prepare(session)))
954
if (!session->is_fatal_error &&
955
(del_result= new multi_delete(aux_tables, lex->table_count)))
957
res= mysql_select(session, &select_lex->ref_pointer_array,
958
select_lex->get_table_list(),
959
select_lex->with_wild,
960
select_lex->item_list,
962
0, (order_st *)NULL, (order_st *)NULL, (Item *)NULL,
963
select_lex->options | session->options | SELECT_NO_JOIN_CACHE | SELECT_NO_UNLOCK | OPTION_SETUP_TABLES_DONE,
964
del_result, unit, select_lex);
965
res|= session->is_error();
889
974
case SQLCOM_DROP_TABLE:
891
976
assert(first_table == all_tables && first_table != 0);
1712
save order by and tables in own lists.
1715
bool add_to_list(Session *session, SQL_LIST &list,Item *item,bool asc)
1718
if (!(order = (order_st *) session->alloc(sizeof(order_st))))
1720
order->item_ptr= item;
1721
order->item= &order->item_ptr;
1725
order->counter_used= 0;
1726
list.link_in_list((unsigned char*) order,(unsigned char**) &order->next);
1604
1732
Add a table to list of used tables.
1606
1734
@param table Table to add
2532
Multi delete query pre-check.
2534
@param session Thread handler
2535
@param tables Global/local table list
2543
bool multi_delete_precheck(Session *session, TableList *)
2545
Select_Lex *select_lex= &session->lex->select_lex;
2546
TableList **save_query_tables_own_last= session->lex->query_tables_own_last;
2548
session->lex->query_tables_own_last= 0;
2549
session->lex->query_tables_own_last= save_query_tables_own_last;
2551
if ((session->options & OPTION_SAFE_UPDATES) && !select_lex->where)
2553
my_message(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE,
2554
ER(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE), MYF(0));
2562
Given a table in the source list, find a correspondent table in the
2563
table references list.
2565
@param lex Pointer to LEX representing multi-delete.
2566
@param src Source table to match.
2567
@param ref Table references list.
2569
@remark The source table list (tables listed before the FROM clause
2570
or tables listed in the FROM clause before the USING clause) may
2571
contain table names or aliases that must match unambiguously one,
2572
and only one, table in the target table list (table references list,
2573
after FROM/USING clause).
2575
@return Matching table, NULL otherwise.
2578
static TableList *multi_delete_table_match(LEX *, TableList *tbl,
2581
TableList *match= NULL;
2583
for (TableList *elem= tables; elem; elem= elem->next_local)
2587
if (tbl->is_fqtn && elem->is_alias)
2588
continue; /* no match */
2589
if (tbl->is_fqtn && elem->is_fqtn)
2590
cmp= my_strcasecmp(table_alias_charset, tbl->table_name, elem->table_name) ||
2591
strcmp(tbl->db, elem->db);
2592
else if (elem->is_alias)
2593
cmp= my_strcasecmp(table_alias_charset, tbl->alias, elem->alias);
2595
cmp= my_strcasecmp(table_alias_charset, tbl->table_name, elem->table_name) ||
2596
strcmp(tbl->db, elem->db);
2603
my_error(ER_NONUNIQ_TABLE, MYF(0), elem->alias);
2611
my_error(ER_UNKNOWN_TABLE, MYF(0), tbl->table_name, "MULTI DELETE");
2618
Link tables in auxilary table list of multi-delete with corresponding
2619
elements in main table list, and set proper locks for them.
2621
@param lex pointer to LEX representing multi-delete
2629
bool multi_delete_set_locks_and_link_aux_tables(LEX *lex)
2631
TableList *tables= (TableList*)lex->select_lex.table_list.first;
2632
TableList *target_tbl;
2634
lex->table_count= 0;
2636
for (target_tbl= (TableList *)lex->auxiliary_table_list.first;
2637
target_tbl; target_tbl= target_tbl->next_local)
2640
/* All tables in aux_tables must be found in FROM PART */
2641
TableList *walk= multi_delete_table_match(lex, target_tbl, tables);
2646
target_tbl->table_name= walk->table_name;
2647
target_tbl->table_name_length= walk->table_name_length;
2649
walk->updating= target_tbl->updating;
2650
walk->lock_type= target_tbl->lock_type;
2651
target_tbl->correspondent_table= walk; // Remember corresponding table
2403
2658
simple INSERT query pre-check.