Below is the list of changes that have just been committed into a local
5.0 repository of evgen. When evgen does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet@stripped, 2006-07-13 18:16:16+04:00, evgen@stripped +8 -0
Merge epotemkin@stripped:/home/bk/mysql-5.0
into moonbone.local:/work/tmp_merge-5.0-opt-mysql
MERGE: 1.2213.2.1
mysql-test/r/rpl_insert_id.result@stripped, 2006-07-13 18:16:12+04:00, evgen@stripped
+0 -0
Auto merged
MERGE: 1.14.1.2
mysql-test/t/rpl_insert_id.test@stripped, 2006-07-13 18:16:12+04:00, evgen@stripped +0
-0
Auto merged
MERGE: 1.16.1.2
sql/item_strfunc.cc@stripped, 2006-07-13 18:16:12+04:00, evgen@stripped +0 -0
Auto merged
MERGE: 1.272.1.1
sql/item_strfunc.h@stripped, 2006-07-13 18:16:12+04:00, evgen@stripped +0 -0
Auto merged
MERGE: 1.108.1.1
sql/sql_class.cc@stripped, 2006-07-13 18:16:12+04:00, evgen@stripped +0 -0
Auto merged
MERGE: 1.236.2.1
sql/sql_class.h@stripped, 2006-07-13 18:16:12+04:00, evgen@stripped +0 -0
Auto merged
MERGE: 1.292.1.1
sql/sql_insert.cc@stripped, 2006-07-13 18:16:12+04:00, evgen@stripped +0 -0
Auto merged
MERGE: 1.194.1.3
sql/sql_select.cc@stripped, 2006-07-13 18:16:12+04:00, evgen@stripped +0 -0
Auto merged
MERGE: 1.428.1.1
# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: evgen
# Host: moonbone.local
# Root: /work/tmp_merge-5.0-opt-mysql/RESYNC
--- 1.273/sql/item_strfunc.cc 2006-07-13 18:16:21 +04:00
+++ 1.274/sql/item_strfunc.cc 2006-07-13 18:16:21 +04:00
@@ -752,44 +752,47 @@
{
DBUG_ASSERT(fixed == 1);
String *res = args[0]->val_str(str);
- char *ptr,*end;
+ char *ptr, *end, *tmp;
if ((null_value=args[0]->null_value))
return 0;
/* An empty string is a special case as the string pointer may be null */
if (!res->length())
return &my_empty_string;
- res=copy_if_not_alloced(str,res,res->length());
- ptr = (char *) res->ptr();
- end=ptr+res->length();
+ if (tmp_value.alloced_length() < res->length() &&
+ tmp_value.realloc(res->length()))
+ {
+ null_value= 1;
+ return 0;
+ }
+ tmp_value.length(res->length());
+ tmp_value.set_charset(res->charset());
+ ptr= (char *) res->ptr();
+ end= ptr + res->length();
+ tmp= (char *) tmp_value.ptr() + tmp_value.length();
#ifdef USE_MB
if (use_mb(res->charset()))
{
- String tmpstr;
- tmpstr.copy(*res);
- char *tmp = (char *) tmpstr.ptr() + tmpstr.length();
register uint32 l;
while (ptr < end)
{
- if ((l=my_ismbchar(res->charset(), ptr,end)))
- tmp-=l, memcpy(tmp,ptr,l), ptr+=l;
+ if ((l= my_ismbchar(res->charset(),ptr,end)))
+ {
+ tmp-= l;
+ memcpy(tmp,ptr,l);
+ ptr+= l;
+ }
else
- *--tmp=*ptr++;
+ *--tmp= *ptr++;
}
- memcpy((char *) res->ptr(),(char *) tmpstr.ptr(), res->length());
}
else
#endif /* USE_MB */
{
- char tmp;
while (ptr < end)
- {
- tmp=*ptr;
- *ptr++=*--end;
- *end=tmp;
- }
+ *--tmp= *ptr++;
}
- return res;
+ return &tmp_value;
}
--- 1.109/sql/item_strfunc.h 2006-07-13 18:16:21 +04:00
+++ 1.110/sql/item_strfunc.h 2006-07-13 18:16:21 +04:00
@@ -102,6 +102,7 @@
class Item_func_reverse :public Item_str_func
{
+ String tmp_value;
public:
Item_func_reverse(Item *a) :Item_str_func(a) {}
String *val_str(String *);
--- 1.239/sql/sql_class.cc 2006-07-13 18:16:21 +04:00
+++ 1.240/sql/sql_class.cc 2006-07-13 18:16:21 +04:00
@@ -269,6 +269,7 @@
tablespace_op=FALSE;
ulong tmp=sql_rnd_with_mutex();
randominit(&rand, tmp + (ulong) &rand, tmp + (ulong) ::query_id);
+ substitute_null_with_insert_id = FALSE;
thr_lock_info_init(&lock_info); /* safety: will be reset after start */
thr_lock_owner_init(&main_lock_id, &lock_info);
}
--- 1.293/sql/sql_class.h 2006-07-13 18:16:21 +04:00
+++ 1.294/sql/sql_class.h 2006-07-13 18:16:21 +04:00
@@ -1324,6 +1324,8 @@
bool no_errors, password, is_fatal_error;
bool query_start_used, rand_used, time_zone_used;
bool last_insert_id_used,insert_id_used, clear_next_insert_id;
+ /* for IS NULL => = last_insert_id() fix in remove_eq_conds() */
+ bool substitute_null_with_insert_id;
bool in_lock_tables;
bool query_error, bootstrap, cleanup_done;
bool tmp_table_used;
@@ -1455,6 +1457,7 @@
{
last_insert_id= id_arg;
insert_id_used=1;
+ substitute_null_with_insert_id= TRUE;
}
inline ulonglong insert_id(void)
{
--- 1.195/sql/sql_insert.cc 2006-07-13 18:16:21 +04:00
+++ 1.196/sql/sql_insert.cc 2006-07-13 18:16:21 +04:00
@@ -17,6 +17,44 @@
/* Insert of records */
+/*
+ INSERT DELAYED
+
+ Insert delayed is distinguished from a normal insert by lock_type ==
+ TL_WRITE_DELAYED instead of TL_WRITE. It first tries to open a
+ "delayed" table (delayed_get_table()), but falls back to
+ open_and_lock_tables() on error and proceeds as normal insert then.
+
+ Opening a "delayed" table means to find a delayed insert thread that
+ has the table open already. If this fails, a new thread is created and
+ waited for to open and lock the table.
+
+ If accessing the thread succeeded, in
+ delayed_insert::get_local_table() the table of the thread is copied
+ for local use. A copy is required because the normal insert logic
+ works on a target table, but the other threads table object must not
+ be used. The insert logic uses the record buffer to create a record.
+ And the delayed insert thread uses the record buffer to pass the
+ record to the table handler. So there must be different objects. Also
+ the copied table is not included in the lock, so that the statement
+ can proceed even if the real table cannot be accessed at this moment.
+
+ Copying a table object is not a trivial operation. Besides the TABLE
+ object there are the field pointer array, the field objects and the
+ record buffer. After copying the field objects, their pointers into
+ the record must be "moved" to point to the new record buffer.
+
+ After this setup the normal insert logic is used. Only that for
+ delayed inserts write_delayed() is called instead of write_record().
+ It inserts the rows into a queue and signals the delayed insert thread
+ instead of writing directly to the table.
+
+ The delayed insert thread awakes from the signal. It locks the table,
+ inserts the rows from the queue, unlocks the table, and waits for the
+ next signal. It does normally live until a FLUSH TABLES or SHUTDOWN.
+
+*/
+
#include "mysql_priv.h"
#include "sp_head.h"
#include "sql_trigger.h"
@@ -241,6 +279,33 @@
}
+/*
+ Mark fields used by triggers for INSERT-like statement.
+
+ SYNOPSIS
+ mark_fields_used_by_triggers_for_insert_stmt()
+ thd The current thread
+ table Table to which insert will happen
+ duplic Type of duplicate handling for insert which will happen
+
+ NOTE
+ For REPLACE there is no sense in marking particular fields
+ used by ON DELETE trigger as to execute it properly we have
+ to retrieve and store values for all table columns anyway.
+*/
+
+void mark_fields_used_by_triggers_for_insert_stmt(THD *thd, TABLE *table,
+ enum_duplicates duplic)
+{
+ if (table->triggers)
+ {
+ table->triggers->mark_fields_used(thd, TRG_EVENT_INSERT);
+ if (duplic == DUP_UPDATE)
+ table->triggers->mark_fields_used(thd, TRG_EVENT_UPDATE);
+ }
+}
+
+
bool mysql_insert(THD *thd,TABLE_LIST *table_list,
List<Item> &fields,
List<List_item> &values_list,
@@ -400,6 +465,17 @@
thd->proc_info="update";
if (duplic != DUP_ERROR || ignore)
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
+ if (duplic == DUP_REPLACE)
+ {
+ if (!table->triggers || !table->triggers->has_delete_triggers())
+ table->file->extra(HA_EXTRA_WRITE_CAN_REPLACE);
+ /*
+ REPLACE should change values of all columns so we should mark
+ all columns as columns to be set. As nice side effect we will
+ retrieve columns which values are needed for ON DELETE triggers.
+ */
+ table->file->extra(HA_EXTRA_RETRIEVE_ALL_COLS);
+ }
/*
let's *try* to start bulk inserts. It won't necessary
start them as values_list.elements should be greater than
@@ -428,6 +504,8 @@
error= 1;
}
+ mark_fields_used_by_triggers_for_insert_stmt(thd, table, duplic);
+
if (table_list->prepare_where(thd, 0, TRUE) ||
table_list->prepare_check_option(thd))
error= 1;
@@ -598,6 +676,9 @@
thd->next_insert_id=0; // Reset this if wrongly used
if (duplic != DUP_ERROR || ignore)
table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
+ if (duplic == DUP_REPLACE &&
+ (!table->triggers || !table->triggers->has_delete_triggers()))
+ table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
/* Reset value of LAST_INSERT_ID if no rows where inserted */
if (!info.copied && thd->insert_id_used)
@@ -967,7 +1048,6 @@
uint key_nr;
if (error != HA_WRITE_SKIP)
goto err;
- table->file->restore_auto_increment();
if ((int) (key_nr = table->file->get_dup_key(error)) < 0)
{
error=HA_WRITE_SKIP; /* Database can't find key */
@@ -1040,20 +1120,20 @@
if (res == VIEW_CHECK_ERROR)
goto before_trg_err;
- if (thd->clear_next_insert_id)
- {
- /* Reset auto-increment cacheing if we do an update */
- thd->clear_next_insert_id= 0;
- thd->next_insert_id= 0;
- }
if
((error=table->file->update_row(table->record[1],table->record[0])))
{
if ((error == HA_ERR_FOUND_DUPP_KEY) && info->ignore)
+ {
+ table->file->restore_auto_increment();
goto ok_or_after_trg_err;
+ }
goto err;
}
info->updated++;
+ if (table->next_number_field)
+
table->file->adjust_next_insert_id_after_explicit_value(table->next_number_field->val_int());
+
trg_error= (table->triggers &&
table->triggers->process_triggers(thd, TRG_EVENT_UPDATE,
TRG_ACTION_AFTER, TRUE));
@@ -1082,12 +1162,6 @@
table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_BOTH) &&
(!table->triggers || !table->triggers->has_delete_triggers()))
{
- if (thd->clear_next_insert_id)
- {
- /* Reset auto-increment cacheing if we do an update */
- thd->clear_next_insert_id= 0;
- thd->next_insert_id= 0;
- }
if ((error=table->file->update_row(table->record[1],
table->record[0])))
goto err;
@@ -1151,6 +1225,7 @@
table->file->print_error(error,MYF(0));
before_trg_err:
+ table->file->restore_auto_increment();
if (key)
my_safe_afree(key, table->s->max_unique_length, MAX_KEY_LENGTH);
DBUG_RETURN(1);
@@ -1454,6 +1529,7 @@
my_ptrdiff_t adjust_ptrs;
Field **field,**org_field, *found_next_number_field;
TABLE *copy;
+ DBUG_ENTER("delayed_insert::get_local_table");
/* First request insert thread to get a lock */
status=1;
@@ -1477,31 +1553,47 @@
}
}
+ /*
+ Allocate memory for the TABLE object, the field pointers array, and
+ one record buffer of reclength size. Normally a table has three
+ record buffers of rec_buff_length size, which includes alignment
+ bytes. Since the table copy is used for creating one record only,
+ the other record buffers and alignment are unnecessary.
+ */
client_thd->proc_info="allocating local table";
copy= (TABLE*) client_thd->alloc(sizeof(*copy)+
(table->s->fields+1)*sizeof(Field**)+
table->s->reclength);
if (!copy)
goto error;
+
+ /* Copy the TABLE object. */
*copy= *table;
copy->s= ©->share_not_to_be_used;
// No name hashing
bzero((char*) ©->s->name_hash,sizeof(copy->s->name_hash));
/* We don't need to change the file handler here */
- field=copy->field=(Field**) (copy+1);
- copy->record[0]=(byte*) (field+table->s->fields+1);
- memcpy((char*) copy->record[0],(char*)
table->record[0],table->s->reclength);
-
- /* Make a copy of all fields */
+ /* Assign the pointers for the field pointers array and the record. */
+ field= copy->field= (Field**) (copy + 1);
+ copy->record[0]= (byte*) (field + table->s->fields + 1);
+ memcpy((char*) copy->record[0], (char*) table->record[0],
+ table->s->reclength);
- adjust_ptrs=PTR_BYTE_DIFF(copy->record[0],table->record[0]);
+ /*
+ Make a copy of all fields.
+ The copied fields need to point into the copied record. This is done
+ by copying the field objects with their old pointer values and then
+ "move" the pointers by the distance between the original and copied
+ records. That way we preserve the relative positions in the records.
+ */
+ adjust_ptrs= PTR_BYTE_DIFF(copy->record[0], table->record[0]);
- found_next_number_field=table->found_next_number_field;
- for (org_field=table->field ; *org_field ; org_field++,field++)
+ found_next_number_field= table->found_next_number_field;
+ for (org_field= table->field; *org_field; org_field++, field++)
{
- if (!(*field= (*org_field)->new_field(client_thd->mem_root,copy)))
- return 0;
+ if (!(*field= (*org_field)->new_field(client_thd->mem_root, copy, 1)))
+ DBUG_RETURN(0);
(*field)->orig_table= copy; // Remove connection
(*field)->move_field(adjust_ptrs); // Point at copy->record[0]
if (*org_field == found_next_number_field)
@@ -1528,14 +1620,14 @@
/* Adjust lock_count. This table object is not part of a lock. */
copy->lock_count= 0;
- return copy;
+ DBUG_RETURN(copy);
/* Got fatal error */
error:
tables_in_use--;
status=1;
pthread_cond_signal(&cond); // Inform thread about abort
- return 0;
+ DBUG_RETURN(0);
}
@@ -1892,7 +1984,8 @@
{
int error;
ulong max_rows;
- bool using_ignore=0, using_bin_log=mysql_bin_log.is_open();
+ bool using_ignore= 0, using_opt_replace= 0;
+ bool using_bin_log= mysql_bin_log.is_open();
delayed_row *row;
DBUG_ENTER("handle_inserts");
@@ -1954,6 +2047,13 @@
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
using_ignore=1;
}
+ if (info.handle_duplicates == DUP_REPLACE &&
+ (!table->triggers ||
+ !table->triggers->has_delete_triggers()))
+ {
+ table->file->extra(HA_EXTRA_WRITE_CAN_REPLACE);
+ using_opt_replace= 1;
+ }
thd.clear_error(); // reset error for binlog
if (write_record(&thd, table, &info))
{
@@ -1966,6 +2066,11 @@
using_ignore=0;
table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
}
+ if (using_opt_replace)
+ {
+ using_opt_replace= 0;
+ table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
+ }
if (row->query && row->log_query && using_bin_log)
{
Query_log_event qinfo(&thd, row->query, row->query_length, 0, FALSE);
@@ -2211,6 +2316,12 @@
thd->cuted_fields=0;
if (info.ignore || info.handle_duplicates != DUP_ERROR)
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
+ if (info.handle_duplicates == DUP_REPLACE)
+ {
+ if (!table->triggers || !table->triggers->has_delete_triggers())
+ table->file->extra(HA_EXTRA_WRITE_CAN_REPLACE);
+ table->file->extra(HA_EXTRA_RETRIEVE_ALL_COLS);
+ }
thd->no_trans_update= 0;
thd->abort_on_warning= (!info.ignore &&
(thd->variables.sql_mode &
@@ -2220,6 +2331,10 @@
check_that_all_fields_are_given_values(thd, table, table_list)) ||
table_list->prepare_where(thd, 0, TRUE) ||
table_list->prepare_check_option(thd));
+
+ if (!res)
+ mark_fields_used_by_triggers_for_insert_stmt(thd, table,
+ info.handle_duplicates);
DBUG_RETURN(res);
}
@@ -2385,6 +2500,7 @@
error= (!thd->prelocked_mode) ? table->file->end_bulk_insert():0;
table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
+ table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
/*
We must invalidate the table in the query cache before binlog writing
@@ -2614,6 +2730,12 @@
thd->cuted_fields=0;
if (info.ignore || info.handle_duplicates != DUP_ERROR)
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
+ if (info.handle_duplicates == DUP_REPLACE)
+ {
+ if (!table->triggers || !table->triggers->has_delete_triggers())
+ table->file->extra(HA_EXTRA_WRITE_CAN_REPLACE);
+ table->file->extra(HA_EXTRA_RETRIEVE_ALL_COLS);
+ }
if (!thd->prelocked_mode)
table->file->start_bulk_insert((ha_rows) 0);
thd->no_trans_update= 0;
@@ -2653,6 +2775,7 @@
else
{
table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
+ table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
VOID(pthread_mutex_lock(&LOCK_open));
mysql_unlock_tables(thd, lock);
/*
@@ -2686,6 +2809,7 @@
if (table)
{
table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
+ table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
enum db_type table_type=table->s->db_type;
if (!table->s->tmp_table)
{
--- 1.429/sql/sql_select.cc 2006-07-13 18:16:21 +04:00
+++ 1.430/sql/sql_select.cc 2006-07-13 18:16:21 +04:00
@@ -7854,7 +7854,7 @@
Field *field=((Item_field*) args[0])->field;
if (field->flags & AUTO_INCREMENT_FLAG &&
!field->table->maybe_null &&
(thd->options & OPTION_AUTO_IS_NULL) &&
- thd->insert_id())
+ thd->insert_id() && thd->substitute_null_with_insert_id)
{
#ifdef HAVE_QUERY_CACHE
query_cache_abort(&thd->net);
@@ -7873,7 +7873,7 @@
*/
cond->fix_fields(thd, &cond);
}
- thd->insert_id(0); // Clear for next request
+ thd->substitute_null_with_insert_id= FALSE; // Clear for next request
}
/* fix to replace 'NULL' dates with '0' (shreeve@stripped) */
else if (((field->type() == FIELD_TYPE_DATE) ||
--- 1.15/mysql-test/r/rpl_insert_id.result 2006-07-13 18:16:21 +04:00
+++ 1.16/mysql-test/r/rpl_insert_id.result 2006-07-13 18:16:21 +04:00
@@ -74,6 +74,19 @@
INSERT INTO t1 VALUES (1),(1);
ERROR 23000: Duplicate entry '1' for key 1
drop table t1;
+create table t1(a int auto_increment, key(a));
+create table t2(a int);
+insert into t1 (a) values (null);
+insert into t2 (a) select a from t1 where a is null;
+insert into t2 (a) select a from t1 where a is null;
+select * from t2;
+a
+1
+select * from t2;
+a
+1
+drop table t1;
+drop table t2;
drop function if exists bug15728;
drop function if exists bug15728_insert;
drop table if exists t1, t2;
--- 1.17/mysql-test/t/rpl_insert_id.test 2006-07-13 18:16:21 +04:00
+++ 1.18/mysql-test/t/rpl_insert_id.test 2006-07-13 18:16:21 +04:00
@@ -77,6 +77,24 @@
connection master;
drop table t1;
sync_slave_with_master;
+
+#
+# Bug#14553: NULL in WHERE resets LAST_INSERT_ID
+#
+connection master;
+create table t1(a int auto_increment, key(a));
+create table t2(a int);
+insert into t1 (a) values (null);
+insert into t2 (a) select a from t1 where a is null;
+insert into t2 (a) select a from t1 where a is null;
+select * from t2;
+sync_slave_with_master;
+connection slave;
+select * from t2;
+connection master;
+drop table t1;
+drop table t2;
+sync_slave_with_master;
# End of 4.1 tests
| Thread |
|---|
| • bk commit into 5.0 tree (evgen:1.2234) | eugene | 15 Jul |