From 736faf473011dffd0fc0905c1d5e7859fa04c5aa Mon Sep 17 00:00:00 2001 From: "andrey@lmy004." <> Date: Wed, 1 Feb 2006 20:35:16 +0100 Subject: [PATCH 1/4] fix for bug #12744 (MYSQL_STMT operations cause seg fault after connection reset) --- libmysql/libmysql.c | 6 ++++++ tests/mysql_client_test.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 921f042922a..498881aa947 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -4628,6 +4628,12 @@ my_bool STDCALL mysql_stmt_reset(MYSQL_STMT *stmt) /* If statement hasnt been prepared there is nothing to reset */ if ((int) stmt->state < (int) MYSQL_STMT_PREPARE_DONE) DBUG_RETURN(0); + if (!stmt->mysql) + { + /* mysql can be reset in mysql_close called from mysql_reconnect */ + set_stmt_error(stmt, CR_SERVER_LOST, unknown_sqlstate); + DBUG_RETURN(1); + } mysql= stmt->mysql->last_used_con; int4store(buff, stmt->stmt_id); /* Send stmt id to server */ diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index 91c2ab9205d..dbc2f582466 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -11706,6 +11706,37 @@ static void test_bug12001() DIE_UNLESS(res==1); } +static void test_bug12744() +{ + MYSQL_STMT *prep_stmt = NULL; + int rc; + myheader("test_bug12744"); + + prep_stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(prep_stmt, "SELECT 1", 8); + DIE_UNLESS(rc==0); + + rc= mysql_kill(mysql, mysql_thread_id(mysql)); + DIE_UNLESS(rc==0); + + if (rc= mysql_stmt_execute(prep_stmt)) + { + if (rc= mysql_stmt_reset(prep_stmt)) + printf("OK!\n"); + else + { + printf("Error!"); + DIE_UNLESS(1==0); + } + } + else + { + fprintf(stderr, "expected error but no error occured\n"); + DIE_UNLESS(1==0); + } + rc= mysql_stmt_close(prep_stmt); +} + /* Bug#11718: query with function, join and order by returns wrong type */ @@ -12054,6 +12085,7 @@ static struct my_tests_st my_tests[]= { { "test_bug8378", test_bug8378 }, { "test_bug9735", test_bug9735 }, { "test_bug11183", test_bug11183 }, + { "test_bug12744", test_bug12744 }, { "test_bug12001", test_bug12001 }, { "test_bug11718", test_bug11718 }, { "test_bug12925", test_bug12925 }, From c696582df47c942f038a562b4966d2a0642dcecc Mon Sep 17 00:00:00 2001 From: "pekka@mysql.com" <> Date: Fri, 3 Feb 2006 15:23:58 +0100 Subject: [PATCH 2/4] ndb - replace+tinyblob back-patch from 5.0 [ discard on 4.1->5.0 merge ] --- mysql-test/r/ndb_blob.result | 7 +++++++ mysql-test/t/ndb_blob.test | 6 +++++- ndb/src/ndbapi/NdbBlob.cpp | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/ndb_blob.result b/mysql-test/r/ndb_blob.result index 6f25ec95c80..bcf867a4edd 100644 --- a/mysql-test/r/ndb_blob.result +++ b/mysql-test/r/ndb_blob.result @@ -428,6 +428,13 @@ delete from t1; select * from t1; a b commit; +replace t1 set a=2, b='y'; +select * from t1; +a b +2 y +delete from t1; +select * from t1; +a b drop table t1; set autocommit=0; create table t1 ( diff --git a/mysql-test/t/ndb_blob.test b/mysql-test/t/ndb_blob.test index a12ebee2f0d..f80b7f71281 100644 --- a/mysql-test/t/ndb_blob.test +++ b/mysql-test/t/ndb_blob.test @@ -338,7 +338,7 @@ select * from t1 order by a; drop table t1; drop database test2; -# -- bug-5252 tinytext crashes plus no-commit result -- +# -- bug-5252 tinytext crashes + no-commit result + replace -- set autocommit=0; create table t1 ( @@ -352,6 +352,10 @@ select * from t1; delete from t1; select * from t1; commit; +replace t1 set a=2, b='y'; +select * from t1; +delete from t1; +select * from t1; drop table t1; # -- bug-5013 insert empty string to text -- diff --git a/ndb/src/ndbapi/NdbBlob.cpp b/ndb/src/ndbapi/NdbBlob.cpp index c5692d79e83..416e983ec14 100644 --- a/ndb/src/ndbapi/NdbBlob.cpp +++ b/ndb/src/ndbapi/NdbBlob.cpp @@ -959,6 +959,8 @@ int NdbBlob::deletePartsUnknown(Uint32 part) { DBG("deletePartsUnknown [in] part=" << part << " count=all"); + if (thePartSize == 0) // tinyblob + return 0; static const unsigned maxbat = 256; static const unsigned minbat = 1; unsigned bat = minbat; From 8ed86030b40298f09f77b5bdf78af905dd89c3f2 Mon Sep 17 00:00:00 2001 From: "pekka@mysql.com" <> Date: Sun, 5 Feb 2006 22:12:06 +0100 Subject: [PATCH 3/4] ndb - bug#16693 (4.1) test + workaround, analyze later --- ndb/test/ndbapi/testBlobs.cpp | 82 +++++++++++++++++++++++++++-------- ndb/tools/delete_all.cpp | 30 ++++++++++--- 2 files changed, 88 insertions(+), 24 deletions(-) diff --git a/ndb/test/ndbapi/testBlobs.cpp b/ndb/test/ndbapi/testBlobs.cpp index cd2287df876..4c82f718788 100644 --- a/ndb/test/ndbapi/testBlobs.cpp +++ b/ndb/test/ndbapi/testBlobs.cpp @@ -841,9 +841,6 @@ insertPk(int style) CHK(g_con->execute(NoCommit) == 0); CHK(writeBlobData(tup) == 0); } - // just another trap - if (urandom(10) == 0) - CHK(g_con->execute(NoCommit) == 0); if (++n == g_opt.m_batch) { CHK(g_con->execute(Commit) == 0); g_ndb->closeTransaction(g_con); @@ -965,21 +962,31 @@ static int deletePk() { DBG("--- deletePk ---"); + unsigned n = 0; + CHK((g_con = g_ndb->startTransaction()) != 0); for (unsigned k = 0; k < g_opt.m_rows; k++) { Tup& tup = g_tups[k]; DBG("deletePk pk1=" << hex << tup.m_pk1); - CHK((g_con = g_ndb->startTransaction()) != 0); CHK((g_opr = g_con->getNdbOperation(g_opt.m_tname)) != 0); CHK(g_opr->deleteTuple() == 0); CHK(g_opr->equal("PK1", tup.m_pk1) == 0); if (g_opt.m_pk2len != 0) CHK(g_opr->equal("PK2", tup.m_pk2) == 0); - CHK(g_con->execute(Commit) == 0); - g_ndb->closeTransaction(g_con); + if (++n == g_opt.m_batch) { + CHK(g_con->execute(Commit) == 0); + g_ndb->closeTransaction(g_con); + CHK((g_con = g_ndb->startTransaction()) != 0); + n = 0; + } g_opr = 0; - g_con = 0; tup.m_exists = false; } + if (n != 0) { + CHK(g_con->execute(Commit) == 0); + n = 0; + } + g_ndb->closeTransaction(g_con); + g_con = 0; return 0; } @@ -1082,19 +1089,27 @@ static int deleteIdx() { DBG("--- deleteIdx ---"); + unsigned n = 0; + CHK((g_con = g_ndb->startTransaction()) != 0); for (unsigned k = 0; k < g_opt.m_rows; k++) { Tup& tup = g_tups[k]; DBG("deleteIdx pk1=" << hex << tup.m_pk1); - CHK((g_con = g_ndb->startTransaction()) != 0); CHK((g_opx = g_con->getNdbIndexOperation(g_opt.m_x1name, g_opt.m_tname)) != 0); CHK(g_opx->deleteTuple() == 0); CHK(g_opx->equal("PK2", tup.m_pk2) == 0); - CHK(g_con->execute(Commit) == 0); - g_ndb->closeTransaction(g_con); + if (++n == g_opt.m_batch) { + CHK(g_con->execute(Commit) == 0); + g_ndb->closeTransaction(g_con); + CHK((g_con = g_ndb->startTransaction()) != 0); + n = 0; + } g_opx = 0; - g_con = 0; tup.m_exists = false; } + if (n != 0) { + CHK(g_con->execute(Commit) == 0); + n = 0; + } return 0; } @@ -1225,20 +1240,49 @@ deleteScan(bool idx) CHK(g_ops->getValue("PK2", tup.m_pk2) != 0); CHK(g_con->execute(NoCommit) == 0); unsigned rows = 0; + unsigned n = 0; while (1) { int ret; tup.m_pk1 = (Uint32)-1; memset(tup.m_pk2, 'x', g_opt.m_pk2len); - CHK((ret = rs->nextResult()) == 0 || ret == 1); + CHK((ret = rs->nextResult(true)) == 0 || ret == 1); if (ret == 1) break; - DBG("deleteScan" << (idx ? "Idx" : "") << " pk1=" << hex << tup.m_pk1); - CHK(rs->deleteTuple() == 0); - CHK(g_con->execute(NoCommit) == 0); - Uint32 k = tup.m_pk1 - g_opt.m_pk1off; - CHK(k < g_opt.m_rows && g_tups[k].m_exists); - g_tups[k].m_exists = false; - rows++; + while (1) { + DBG("deleteScan" << (idx ? "Idx" : "") << " pk1=" << hex << tup.m_pk1); + Uint32 k = tup.m_pk1 - g_opt.m_pk1off; + CHK(k < g_opt.m_rows && g_tups[k].m_exists); + g_tups[k].m_exists = false; + CHK(rs->deleteTuple() == 0); + rows++; + tup.m_pk1 = (Uint32)-1; + memset(tup.m_pk2, 'x', g_opt.m_pk2len); + CHK((ret = rs->nextResult(false)) == 0 || ret == 1 || ret == 2); + if (++n == g_opt.m_batch || ret == 2) { + DBG("execute batch: n=" << n << " ret=" << ret); + switch (0) { + case 0: // works normally + CHK(g_con->execute(NoCommit) == 0); + CHK(true || g_con->restart() == 0); + break; + case 1: // nonsense - g_con is invalid for 2nd batch + CHK(g_con->execute(Commit) == 0); + CHK(true || g_con->restart() == 0); + break; + case 2: // DBTC sendSignalErrorRefuseLab + CHK(g_con->execute(NoCommit) == 0); + CHK(g_con->restart() == 0); + break; + case 3: // 266 time-out + CHK(g_con->execute(Commit) == 0); + CHK(g_con->restart() == 0); + break; + } + n = 0; + } + if (ret == 2) + break; + } } CHK(g_con->execute(Commit) == 0); g_ndb->closeTransaction(g_con); diff --git a/ndb/tools/delete_all.cpp b/ndb/tools/delete_all.cpp index 21e0c2ac089..d4a07fdf505 100644 --- a/ndb/tools/delete_all.cpp +++ b/ndb/tools/delete_all.cpp @@ -22,7 +22,8 @@ #include #include -static int clear_table(Ndb* pNdb, const NdbDictionary::Table* pTab, int parallelism=240); +static int clear_table(Ndb* pNdb, const NdbDictionary::Table* pTab, + bool commit_across_open_cursor, int parallelism=240); NDB_STD_OPTS_VARS; @@ -81,8 +82,18 @@ int main(int argc, char** argv){ ndbout << " Table " << argv[i] << " does not exist!" << endl; return NDBT_ProgramExit(NDBT_WRONGARGS); } + // Check if we have any blobs + bool commit_across_open_cursor = true; + for (int j = 0; j < pTab->getNoOfColumns(); j++) { + NdbDictionary::Column::Type t = pTab->getColumn(j)->getType(); + if (t == NdbDictionary::Column::Blob || + t == NdbDictionary::Column::Text) { + commit_across_open_cursor = false; + break; + } + } ndbout << "Deleting all from " << argv[i] << "..."; - if(clear_table(&MyNdb, pTab) == NDBT_FAILED){ + if(clear_table(&MyNdb, pTab, commit_across_open_cursor) == NDBT_FAILED){ res = NDBT_FAILED; ndbout << "FAILED" << endl; } @@ -91,7 +102,8 @@ int main(int argc, char** argv){ } -int clear_table(Ndb* pNdb, const NdbDictionary::Table* pTab, int parallelism) +int clear_table(Ndb* pNdb, const NdbDictionary::Table* pTab, + bool commit_across_open_cursor, int parallelism) { // Scan all records exclusive and delete // them one by one @@ -153,8 +165,12 @@ int clear_table(Ndb* pNdb, const NdbDictionary::Table* pTab, int parallelism) } while((check = rs->nextResult(false)) == 0); if(check != -1){ - check = pTrans->execute(Commit); - pTrans->restart(); + if (commit_across_open_cursor) { + check = pTrans->execute(Commit); + pTrans->restart(); // new tx id + } else { + check = pTrans->execute(NoCommit); + } } err = pTrans->getNdbError(); @@ -180,6 +196,10 @@ int clear_table(Ndb* pNdb, const NdbDictionary::Table* pTab, int parallelism) } goto failed; } + if (! commit_across_open_cursor && pTrans->execute(Commit) != 0) { + err = pTrans->getNdbError(); + goto failed; + } pNdb->closeTransaction(pTrans); return NDBT_OK; } From 5bbb5c29b79432ccc76b43ad0019012f007b3670 Mon Sep 17 00:00:00 2001 From: "tomas@poseidon.ndb.mysql.com" <> Date: Tue, 7 Feb 2006 00:03:39 +0100 Subject: [PATCH 4/4] Bug #17154 load data infile of char values into a table of char(PK) hangs Bug #17158 load data infile of char values into table of char with no (PK) fails to load Bug #17081 Doing "LOAD DATA INFILE" directly after delete can cause missing data --- mysql-test/r/ndb_load.result | 80 ++++++++++++++++++++++++++++++++++++ mysql-test/t/ndb_load.test | 24 +++++++++++ sql/ha_ndbcluster.cc | 22 ++++++++-- sql/sql_load.cc | 7 +++- 4 files changed, 127 insertions(+), 6 deletions(-) create mode 100644 mysql-test/r/ndb_load.result create mode 100644 mysql-test/t/ndb_load.test diff --git a/mysql-test/r/ndb_load.result b/mysql-test/r/ndb_load.result new file mode 100644 index 00000000000..76da5b2a215 --- /dev/null +++ b/mysql-test/r/ndb_load.result @@ -0,0 +1,80 @@ +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (word CHAR(20) NOT NULL PRIMARY KEY) ENGINE=NDB; +LOAD DATA INFILE '../../std_data/words.dat' INTO TABLE t1 ; +ERROR 23000: Can't write; duplicate key in table 't1' +DROP TABLE t1; +CREATE TABLE t1 (word CHAR(20) NOT NULL) ENGINE=NDB; +LOAD DATA INFILE '../../std_data/words.dat' INTO TABLE t1 ; +SELECT * FROM t1 ORDER BY word; +word +Aarhus +Aarhus +Aaron +Aaron +Ababa +Ababa +aback +aback +abaft +abaft +abandon +abandon +abandoned +abandoned +abandoning +abandoning +abandonment +abandonment +abandons +abandons +abase +abased +abasement +abasements +abases +abash +abashed +abashes +abashing +abasing +abate +abated +abatement +abatements +abater +abates +abating +Abba +abbe +abbey +abbeys +abbot +abbots +Abbott +abbreviate +abbreviated +abbreviates +abbreviating +abbreviation +abbreviations +Abby +abdomen +abdomens +abdominal +abduct +abducted +abduction +abductions +abductor +abductors +abducts +Abe +abed +Abel +Abelian +Abelson +Aberdeen +Abernathy +aberrant +aberration +DROP TABLE t1; diff --git a/mysql-test/t/ndb_load.test b/mysql-test/t/ndb_load.test new file mode 100644 index 00000000000..72a5b53eaad --- /dev/null +++ b/mysql-test/t/ndb_load.test @@ -0,0 +1,24 @@ +-- source include/have_ndb.inc +-- source include/not_embedded.inc + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +# +# Basic test for different types of loading data +# + +# should give duplicate key +CREATE TABLE t1 (word CHAR(20) NOT NULL PRIMARY KEY) ENGINE=NDB; +--error 1022 +LOAD DATA INFILE '../../std_data/words.dat' INTO TABLE t1 ; +DROP TABLE t1; + +# now without a primary key we should be ok +CREATE TABLE t1 (word CHAR(20) NOT NULL) ENGINE=NDB; +LOAD DATA INFILE '../../std_data/words.dat' INTO TABLE t1 ; +SELECT * FROM t1 ORDER BY word; +DROP TABLE t1; + +# End of 4.1 tests diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index 594551b918a..f5c0f3dc173 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -3046,9 +3046,23 @@ int ha_ndbcluster::end_bulk_insert() "rows_inserted:%d, bulk_insert_rows: %d", (int) m_rows_inserted, (int) m_bulk_insert_rows)); m_bulk_insert_not_flushed= FALSE; - if (execute_no_commit(this,trans) != 0) { - no_uncommitted_rows_execute_failure(); - my_errno= error= ndb_err(trans); + if (m_transaction_on) + { + if (execute_no_commit(this, trans) != 0) + { + no_uncommitted_rows_execute_failure(); + my_errno= error= ndb_err(trans); + } + } + else + { + if (execute_commit(this, trans) != 0) + { + no_uncommitted_rows_execute_failure(); + my_errno= error= ndb_err(trans); + } + int res= trans->restart(); + DBUG_ASSERT(res == 0); } } @@ -4867,7 +4881,7 @@ bool ha_ndbcluster::low_byte_first() const } bool ha_ndbcluster::has_transactions() { - return m_transaction_on; + return TRUE; } const char* ha_ndbcluster::index_type(uint key_number) { diff --git a/sql/sql_load.cc b/sql/sql_load.cc index aa4ea3e6c8c..4e6c458cc43 100644 --- a/sql/sql_load.cc +++ b/sql/sql_load.cc @@ -285,8 +285,11 @@ int mysql_load(THD *thd,sql_exchange *ex,TABLE_LIST *table_list, else error=read_sep_field(thd,info,table,fields,read_info,*enclosed, skip_lines); - if (table->file->end_bulk_insert()) - error=1; /* purecov: inspected */ + if (table->file->end_bulk_insert() && !error) + { + table->file->print_error(my_errno, MYF(0)); + error= 1; + } table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY); table->next_number_field=0; }