List:Commits« Previous MessageNext Message »
From:Patrick Galbraith Date:January 8 2006 11:13pm
Subject:bk commit into 5.0 tree (patg:1.2021) BUG#14768
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of patg. When patg 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
  1.2021 06/01/08 15:13:44 patg@stripped +4 -0
  BUG# 14768
  
  Added last_insert_id() functionality.
  Fixed memory not freed issue with share->scheme

  sql/ha_federated.h
    1.23 06/01/08 15:13:30 patg@stripped +3 -0
    BUG# 14768
    
    Added DEFINEs for last_insert_id() text, delclaration of update_auto_increment

  sql/ha_federated.cc
    1.59 06/01/08 15:13:30 patg@stripped +62 -0
    BUG# 14768
    
    1. Added fix for making last_insert_id(). New function update_auto_increment called at the end
    of write_row in the even that the table has an auto_increment column.
    2. Fixed bug where share->socket wasn't freed.

  mysql-test/t/federated.test
    1.20 06/01/08 15:13:30 patg@stripped +30 -0
    BUG# 14768
    
    Added tests for testing last_insert_id()

  mysql-test/r/federated.result
    1.24 06/01/08 15:13:30 patg@stripped +42 -0
    BUG# 14768
    
    Added test results for testing last_insert_id

# 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:	patg
# Host:	krsna.patg.net
# Root:	/home/patg/mysql-build/mysql-5.0

--- 1.23/mysql-test/r/federated.result	2005-11-23 16:36:25 -08:00
+++ 1.24/mysql-test/r/federated.result	2006-01-08 15:13:30 -08:00
@@ -1517,6 +1517,48 @@
 drop table federated.t1;
 drop table federated.t1;
 DROP TABLE IF EXISTS federated.t1;
+Warnings:
+Note	1051	Unknown table 't1'
+CREATE TABLE federated.t1 (
+`id` int(20) NOT NULL auto_increment,
+PRIMARY KEY  (`id`));
+DROP TABLE IF EXISTS federated.t1;
+Warnings:
+Note	1051	Unknown table 't1'
+CREATE TABLE federated.t1 (
+`id` int(20) NOT NULL auto_increment,
+PRIMARY KEY  (`id`)
+)
+ENGINE="FEDERATED" DEFAULT CHARSET=latin1
+CONNECTION='mysql://root@stripped:9308/federated/t1';
+INSERT INTO federated.t1 VALUES ();
+SELECT LAST_INSERT_ID();
+LAST_INSERT_ID()
+1
+INSERT INTO federated.t1 VALUES ();
+SELECT LAST_INSERT_ID();
+LAST_INSERT_ID()
+2
+INSERT INTO federated.t1 VALUES ();
+SELECT LAST_INSERT_ID();
+LAST_INSERT_ID()
+3
+INSERT INTO federated.t1 VALUES ();
+SELECT LAST_INSERT_ID();
+LAST_INSERT_ID()
+4
+INSERT INTO federated.t1 VALUES ();
+SELECT LAST_INSERT_ID();
+LAST_INSERT_ID()
+5
+SELECT * FROM federated.t1;
+id
+1
+2
+3
+4
+5
+DROP TABLE IF EXISTS federated.t1;
 DROP DATABASE IF EXISTS federated;
 DROP TABLE IF EXISTS federated.t1;
 DROP DATABASE IF EXISTS federated;

--- 1.19/mysql-test/t/federated.test	2005-10-31 17:26:36 -08:00
+++ 1.20/mysql-test/t/federated.test	2006-01-08 15:13:30 -08:00
@@ -1224,4 +1224,34 @@
 connection slave;
 drop table federated.t1;
 
+#
+# BUG# 14768 test auto_increment last_insert_id()
+# 
+connection slave;
+DROP TABLE IF EXISTS federated.t1;
+CREATE TABLE federated.t1 (
+    `id` int(20) NOT NULL auto_increment,
+    PRIMARY KEY  (`id`));
+
+connection master;
+DROP TABLE IF EXISTS federated.t1;
+eval CREATE TABLE federated.t1 (
+    `id` int(20) NOT NULL auto_increment,
+    PRIMARY KEY  (`id`)
+    )
+  ENGINE="FEDERATED" DEFAULT CHARSET=latin1
+  CONNECTION='mysql://root@stripped:$SLAVE_MYPORT/federated/t1';
+
+INSERT INTO federated.t1 VALUES ();
+SELECT LAST_INSERT_ID();
+INSERT INTO federated.t1 VALUES ();
+SELECT LAST_INSERT_ID();
+INSERT INTO federated.t1 VALUES ();
+SELECT LAST_INSERT_ID();
+INSERT INTO federated.t1 VALUES ();
+SELECT LAST_INSERT_ID();
+INSERT INTO federated.t1 VALUES ();
+SELECT LAST_INSERT_ID();
+SELECT * FROM federated.t1;
+
 source include/federated_cleanup.inc;

