Commit 1e4ccec8 authored by tomas@poseidon.ndb.mysql.com's avatar tomas@poseidon.ndb.mysql.com

Merge poseidon.ndb.mysql.com:/home/tomas/mysql-5.0

into  poseidon.ndb.mysql.com:/home/tomas/mysql-5.0-release
parents b3e368df 98874725
...@@ -363,6 +363,7 @@ void ha_ndbcluster::records_update() ...@@ -363,6 +363,7 @@ void ha_ndbcluster::records_update()
{ {
Ndb *ndb= get_ndb(); Ndb *ndb= get_ndb();
struct Ndb_statistics stat; struct Ndb_statistics stat;
ndb->setDatabaseName(m_dbname);
if (ndb_get_table_statistics(ndb, m_tabname, &stat) == 0){ if (ndb_get_table_statistics(ndb, m_tabname, &stat) == 0){
mean_rec_length= stat.row_size; mean_rec_length= stat.row_size;
data_file_length= stat.fragment_memory; data_file_length= stat.fragment_memory;
...@@ -3081,6 +3082,7 @@ void ha_ndbcluster::info(uint flag) ...@@ -3081,6 +3082,7 @@ void ha_ndbcluster::info(uint flag)
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
Ndb *ndb= get_ndb(); Ndb *ndb= get_ndb();
struct Ndb_statistics stat; struct Ndb_statistics stat;
ndb->setDatabaseName(m_dbname);
if (current_thd->variables.ndb_use_exact_count && if (current_thd->variables.ndb_use_exact_count &&
ndb_get_table_statistics(ndb, m_tabname, &stat) == 0) ndb_get_table_statistics(ndb, m_tabname, &stat) == 0)
{ {
...@@ -4578,7 +4580,8 @@ ha_ndbcluster::ha_ndbcluster(TABLE *table_arg): ...@@ -4578,7 +4580,8 @@ ha_ndbcluster::ha_ndbcluster(TABLE *table_arg):
HA_NO_PREFIX_CHAR_KEYS | HA_NO_PREFIX_CHAR_KEYS |
HA_NEED_READ_RANGE_BUFFER | HA_NEED_READ_RANGE_BUFFER |
HA_CAN_GEOMETRY | HA_CAN_GEOMETRY |
HA_CAN_BIT_FIELD), HA_CAN_BIT_FIELD |
HA_PARTIAL_COLUMN_READ),
m_share(0), m_share(0),
m_use_write(FALSE), m_use_write(FALSE),
m_ignore_dup_key(FALSE), m_ignore_dup_key(FALSE),
...@@ -5842,62 +5845,60 @@ ndb_get_table_statistics(Ndb* ndb, const char * table, ...@@ -5842,62 +5845,60 @@ ndb_get_table_statistics(Ndb* ndb, const char * table,
DBUG_ENTER("ndb_get_table_statistics"); DBUG_ENTER("ndb_get_table_statistics");
DBUG_PRINT("enter", ("table: %s", table)); DBUG_PRINT("enter", ("table: %s", table));
NdbTransaction* pTrans; NdbTransaction* pTrans;
NdbError error;
int retries= 10; int retries= 10;
int retry_sleep= 30 * 1000; /* 30 milliseconds */ int retry_sleep= 30 * 1000; /* 30 milliseconds */
do do
{ {
pTrans= ndb->startTransaction(); Uint64 rows, commits, mem;
if (pTrans == NULL) Uint32 size;
{ Uint32 count= 0;
if (ndb->getNdbError().status == NdbError::TemporaryError && Uint64 sum_rows= 0;
retries--) Uint64 sum_commits= 0;
Uint64 sum_row_size= 0;
Uint64 sum_mem= 0;
NdbScanOperation*pOp;
NdbResultSet *rs;
int check;
if ((pTrans= ndb->startTransaction()) == NULL)
{ {
my_sleep(retry_sleep); error= ndb->getNdbError();
continue; goto retry;
}
break;
} }
NdbScanOperation* pOp= pTrans->getNdbScanOperation(table); if ((pOp= pTrans->getNdbScanOperation(table)) == NULL)
if (pOp == NULL) {
break; error= pTrans->getNdbError();
goto retry;
}
if (pOp->readTuples(NdbOperation::LM_CommittedRead)) if (pOp->readTuples(NdbOperation::LM_CommittedRead))
break; {
error= pOp->getNdbError();
goto retry;
}
int check= pOp->interpret_exit_last_row(); if (pOp->interpret_exit_last_row() == -1)
if (check == -1) {
break; error= pOp->getNdbError();
goto retry;
}
Uint64 rows, commits, mem;
Uint32 size;
pOp->getValue(NdbDictionary::Column::ROW_COUNT, (char*)&rows); pOp->getValue(NdbDictionary::Column::ROW_COUNT, (char*)&rows);
pOp->getValue(NdbDictionary::Column::COMMIT_COUNT, (char*)&commits); pOp->getValue(NdbDictionary::Column::COMMIT_COUNT, (char*)&commits);
pOp->getValue(NdbDictionary::Column::ROW_SIZE, (char*)&size); pOp->getValue(NdbDictionary::Column::ROW_SIZE, (char*)&size);
pOp->getValue(NdbDictionary::Column::FRAGMENT_MEMORY, (char*)&mem); pOp->getValue(NdbDictionary::Column::FRAGMENT_MEMORY, (char*)&mem);
check= pTrans->execute(NdbTransaction::NoCommit, if (pTrans->execute(NdbTransaction::NoCommit,
NdbTransaction::AbortOnError, NdbTransaction::AbortOnError,
TRUE); TRUE) == -1)
if (check == -1)
{ {
if (pTrans->getNdbError().status == NdbError::TemporaryError && error= pTrans->getNdbError();
retries--) goto retry;
{
ndb->closeTransaction(pTrans);
pTrans= 0;
my_sleep(retry_sleep);
continue;
}
break;
} }
Uint32 count= 0;
Uint64 sum_rows= 0;
Uint64 sum_commits= 0;
Uint64 sum_row_size= 0;
Uint64 sum_mem= 0;
while ((check= pOp->nextResult(TRUE, TRUE)) == 0) while ((check= pOp->nextResult(TRUE, TRUE)) == 0)
{ {
sum_rows+= rows; sum_rows+= rows;
...@@ -5909,7 +5910,10 @@ ndb_get_table_statistics(Ndb* ndb, const char * table, ...@@ -5909,7 +5910,10 @@ ndb_get_table_statistics(Ndb* ndb, const char * table,
} }
if (check == -1) if (check == -1)
break; {
error= pOp->getNdbError();
goto retry;
}
pOp->close(TRUE); pOp->close(TRUE);
...@@ -5926,12 +5930,21 @@ ndb_get_table_statistics(Ndb* ndb, const char * table, ...@@ -5926,12 +5930,21 @@ ndb_get_table_statistics(Ndb* ndb, const char * table,
sum_mem, count)); sum_mem, count));
DBUG_RETURN(0); DBUG_RETURN(0);
} while(1); retry:
if (pTrans) if (pTrans)
{
ndb->closeTransaction(pTrans); ndb->closeTransaction(pTrans);
DBUG_PRINT("exit", ("failed")); pTrans= NULL;
DBUG_RETURN(-1); }
if (error.status == NdbError::TemporaryError && retries--)
{
my_sleep(retry_sleep);
continue;
}
break;
} while(1);
DBUG_PRINT("exit", ("failed, error %u(%s)", error.code, error.message));
ERR_RETURN(error);
} }
/* /*
......
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
see mi_rsame/heap_rsame/myrg_rsame see mi_rsame/heap_rsame/myrg_rsame
*/ */
#define HA_READ_RND_SAME (1 << 0) #define HA_READ_RND_SAME (1 << 0)
#define HA_PARTIAL_COLUMN_READ (1 << 1) /* read may not return all columns */
#define HA_TABLE_SCAN_ON_INDEX (1 << 2) /* No separate data/index file */ #define HA_TABLE_SCAN_ON_INDEX (1 << 2) /* No separate data/index file */
#define HA_REC_NOT_IN_SEQ (1 << 3) /* ha_info don't return recnumber; #define HA_REC_NOT_IN_SEQ (1 << 3) /* ha_info don't return recnumber;
It returns a position to ha_r_rnd */ It returns a position to ha_r_rnd */
......
...@@ -120,6 +120,7 @@ int mysql_update(THD *thd, ...@@ -120,6 +120,7 @@ int mysql_update(THD *thd,
bool using_limit= limit != HA_POS_ERROR; bool using_limit= limit != HA_POS_ERROR;
bool safe_update= thd->options & OPTION_SAFE_UPDATES; bool safe_update= thd->options & OPTION_SAFE_UPDATES;
bool used_key_is_modified, transactional_table; bool used_key_is_modified, transactional_table;
bool can_compare_record;
int res; int res;
int error; int error;
uint used_index= MAX_KEY; uint used_index= MAX_KEY;
...@@ -433,6 +434,13 @@ int mysql_update(THD *thd, ...@@ -433,6 +434,13 @@ int mysql_update(THD *thd,
(MODE_STRICT_TRANS_TABLES | (MODE_STRICT_TRANS_TABLES |
MODE_STRICT_ALL_TABLES))); MODE_STRICT_ALL_TABLES)));
/*
We can use compare_record() to optimize away updates if
the table handler is returning all columns
*/
can_compare_record= !(table->file->table_flags() &
HA_PARTIAL_COLUMN_READ);
while (!(error=info.read_record(&info)) && !thd->killed) while (!(error=info.read_record(&info)) && !thd->killed)
{ {
if (!(select && select->skip_record())) if (!(select && select->skip_record()))
...@@ -445,7 +453,7 @@ int mysql_update(THD *thd, ...@@ -445,7 +453,7 @@ int mysql_update(THD *thd,
found++; found++;
if (compare_record(table, query_id)) if (!can_compare_record || compare_record(table, query_id))
{ {
if ((res= table_list->view_check_option(thd, ignore)) != if ((res= table_list->view_check_option(thd, ignore)) !=
VIEW_CHECK_OK) VIEW_CHECK_OK)
...@@ -1248,8 +1256,15 @@ bool multi_update::send_data(List<Item> &not_used_values) ...@@ -1248,8 +1256,15 @@ bool multi_update::send_data(List<Item> &not_used_values)
uint offset= cur_table->shared; uint offset= cur_table->shared;
table->file->position(table->record[0]); table->file->position(table->record[0]);
/*
We can use compare_record() to optimize away updates if
the table handler is returning all columns
*/
if (table == table_to_update) if (table == table_to_update)
{ {
bool can_compare_record;
can_compare_record= !(table->file->table_flags() &
HA_PARTIAL_COLUMN_READ);
table->status|= STATUS_UPDATED; table->status|= STATUS_UPDATED;
store_record(table,record[1]); store_record(table,record[1]);
if (fill_record_n_invoke_before_triggers(thd, *fields_for_table[offset], if (fill_record_n_invoke_before_triggers(thd, *fields_for_table[offset],
...@@ -1259,7 +1274,7 @@ bool multi_update::send_data(List<Item> &not_used_values) ...@@ -1259,7 +1274,7 @@ bool multi_update::send_data(List<Item> &not_used_values)
DBUG_RETURN(1); DBUG_RETURN(1);
found++; found++;
if (compare_record(table, thd->query_id)) if (!can_compare_record || compare_record(table, thd->query_id))
{ {
int error; int error;
if ((error= cur_table->view_check_option(thd, ignore)) != if ((error= cur_table->view_check_option(thd, ignore)) !=
...@@ -1376,6 +1391,7 @@ int multi_update::do_updates(bool from_send_error) ...@@ -1376,6 +1391,7 @@ int multi_update::do_updates(bool from_send_error)
for (cur_table= update_tables; cur_table; cur_table= cur_table->next_local) for (cur_table= update_tables; cur_table; cur_table= cur_table->next_local)
{ {
byte *ref_pos; byte *ref_pos;
bool can_compare_record;
table = cur_table->table; table = cur_table->table;
if (table == table_to_update) if (table == table_to_update)
...@@ -1402,6 +1418,9 @@ int multi_update::do_updates(bool from_send_error) ...@@ -1402,6 +1418,9 @@ int multi_update::do_updates(bool from_send_error)
if ((local_error = tmp_table->file->ha_rnd_init(1))) if ((local_error = tmp_table->file->ha_rnd_init(1)))
goto err; goto err;
can_compare_record= !(table->file->table_flags() &
HA_PARTIAL_COLUMN_READ);
ref_pos= (byte*) tmp_table->field[0]->ptr; ref_pos= (byte*) tmp_table->field[0]->ptr;
for (;;) for (;;)
{ {
...@@ -1431,7 +1450,7 @@ int multi_update::do_updates(bool from_send_error) ...@@ -1431,7 +1450,7 @@ int multi_update::do_updates(bool from_send_error)
TRG_ACTION_BEFORE, TRUE)) TRG_ACTION_BEFORE, TRUE))
goto err2; goto err2;
if (compare_record(table, thd->query_id)) if (!can_compare_record || compare_record(table, thd->query_id))
{ {
if ((local_error=table->file->update_row(table->record[1], if ((local_error=table->file->update_row(table->record[1],
table->record[0]))) table->record[0])))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment