Commit 006ff09c authored by Sinisa@sinisa.nasamreza.org's avatar Sinisa@sinisa.nasamreza.org
Browse files

New alternate UNION syntax and bug fix for multi-table deletes

parent 386b5ad1
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -68,6 +68,12 @@ t2 c 1
t2	d	1
t2	e	1
t2	f	1
(select a,b from t1 limit 2)  union all (select a,b from t2 order by a) limit 4;
a	b
1	a
2	b
3	c
4	d
explain select a,b from t1 union all select a,b from t2;
table	type	possible_keys	key	key_len	ref	rows	Extra
t1	ALL	NULL	NULL	NULL	NULL	4	
+3 −0
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@ select 0,'#' union select a,b from t1 union all select a,b from t2 union select
select a,b from t1 union select a,b from t1;
select 't1',b,count(*) from t1 group by b UNION select 't2',b,count(*) from t2 group by b;

#test alternate syntax for unions 
(select a,b from t1 limit 2)  union all (select a,b from t2 order by a) limit 4;

# Test some error conditions with UNION
explain select a,b from t1 union all select a,b from t2;

+7 −7
Original line number Diff line number Diff line
@@ -455,11 +455,13 @@ int multi_delete::do_deletes (bool from_send_error)
bool multi_delete::send_eof()
{
  thd->proc_info="deleting from reference tables";  /* out: 1 if error, 0 if success */

  /* Does deletes for the last n - 1 tables, returns 0 if ok */
  int error = do_deletes(false);   /* do_deletes returns 0 if success */

  /* reset used flags */
  delete_tables->table->no_keyread=0;

  if (error == -1) error = 0;
  thd->proc_info="end";
  if (error)
  {
@@ -485,12 +487,10 @@ bool multi_delete::send_eof()
	!some_table_is_not_transaction_safe(delete_tables))
      error=1;  /* Log write failed: roll back
		   the SQL statement */
    if (deleted) 
    {
      /* If autocommit is on we do a commit, in an error case we
	 roll back the current SQL statement */
      VOID(ha_autocommit_or_rollback(thd, error != 0));
    }

    /* Commit or rollback the current SQL statement */ 

    VOID(ha_autocommit_or_rollback(thd,error > 0));
  }

  ::send_ok(&thd->net,deleted);
+1 −0
Original line number Diff line number Diff line
@@ -2406,6 +2406,7 @@ mysql_init_query(THD *thd)
  thd->fatal_error=0;				// Safety
  thd->last_insert_id_used=thd->query_start_used=thd->insert_id_used=0;
  thd->sent_row_count=thd->examined_row_count=0;
  thd->lex.sql_command=SQLCOM_SELECT;
  DBUG_VOID_RETURN;
}

+6 −5
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@

int mysql_union(THD *thd, LEX *lex,select_result *result)
{
  SELECT_LEX *sl, *last_sl, lex_sl;
  SELECT_LEX *sl, *last_sl=(SELECT_LEX *)NULL, lex_sl;
  ORDER *order;
  List<Item> item_list;
  TABLE *table;
@@ -38,7 +38,7 @@ int mysql_union(THD *thd, LEX *lex,select_result *result)
  DBUG_ENTER("mysql_union");

  /* Fix tables 'to-be-unioned-from' list to point at opened tables */
  for (sl=&lex->select_lex; sl && sl->linkage != NOT_A_SELECT; sl=sl->next)
  for (sl=&lex->select_lex; sl && sl->linkage != NOT_A_SELECT; last_sl=sl, sl=sl->next)
  {
    for (TABLE_LIST *cursor= (TABLE_LIST *)sl->table_list.first;
	 cursor;
@@ -50,6 +50,7 @@ int mysql_union(THD *thd, LEX *lex,select_result *result)
  {
    lex_sl=*sl;
    sl=(SELECT_LEX *)NULL;
    if (last_sl) last_sl->next=sl;
  }
  else
    lex_sl.linkage=UNSPECIFIED_TYPE;
@@ -68,7 +69,7 @@ int mysql_union(THD *thd, LEX *lex,select_result *result)
		       sl->item_list,
		       sl->where,
		       sl->ftfunc_list,
		       (sl->braces) ? (ORDER*) 0 : (ORDER *) sl->order_list.first,
		       (sl->braces) ? (ORDER *) sl->order_list.first : (ORDER *) 0,
		       (ORDER*) sl->group_list.first,
		       sl->having,
		       (ORDER*) NULL,
@@ -79,7 +80,7 @@ int mysql_union(THD *thd, LEX *lex,select_result *result)
    DBUG_RETURN(0);
  }

  order = (lex_sl.linkage == UNSPECIFIED_TYPE) ? (ORDER *) last_sl->order_list.first : (ORDER *) lex_sl.order_list.first;
  order = (lex_sl.linkage == UNSPECIFIED_TYPE) ? ( (last_sl->braces) ? (ORDER *) 0 :  (ORDER *) last_sl->order_list.first) : (ORDER *) lex_sl.order_list.first;

  {
    Item *item;
@@ -127,7 +128,7 @@ int mysql_union(THD *thd, LEX *lex,select_result *result)
		     sl->item_list,
		     sl->where,
		     sl->ftfunc_list,
		     (sl->braces) ? (ORDER*) 0 : (ORDER *)sl->order_list.first,
		     (sl->braces) ? (ORDER *)sl->order_list.first : (ORDER *) 0,
		     (ORDER*) sl->group_list.first,
		     sl->having,
		     (ORDER*) NULL,
Loading