Commit d7d3b4cd authored by unknown's avatar unknown
Browse files

Merge osalerma@bk-internal.mysql.com:/home/bk/mysql-5.0

into  127.(none):/home/osku/mysql-5.0


sql/ha_innodb.cc:
  Auto merged
sql/sql_delete.cc:
  Auto merged
parents 11d32b4a 9363d02f
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -2488,3 +2488,26 @@ delete t1 from t1,t2 where f1=f3 and f4='cc';
select * from t1;
f1	f2
drop table t1,t2;
CREATE TABLE t1 (
id INTEGER NOT NULL AUTO_INCREMENT, PRIMARY KEY (id)
) ENGINE=InnoDB;
CREATE TABLE t2 (
id INTEGER NOT NULL,
FOREIGN KEY (id) REFERENCES t1 (id)
) ENGINE=InnoDB;
INSERT INTO t1 (id) VALUES (NULL);
SELECT * FROM t1;
id
1
TRUNCATE t1;
INSERT INTO t1 (id) VALUES (NULL);
SELECT * FROM t1;
id
1
DELETE FROM t1;
TRUNCATE t1;
INSERT INTO t1 (id) VALUES (NULL);
SELECT * FROM t1;
id
1
DROP TABLE t2, t1;
+28 −0
Original line number Diff line number Diff line
@@ -1405,3 +1405,31 @@ insert into t1 values ('aa','bb'),('aa','cc');
delete t1 from t1,t2 where f1=f3 and f4='cc';
select * from t1;
drop table t1,t2;

#
# Test that the slow TRUNCATE implementation resets autoincrement columns
# (bug #11946)
#

CREATE TABLE t1 (
id INTEGER NOT NULL AUTO_INCREMENT, PRIMARY KEY (id)
) ENGINE=InnoDB;

CREATE TABLE t2 (
id INTEGER NOT NULL,
FOREIGN KEY (id) REFERENCES t1 (id)
) ENGINE=InnoDB;

INSERT INTO t1 (id) VALUES (NULL);
SELECT * FROM t1;
TRUNCATE t1;
INSERT INTO t1 (id) VALUES (NULL);
SELECT * FROM t1;

# continued from above; test that doing a slow TRUNCATE on a table with 0
# rows resets autoincrement columns
DELETE FROM t1;
TRUNCATE t1;
INSERT INTO t1 (id) VALUES (NULL);
SELECT * FROM t1;
DROP TABLE t2, t1;
+22 −0
Original line number Diff line number Diff line
@@ -6888,6 +6888,28 @@ ha_innobase::get_auto_increment()
	return((ulonglong) nr);
}

/* See comment in handler.h */
int
ha_innobase::reset_auto_increment()
{
	DBUG_ENTER("ha_innobase::reset_auto_increment");

	row_prebuilt_t* prebuilt = (row_prebuilt_t*) innobase_prebuilt;
  	int     	error;

	error = row_lock_table_autoinc_for_mysql(prebuilt);

	if (error != DB_SUCCESS) {
		error = convert_error_code_to_mysql(error, user_thd);

		DBUG_RETURN(error);
	}	

	dict_table_autoinc_initialize(prebuilt->table, 0);

	DBUG_RETURN(0);
}

/***********************************************************************
Compares two 'refs'. A 'ref' is the (internal) primary key value of the row.
If there is no explicitly declared non-null unique key or a primary key, then
+2 −0
Original line number Diff line number Diff line
@@ -173,6 +173,8 @@ class ha_innobase: public handler
			     		enum thr_lock_type lock_type);
	void init_table_handle_for_HANDLER(); 
	ulonglong get_auto_increment();
	int reset_auto_increment();
	
        uint8 table_cache_type() { return HA_CACHE_TBL_ASKTRANSACT; }
        /*
          ask handler about permission to cache table during query registration
+9 −0
Original line number Diff line number Diff line
@@ -650,6 +650,15 @@ class handler :public Sql_alloc
  { return (my_errno=HA_ERR_WRONG_COMMAND); }
  virtual ulonglong get_auto_increment();
  virtual void restore_auto_increment();

  /* This is called after TRUNCATE is emulated by doing a 'DELETE FROM t',
     in which case we need a separate operation for resetting the table's
     auto-increment counter. HA_ERR_WRONG_COMMAND is returned by storage
     engines that have no need for this, i.e. those that can always do a
     fast TRUNCATE. */
  virtual int reset_auto_increment()
  { return HA_ERR_WRONG_COMMAND; }

  virtual void update_create_info(HA_CREATE_INFO *create_info) {}

  /* admin commands - called from mysql_admin_table */
Loading