summaryrefslogtreecommitdiff
path: root/sql/ha_ndbcluster.cc
diff options
context:
space:
mode:
authorunknown <mskold/marty@mysql.com/quadfish.(none)>2007-11-05 20:18:22 +0100
committerunknown <mskold/marty@mysql.com/quadfish.(none)>2007-11-05 20:18:22 +0100
commitf7ee88253a7d4620de3651c3c4d7cb7a3ab3d8ac (patch)
tree2882b224abd5a071f7a2caaaf4ef74053d8decf1 /sql/ha_ndbcluster.cc
parent8890b29508dae960f75272e51862ed5fe9f355f5 (diff)
downloadmariadb-git-f7ee88253a7d4620de3651c3c4d7cb7a3ab3d8ac.tar.gz
ha_ndbcluster.h:
Bug #31956 auto increment bugs in MySQL Cluster: Added utility method and constant for internal prefetch default ndb_auto_increment.result: BitKeeper file /home/marty/MySQL/mysql-5.0-ndb/mysql-test/r/ndb_auto_increment.result mysqld.cc: Bug #25176 Trying to set ndb_autoincrement_prefetch_sz always fails: Changed pointer to max value Bug #31956 auto increment bugs in MySQL Cluster: Changed meaning of ndb_autoincrement_prefetch_sz to specify prefetch between statements, changed default to 1 (with internal prefetch to at least 32 inside a statement) ndb_insert.test, ndb_insert.result: Moved auto_increment tests to ndb_auto_increment.test ndb_auto_increment.test: BitKeeper file /home/marty/MySQL/mysql-5.0-ndb/mysql-test/t/ndb_auto_increment.test ha_ndbcluster.cc: Bug #31956 auto increment bugs in MySQL Cluster: Changed meaning of ndb_autoincrement_prefetch_sz to specify prefetch between statements, changed default to 1 (with internal prefetch to at least 32 inside a statement), added handling of updates of pk/unique key with auto_increment Bug #32055 Cluster does not handle auto inc correctly with insert ignore statement sql/mysqld.cc: Bug #25176 Trying to set ndb_autoincrement_prefetch_sz always fails: Changed pointer to max value Bug #31956 auto increment bugs in MySQL Cluster: Changed meaning of ndb_autoincrement_prefetch_sz to specify prefetch between statements, changed default to 1 (with internal prefetch to at least 32 inside a statement) sql/ha_ndbcluster.h: Bug #31956 auto increment bugs in MySQL Cluster: Added utility method and constant for internal prefetch default sql/ha_ndbcluster.cc: Bug #31956 auto increment bugs in MySQL Cluster: Changed meaning of ndb_autoincrement_prefetch_sz to specify prefetch between statements, changed default to 1 (with internal prefetch to at least 32 inside a statement), added handling of updates of pk/unique key with auto_increment Bug #32055 Cluster does not handle auto inc correctly with insert ignore statement mysql-test/r/ndb_auto_increment.result: BitKeeper file /home/marty/MySQL/mysql-5.0-ndb/mysql-test/r/ndb_auto_increment.result mysql-test/t/ndb_auto_increment.test: BitKeeper file /home/marty/MySQL/mysql-5.0-ndb/mysql-test/t/ndb_auto_increment.test mysql-test/t/ndb_insert.test: Moved auto_increment tests to ndb_auto_increment.test mysql-test/r/ndb_insert.result: Moved auto_increment tests to ndb_auto_increment.test
Diffstat (limited to 'sql/ha_ndbcluster.cc')
-rw-r--r--sql/ha_ndbcluster.cc84
1 files changed, 62 insertions, 22 deletions
diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc
index 00e4621ec1a..de6187da70f 100644
--- a/sql/ha_ndbcluster.cc
+++ b/sql/ha_ndbcluster.cc
@@ -2259,6 +2259,25 @@ int ha_ndbcluster::full_table_scan(byte *buf)
DBUG_RETURN(next_result(buf));
}
+int
+ha_ndbcluster::set_auto_inc(Field *field)
+{
+ Ndb *ndb= get_ndb();
+ Uint64 next_val= (Uint64) field->val_int() + 1;
+ DBUG_ENTER("ha_ndbcluster::set_auto_inc");
+#ifndef DBUG_OFF
+ char buff[22];
+ DBUG_PRINT("info",
+ ("Trying to set next auto increment value to %s",
+ llstr(next_val, buff)));
+#endif
+ if (ndb->setAutoIncrementValue((const NDBTAB *) m_table, next_val, TRUE)
+ == -1)
+ ERR_RETURN(ndb->getNdbError());
+ DBUG_RETURN(0);
+}
+
+
/*
Insert one record into NDB
*/
@@ -2413,17 +2432,11 @@ int ha_ndbcluster::write_row(byte *record)
}
if ((has_auto_increment) && (m_skip_auto_increment))
{
- Ndb *ndb= get_ndb();
- Uint64 next_val= (Uint64) table->next_number_field->val_int() + 1;
-#ifndef DBUG_OFF
- char buff[22];
- DBUG_PRINT("info",
- ("Trying to set next auto increment value to %s",
- llstr(next_val, buff)));
-#endif
- if (ndb->setAutoIncrementValue((const NDBTAB *) m_table, next_val, TRUE)
- == -1)
- ERR_RETURN(ndb->getNdbError());
+ int ret_val;
+ if ((ret_val= set_auto_inc(table->next_number_field)))
+ {
+ DBUG_RETURN(ret_val);
+ }
}
m_skip_auto_increment= TRUE;
@@ -2476,6 +2489,7 @@ int ha_ndbcluster::update_row(const byte *old_data, byte *new_data)
NdbScanOperation* cursor= m_active_cursor;
NdbOperation *op;
uint i;
+ int auto_res;
bool pk_update= (table->s->primary_key != MAX_KEY &&
key_cmp(table->s->primary_key, old_data, new_data));
DBUG_ENTER("update_row");
@@ -2531,6 +2545,16 @@ int ha_ndbcluster::update_row(const byte *old_data, byte *new_data)
// Insert new row
DBUG_PRINT("info", ("delete succeded"));
m_primary_key_update= TRUE;
+ /*
+ If we are updating a primary key with auto_increment
+ then we need to update the auto_increment counter
+ */
+ if (table->found_next_number_field &&
+ table->found_next_number_field->query_id == thd->query_id &&
+ (auto_res= set_auto_inc(table->found_next_number_field)))
+ {
+ DBUG_RETURN(auto_res);
+ }
insert_res= write_row(new_data);
m_primary_key_update= FALSE;
if (insert_res)
@@ -2553,7 +2577,16 @@ int ha_ndbcluster::update_row(const byte *old_data, byte *new_data)
DBUG_PRINT("info", ("delete+insert succeeded"));
DBUG_RETURN(0);
}
-
+ /*
+ If we are updating a unique key with auto_increment
+ then we need to update the auto_increment counter
+ */
+ if (table->found_next_number_field &&
+ table->found_next_number_field->query_id == thd->query_id &&
+ (auto_res= set_auto_inc(table->found_next_number_field)))
+ {
+ DBUG_RETURN(auto_res);
+ }
if (cursor)
{
/*
@@ -3841,9 +3874,11 @@ int ha_ndbcluster::external_lock(THD *thd, int lock_type)
// store thread specific data first to set the right context
m_force_send= thd->variables.ndb_force_send;
m_ha_not_exact_count= !thd->variables.ndb_use_exact_count;
- m_autoincrement_prefetch=
- (ha_rows) thd->variables.ndb_autoincrement_prefetch_sz;
-
+ m_autoincrement_prefetch=
+ (thd->variables.ndb_autoincrement_prefetch_sz >
+ NDB_DEFAULT_AUTO_PREFETCH) ?
+ (ha_rows) thd->variables.ndb_autoincrement_prefetch_sz
+ : (ha_rows) NDB_DEFAULT_AUTO_PREFETCH;
m_active_trans= thd_ndb->all ? thd_ndb->all : thd_ndb->stmt;
DBUG_ASSERT(m_active_trans);
// Start of transaction
@@ -4868,8 +4903,9 @@ ulonglong ha_ndbcluster::get_auto_increment()
{
int cache_size;
Uint64 auto_value;
- Uint64 step= current_thd->variables.auto_increment_increment;
- Uint64 start= current_thd->variables.auto_increment_offset;
+ THD *thd= current_thd;
+ Uint64 step= thd->variables.auto_increment_increment;
+ Uint64 start= thd->variables.auto_increment_offset;
DBUG_ENTER("get_auto_increment");
DBUG_PRINT("enter", ("m_tabname: %s", m_tabname));
Ndb *ndb= get_ndb();
@@ -4879,11 +4915,15 @@ ulonglong ha_ndbcluster::get_auto_increment()
/* We guessed too low */
m_rows_to_insert+= m_autoincrement_prefetch;
}
+ int remaining= m_rows_to_insert - m_rows_inserted;
+ int min_prefetch=
+ (remaining < thd->variables.ndb_autoincrement_prefetch_sz) ?
+ thd->variables.ndb_autoincrement_prefetch_sz
+ : remaining;
cache_size=
- (int) ((m_rows_to_insert - m_rows_inserted < m_autoincrement_prefetch) ?
- m_rows_to_insert - m_rows_inserted :
- ((m_rows_to_insert > m_autoincrement_prefetch) ?
- m_rows_to_insert : m_autoincrement_prefetch));
+ (int) ((remaining < m_autoincrement_prefetch) ?
+ min_prefetch
+ : remaining);
uint retries= NDB_AUTO_INCREMENT_RETRIES;
int retry_sleep= 30; /* 30 milliseconds, transaction */
for (;;)
@@ -4953,7 +4993,7 @@ ha_ndbcluster::ha_ndbcluster(TABLE *table_arg):
m_dupkey((uint) -1),
m_ha_not_exact_count(FALSE),
m_force_send(TRUE),
- m_autoincrement_prefetch((ha_rows) 32),
+ m_autoincrement_prefetch((ha_rows) NDB_DEFAULT_AUTO_PREFETCH),
m_transaction_on(TRUE),
m_cond(NULL),
m_multi_cursor(NULL)