#At file:///home/msvensson/mysql/7.0-seagull-wl2679/ based on revid:magnus.blaudd@strippedje1f7qw
3745 Magnus Blåudd 2010-10-01
ndb
- Revert addition of the handler::bulk_delete_row function which
was added as part of WL#2679 and instead set a ha_ndbcluster
flag in start_bulk_delete() which will indicate to
ha_ndbcluster::delete_row() that bulk delete is active.
Reset the flag and flush any outstanding deletes
in ha_ndbcluster::end_bulk_delete()
- Extend the ndb_bulk_delete test case with a table with more rows
and more IN values which triggers ha_nddbcluster to
flush the deletes because it runs out of batch memory space.
modified:
mysql-test/suite/ndb/r/ndb_bulk_delete.result
mysql-test/suite/ndb/t/ndb_bulk_delete.test
sql/ha_ndbcluster.cc
sql/ha_ndbcluster.h
sql/handler.cc
sql/handler.h
sql/sql_delete.cc
=== modified file 'mysql-test/suite/ndb/r/ndb_bulk_delete.result'
--- a/mysql-test/suite/ndb/r/ndb_bulk_delete.result 2008-09-24 14:44:11 +0000
+++ b/mysql-test/suite/ndb/r/ndb_bulk_delete.result 2010-10-01 13:20:38 +0000
@@ -1,4 +1,3 @@
-DROP TABLE IF EXISTS t1;
create table t1 (a int key) engine ndb;
insert into t1 values (1);
insert into t1 select a+1 from t1;
@@ -9,6 +8,9 @@ insert into t1 select a+16 from t1;
insert into t1 select a+32 from t1;
insert into t1 select a+64 from t1;
insert into t1 select a+128 from t1;
+select count(*) from t1;
+count(*)
+256
# test: simple delete of multiple pk's
# expected result 1 roundtrips
@@ -46,5 +48,26 @@ affected rows: 0
@ndb_execute_count:=VARIABLE_VALUE-@ndb_init_execute_count
1
affected rows: 1
+select count(*) as "0(was deleted)" from t1 where a in (1,7, 90, 100, 130);
+0(was deleted)
+0
+select count(*) as "0(never existed)" from t1 where a=1000;
+0(never existed)
+0
+select count(*) as "0(never existed)" from t1
+where a in (1000, 1001, 1002, 1003, 1004);
+0(never existed)
+0
+select count(*) as "251(remaining)" from t1;
+251(remaining)
+251
+select count(*) as "5(not deleted)" from t1 where a in (2, 3, 4, 5, 6);
+5(not deleted)
+5
drop table t1;
-affected rows: 0
+create table t2 (a int primary key, b varchar(256)) engine ndb;
+Has loaded 2000 rows
+2000
+Should be 1500 rows left now
+1500
+drop table t2, t3;
=== modified file 'mysql-test/suite/ndb/t/ndb_bulk_delete.test'
--- a/mysql-test/suite/ndb/t/ndb_bulk_delete.test 2008-09-24 14:44:11 +0000
+++ b/mysql-test/suite/ndb/t/ndb_bulk_delete.test 2010-10-01 13:20:38 +0000
@@ -1,13 +1,9 @@
#
-# Basic test of bulk update interface. Test counts number of execute
-# as measurement of numbre of round trips to kernel.
+# Basic test of bulk delete interface. Test counts number of execute
+# as measurement of number of round trips to kernel.
#
-- source include/have_ndb.inc
---disable_warnings
-DROP TABLE IF EXISTS t1;
---enable_warnings
-
create table t1 (a int key) engine ndb;
insert into t1 values (1);
insert into t1 select a+1 from t1;
@@ -18,6 +14,7 @@ insert into t1 select a+16 from t1;
insert into t1 select a+32 from t1;
insert into t1 select a+64 from t1;
insert into t1 select a+128 from t1;
+select count(*) from t1; # 256 rows
--enable_info
@@ -57,6 +54,83 @@ delete from t1 where a=1000;
delete from t1 where a in (1000, 1001, 1002, 1003, 1004);
--source include/ndb_execute_count.inc
+--disable_info
+
+# Check that the expected rows remains
+select count(*) as "0(was deleted)" from t1 where a in (1,7, 90, 100, 130);
+select count(*) as "0(never existed)" from t1 where a=1000;
+select count(*) as "0(never existed)" from t1
+ where a in (1000, 1001, 1002, 1003, 1004);
+select count(*) as "251(remaining)" from t1;
+select count(*) as "5(not deleted)" from t1 where a in (2, 3, 4, 5, 6);
# cleanup
drop table t1;
+
+
+# Build table t2 with 2000 rows
+create table t2 (a int primary key, b varchar(256)) engine ndb;
+--disable_result_log
+--disable_query_log
+let $i = 200;
+while($i)
+{
+ eval insert into t2 values
+ ($i*10,"building a table"),
+ ($i*10+1, "one row"), ($i*10+2, "another row"),
+ ($i*10+3, "the third row"), ($i*10+4, ""),
+ ($i*10+5, "fifth"), ($i*10+6, "a longer string at line six"),
+ ($i*10+7, "in the sevent it will get even longer"),
+ ($i*10+8, "another row 8"), ($i*10+9, "another row 9");
+ dec $i;
+}
+--enable_result_log
+select count(*) as "Has loaded 2000 rows" from t2;
+--enable_query_log
+
+# Build table t3 and delete from it with increasing
+# number of values in the IN clause, don't do too many
+# as mysqld will switch to full table scan
+--disable_query_log
+--disable_result_log
+create table t3 like t2;
+let $i = 50;
+let $in = $i;
+while($i)
+{
+ # Repopulate t3 with all rows
+ replace into t3 select * from t2;
+
+ # Extend the IN clause with another 10 values
+ let $in =$in,$i*10,$i*10+1,$i*10+2,$i*10+3,$i*10+4,$i*10+5,
+ $i*10+6,$i*10+7,$i*10+8,$i*10+9;
+
+ # Get the execute count before DELETE
+ let $before= `select VARIABLE_VALUE from information_schema.session_status
+ where variable_name like 'NDB_EXECUTE_COUNT'`;
+
+ # Run the query
+ eval delete from t3 where a in ($in);
+
+ # Check that execute count after DELETE is not greater than 3
+ let $after= `select VARIABLE_VALUE from information_schema.session_status
+ where variable_name like 'NDB_EXECUTE_COUNT'`;
+ if (!`select $after-$before <= 3`)
+ {
+ echo before: $before;
+ echo after: $after;
+ enable_result_log;
+ show session status like 'ndb%';
+ die Got unexpected ndb_execute_count value;
+ }
+
+ dec $i;
+}
+--enable_result_log
+select count(*) as "Should be 1500 rows left now" from t3;
+--enable_query_log
+
+# Cleanup
+drop table t2, t3;
+
+
=== modified file 'sql/ha_ndbcluster.cc'
--- a/sql/ha_ndbcluster.cc 2010-09-02 06:50:05 +0000
+++ b/sql/ha_ndbcluster.cc 2010-10-01 13:20:38 +0000
@@ -4671,18 +4671,14 @@ int ha_ndbcluster::delete_row(const ucha
bool ha_ndbcluster::start_bulk_delete()
{
DBUG_ENTER("start_bulk_delete");
- DBUG_RETURN(FALSE);
-}
-
-int ha_ndbcluster::bulk_delete_row(const uchar *record)
-{
- DBUG_ENTER("bulk_delete_row");
- DBUG_RETURN(ndb_delete_row(record, FALSE, TRUE));
+ m_is_bulk_delete = true;
+ DBUG_RETURN(0); // Bulk delete used by handler
}
int ha_ndbcluster::end_bulk_delete()
{
DBUG_ENTER("end_bulk_delete");
+ assert(m_is_bulk_delete); // Don't allow end() without start()
if (m_thd_ndb->m_unsent_bytes &&
!(table->in_use->options & OPTION_ALLOW_BATCH) &&
!m_thd_ndb->m_handler)
@@ -4697,6 +4693,7 @@ int ha_ndbcluster::end_bulk_delete()
}
m_rows_deleted-= ignore_count;
}
+ m_is_bulk_delete = false;
DBUG_RETURN(0);
}
@@ -4706,8 +4703,7 @@ int ha_ndbcluster::end_bulk_delete()
*/
int ha_ndbcluster::ndb_delete_row(const uchar *record,
- bool primary_key_update,
- bool is_bulk_delete)
+ bool primary_key_update)
{
THD *thd= table->in_use;
Thd_ndb *thd_ndb= get_thd_ndb(thd);
@@ -4716,7 +4712,7 @@ int ha_ndbcluster::ndb_delete_row(const
const NdbOperation *op;
uint32 part_id= ~uint32(0);
int error;
- bool allow_batch= is_bulk_delete || (thd->options & OPTION_ALLOW_BATCH);
+ bool allow_batch= m_is_bulk_delete || (thd->options & OPTION_ALLOW_BATCH);
DBUG_ENTER("ndb_delete_row");
DBUG_ASSERT(trans);
@@ -5857,6 +5853,9 @@ int ha_ndbcluster::reset()
m_delete_cannot_batch= FALSE;
m_update_cannot_batch= FALSE;
+ assert(m_is_bulk_delete == false);
+ m_is_bulk_delete = false;
+
DBUG_RETURN(0);
}
@@ -8693,6 +8692,7 @@ ha_ndbcluster::ha_ndbcluster(handlerton
m_update_cannot_batch(FALSE),
m_skip_auto_increment(TRUE),
m_blobs_pending(0),
+ m_is_bulk_delete(false),
m_blobs_row_total_size(0),
m_blobs_buffer(0),
m_blobs_buffer_size(0),
=== modified file 'sql/ha_ndbcluster.h'
--- a/sql/ha_ndbcluster.h 2010-06-03 14:12:46 +0000
+++ b/sql/ha_ndbcluster.h 2010-10-01 13:20:38 +0000
@@ -653,10 +653,8 @@ private:
bool batched_update);
bool start_bulk_delete();
- int bulk_delete_row(const uchar *record);
int end_bulk_delete();
- int ndb_delete_row(const uchar *record, bool primary_key_update,
- bool is_bulk_delete= FALSE);
+ int ndb_delete_row(const uchar *record, bool primary_key_update);
int ndb_optimize_table(THD* thd, uint delay);
@@ -841,6 +839,7 @@ private:
bool m_skip_auto_increment;
bool m_blobs_pending;
bool m_slow_path;
+ bool m_is_bulk_delete;
/* State for setActiveHook() callback for reading blob data. */
uint m_blob_counter;
=== modified file 'sql/handler.cc'
--- a/sql/handler.cc 2010-08-20 14:07:55 +0000
+++ b/sql/handler.cc 2010-10-01 13:20:38 +0000
@@ -4952,19 +4952,14 @@ int handler::ha_update_row(const uchar *
return 0;
}
-int handler::ha_delete_row(const uchar *buf, bool will_batch)
+int handler::ha_delete_row(const uchar *buf)
{
int error;
Log_func *log_func= Delete_rows_log_event::binlog_row_logging_function;
mark_trx_read_write();
- if (will_batch)
- {
- if (unlikely((error= bulk_delete_row(buf)) != 0))
- return error;
- }
- else if (unlikely((error= delete_row(buf)) != 0))
+ if (unlikely((error= delete_row(buf)) != 0))
return error;
if (unlikely((error= binlog_log_row(table, buf, 0, log_func)) != 0))
return error;
=== modified file 'sql/handler.h'
--- a/sql/handler.h 2010-09-02 06:50:05 +0000
+++ b/sql/handler.h 2010-10-01 13:20:38 +0000
@@ -1302,7 +1302,7 @@ public:
int ha_external_lock(THD *thd, int lock_type);
int ha_write_row(uchar * buf);
int ha_update_row(const uchar * old_data, uchar * new_data);
- int ha_delete_row(const uchar * buf, bool will_batch= FALSE);
+ int ha_delete_row(const uchar * buf);
void ha_release_auto_increment();
int check_collation_compatibility();
@@ -2068,22 +2068,6 @@ private:
DBUG_ASSERT(FALSE);
return HA_ERR_WRONG_COMMAND;
}
- /*
- This method is similar to delete_row, however the handler doesn't need
- to execute the delete at this point in time. The handler can be certain
- that another call to bulk_delete_row will occur OR a call to
- end_bulk_delete before the set of deletes in this query is concluded.
-
- @param record Record to delete
-
- @retval 0 Success
- @retval !=0 Error code
- */
- virtual int bulk_delete_row(const uchar *record)
- {
- DBUG_ASSERT(FALSE);
- return HA_ERR_WRONG_COMMAND;
- }
/**
This is called to delete all rows in a table
If the handler don't support this, then this function will
=== modified file 'sql/sql_delete.cc'
--- a/sql/sql_delete.cc 2010-06-16 12:04:53 +0000
+++ b/sql/sql_delete.cc 2010-10-01 13:20:38 +0000
@@ -336,7 +336,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *
break;
}
- if (!(error= table->file->ha_delete_row(table->record[0], will_batch)))
+ if (!(error= table->file->ha_delete_row(table->record[0])))
{
deleted++;
if (triggers_applicable &&
Attachment: [text/bzr-bundle] bzr/magnus.blaudd@sun.com-20101001132038-zx3dimdqaien53yu.bundle
| Thread |
|---|
| • bzr commit into mysql-5.1-telco-7.0 branch (magnus.blaudd:3745) WL#2679 | Magnus Blåudd | 1 Oct |