--- 1.58/sql/ha_federated.cc	2006-01-05 14:47:40 -08:00
+++ 1.59/sql/ha_federated.cc	2006-01-08 15:13:30 -08:00
@@ -1393,6 +1393,12 @@
     hash_delete(&federated_open_tables, (byte*) share);
     my_free((gptr) share->scheme, MYF(MY_ALLOW_ZERO_PTR));
     share->scheme= 0;
+    if (share->socket)
+    {
+      my_free((gptr) share->socket, MYF(MY_ALLOW_ZERO_PTR));
+      share->socket= 0;
+    }
+
     thr_lock_delete(&share->lock);
     VOID(pthread_mutex_destroy(&share->mutex));
     my_free((gptr) share, MYF(0));
@@ -1695,10 +1701,66 @@
   {
     DBUG_RETURN(stash_remote_error());
   }
+  /*
+    If the table we've just written a record to contains an auto_increment field,
+    then store the last_insert_id() value from the foreign server
+  */
+  if (table->next_number_field)
+    update_auto_increment();
 
   DBUG_RETURN(0);
 }
 
+/*
+  ha_federated::update_auto_increment
+
+  This method ensures that last_insert_id() works properly. What it simply does
+  is calls last_insert_id() on the foreign database immediately after insert
+  (if the table has an auto_increment field) and sets the insert id via
+  thd->insert_id(ID) (as well as storing thd->prev_insert_id)
+*/
+void ha_federated::update_auto_increment(void)
+{
+  int error_code= ER_QUERY_ON_FOREIGN_DATA_SOURCE;
+  char error_buffer[FEDERATED_QUERY_BUFFER_SIZE];
+  MYSQL_ROW row;
+  MYSQL_RES *result= 0;
+  THD *thd= current_thd;
+  DBUG_ENTER("ha_federated::update_auto_increment");
+
+  if (mysql_real_query(mysql,
+                       FEDERATED_LAST_INSERT_ID,
+                       FEDERATED_LAST_INSERT_ID_SIZE))
+    goto error;
+
+  result= mysql_store_result(mysql);
+
+  if (!result)
+    goto error;
+  if (!mysql_num_rows(result))
+    goto error;
+
+  if (!(row= mysql_fetch_row(result)))
+    goto error;
+
+  if (row[0] != NULL)
+  {
+    thd->prev_insert_id= auto_increment_value;
+    auto_increment_value= my_strtoll10(row[0], (char**) 0, &error_code);
+    thd->insert_id(auto_increment_value);
+  }
+  DBUG_PRINT("info",("auto_increment_value %d", auto_increment_value));
+  if (result)
+    mysql_free_result(result);
+
+  DBUG_VOID_RETURN;
+
+error:
+  my_sprintf(error_buffer, (error_buffer, ": %d : %s",
+                            mysql_errno(mysql), mysql_error(mysql)));
+  my_error(error_code, MYF(0), error_buffer);
+  DBUG_VOID_RETURN;
+}
 
 int ha_federated::optimize(THD* thd, HA_CHECK_OPT* check_opt)
 {

--- 1.22/sql/ha_federated.h	2005-11-17 06:05:03 -08:00
+++ 1.23/sql/ha_federated.h	2006-01-08 15:13:30 -08:00
@@ -38,6 +38,8 @@
 #define FEDERATED_QUERY_BUFFER_SIZE STRING_BUFFER_USUAL_SIZE * 5
 #define FEDERATED_RECORDS_IN_RANGE 2
 
+#define FEDERATED_LAST_INSERT_ID "SELECT LAST_INSERT_ID() "
+#define FEDERATED_LAST_INSERT_ID_SIZE sizeof(FEDERATED_LAST_INSERT_ID)
 #define FEDERATED_INFO " SHOW TABLE STATUS LIKE "
 #define FEDERATED_INFO_LEN sizeof(FEDERATED_INFO)
 #define FEDERATED_SELECT "SELECT "
@@ -285,6 +287,7 @@
   void position(const byte *record);                            //required
   void info(uint);                                              //required
 
+  void update_auto_increment(void);
   int repair(THD* thd, HA_CHECK_OPT* check_opt);
   int optimize(THD* thd, HA_CHECK_OPT* check_opt);
 
Thread
bk commit into 5.0 tree (patg:1.2021) BUG#14768Patrick Galbraith9 Jan