Below is the list of changes that have just been committed into a local
6.0 repository of cpowers. When cpowers does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet@stripped, 2007-11-13 16:09:39-06:00, chris@stripped +20 -0
Bug#22173, "TRUNCATE does not reset auto_increment counter"
- Implemented fast truncate via delete_all_rows() interface.
- Added recreate sequence capability to reset auto_increment counters.
storage/falcon/Database.cpp@stripped, 2007-11-13 16:09:36-06:00, chris@stripped +25 -2
Added truncateTable()
storage/falcon/Database.h@stripped, 2007-11-13 16:09:36-06:00, chris@stripped +1 -0
Added truncateTable()
storage/falcon/Sequence.cpp@stripped, 2007-11-13 16:09:36-06:00, chris@stripped +5 -0
Added recreate()
storage/falcon/Sequence.h@stripped, 2007-11-13 16:09:36-06:00, chris@stripped +1 -0
Added recreate()
storage/falcon/SequenceManager.cpp@stripped, 2007-11-13 16:09:36-06:00, chris@stripped +9 -0
Added recreateSequence()
storage/falcon/SequenceManager.h@stripped, 2007-11-13 16:09:36-06:00, chris@stripped +1 -0
Added recreateSequence()
storage/falcon/StorageDatabase.cpp@stripped, 2007-11-13 16:09:36-06:00, chris@stripped +36 -1
Added truncateTable()
storage/falcon/StorageDatabase.h@stripped, 2007-11-13 16:09:36-06:00, chris@stripped +1 -0
Added truncateTable()
storage/falcon/StorageTable.cpp@stripped, 2007-11-13 16:09:36-06:00, chris@stripped +7 -0
Added truncateTable()
storage/falcon/StorageTable.h@stripped, 2007-11-13 16:09:36-06:00, chris@stripped +1 -0
Added truncateTable()
storage/falcon/StorageTableShare.cpp@stripped, 2007-11-13 16:09:36-06:00, chris@stripped +7 -0
Added truncateTable()
storage/falcon/StorageTableShare.h@stripped, 2007-11-13 16:09:36-06:00, chris@stripped +1 -0
Added truncateTable()
storage/falcon/Table.cpp@stripped, 2007-11-13 16:09:37-06:00, chris@stripped +66 -2
Added truncate()
Added 'force' option to rebuildIndexes()
storage/falcon/Table.h@stripped, 2007-11-13 16:09:37-06:00, chris@stripped +2 -1
Added truncate()
Added 'force' option to rebuildIndexes()
storage/falcon/Transaction.cpp@stripped, 2007-11-13 16:09:37-06:00, chris@stripped +16 -0
Added truncateTable()
storage/falcon/Transaction.h@stripped, 2007-11-13 16:09:37-06:00, chris@stripped +1 -0
Added truncateTable()
storage/falcon/TransactionManager.cpp@stripped, 2007-11-13 16:09:37-06:00, chris@stripped +11 -0
Added truncateTable()
storage/falcon/TransactionManager.h@stripped, 2007-11-13 16:09:37-06:00, chris@stripped +1 -0
Added truncateTable()
storage/falcon/ha_falcon.cpp@stripped, 2007-11-13 16:09:37-06:00, chris@stripped +30 -3
Implemented delete_all_rows() interface for TRUNCATE operations.
storage/falcon/ha_falcon.h@stripped, 2007-11-13 16:09:37-06:00, chris@stripped +3 -1
Added delete_all_rows()
diff -Nrup a/storage/falcon/Database.cpp b/storage/falcon/Database.cpp
--- a/storage/falcon/Database.cpp 2007-11-05 15:11:20 -06:00
+++ b/storage/falcon/Database.cpp 2007-11-13 16:09:36 -06:00
@@ -75,6 +75,7 @@
#include "LogStream.h"
#include "SyncTest.h"
#include "PriorityScheduler.h"
+#include "Sequence.h"
#ifndef STORAGE_ENGINE
#include "Applications.h"
@@ -1359,8 +1360,8 @@ void Database::dropTable(Table * table,
// Check for records in active transactions. If so, barf
if (hasUncommittedRecords(table, transaction))
- throw SQLError(UNCOMMITTED_UPDATES, "table %s.%s has uncommitted updates and can't be dropped",
- table->schemaName, table->name);
+ throw SQLError(UNCOMMITTED_UPDATES, "table %s.%s has uncommitted updates and can't be dropped",
+ table->schemaName, table->name);
// OK, now make sure any records are purged out of committed transactions as well
@@ -1406,6 +1407,28 @@ void Database::dropTable(Table * table,
delete table;
}
+void Database::truncateTable(Table *table, Transaction *transaction)
+{
+ Sync scavenge(&table->syncScavenge, "Database::truncateTable");
+
+ table->checkDrop();
+
+ // Check for records in active transactions
+
+ if (hasUncommittedRecords(table, transaction))
+ throw SQLError(UNCOMMITTED_UPDATES, "table %s.%s has uncommitted updates and cannot be truncated",
+ table->schemaName, table->name);
+
+ scavenge.lock(Shared);
+
+ // Purge records out of committed transactions
+
+ transactionManager->truncateTable(table, transaction);
+
+ // Recreate data/blob sections and indexes
+
+ table->truncate(transaction);
+}
void Database::addTable(Table * table)
{
diff -Nrup a/storage/falcon/Database.h b/storage/falcon/Database.h
--- a/storage/falcon/Database.h 2007-11-02 11:54:37 -05:00
+++ b/storage/falcon/Database.h 2007-11-13 16:09:36 -06:00
@@ -169,6 +169,7 @@ public:
void shutdown();
void execute (const char *sql);
void addTable (Table *table);
+ void truncateTable(Table *table, Transaction *transaction);
void dropTable (Table *table, Transaction *transaction);
void flushInversion(Transaction *transaction);
bool matches (const char *fileName);
diff -Nrup a/storage/falcon/Sequence.cpp b/storage/falcon/Sequence.cpp
--- a/storage/falcon/Sequence.cpp 2007-09-20 10:42:33 -05:00
+++ b/storage/falcon/Sequence.cpp 2007-11-13 16:09:36 -06:00
@@ -60,3 +60,8 @@ void Sequence::rename(const char* newNam
{
database->sequenceManager->renameSequence(this, newName);
}
+
+Sequence* Sequence::recreate(void)
+{
+ return database->sequenceManager->recreateSequence(this);
+}
diff -Nrup a/storage/falcon/Sequence.h b/storage/falcon/Sequence.h
--- a/storage/falcon/Sequence.h 2007-09-20 10:42:33 -05:00
+++ b/storage/falcon/Sequence.h 2007-11-13 16:09:36 -06:00
@@ -45,6 +45,7 @@ public:
Schema *schema;
Database *database;
void rename(const char* newName);
+ Sequence *recreate(void);
};
#endif // !defined(AFX_SEQUENCE_H__52A2DA15_7937_11D4_98F0_0000C01D2301__INCLUDED_)
diff -Nrup a/storage/falcon/SequenceManager.cpp b/storage/falcon/SequenceManager.cpp
--- a/storage/falcon/SequenceManager.cpp 2007-10-11 07:12:01 -05:00
+++ b/storage/falcon/SequenceManager.cpp 2007-11-13 16:09:36 -06:00
@@ -139,6 +139,15 @@ Sequence* SequenceManager::createSequenc
return sequence;
}
+Sequence* SequenceManager::recreateSequence(Sequence *oldSequence)
+{
+ const char *schemaName = database->getSymbol(oldSequence->schemaName);
+ const char *sequenceName = database->getSymbol(oldSequence->name);
+
+ deleteSequence(schemaName, sequenceName);
+ return createSequence(schemaName, sequenceName, 0);
+}
+
void SequenceManager::deleteSequence(const char *schema, const char *name)
{
Sync sync (&database->syncSysConnection, "SequenceManager::deleteSequence");
diff -Nrup a/storage/falcon/SequenceManager.h b/storage/falcon/SequenceManager.h
--- a/storage/falcon/SequenceManager.h 2007-09-20 10:42:33 -05:00
+++ b/storage/falcon/SequenceManager.h 2007-11-13 16:09:36 -06:00
@@ -48,6 +48,7 @@ protected:
SyncObject syncObject;
public:
void renameSequence(Sequence* sequence, const char* newName);
+ Sequence *recreateSequence(Sequence *oldSequence);
};
#endif // !defined(AFX_SEQUENCEMANAGER_H__52A2DA14_7937_11D4_98F0_0000C01D2301__INCLUDED_)
diff -Nrup a/storage/falcon/StorageDatabase.cpp b/storage/falcon/StorageDatabase.cpp
--- a/storage/falcon/StorageDatabase.cpp 2007-11-03 00:33:55 -05:00
+++ b/storage/falcon/StorageDatabase.cpp 2007-11-13 16:09:36 -06:00
@@ -520,6 +520,42 @@ int StorageDatabase::deleteTable(Storage
return res;
}
+int StorageDatabase::truncateTable(StorageConnection* storageConnection, StorageTableShare *tableShare)
+{
+ Connection *connection = storageConnection->connection;
+ Transaction *transaction = connection->transaction;
+ Database *database = connection->database;
+ Sequence *sequence = tableShare->sequence;
+
+ int res = 0;
+
+ try
+ {
+ database->truncateTable(tableShare->table, transaction);
+
+ if (sequence)
+ sequence = sequence->recreate();
+ }
+ catch (SQLException& exception)
+ {
+ int errorCode = exception.getSqlcode();
+ storageConnection->setErrorText(&exception);
+
+ switch (errorCode)
+ {
+ case NO_SUCH_TABLE:
+ return StorageErrorTableNotFound;
+
+ case UNCOMMITTED_UPDATES:
+ return StorageErrorUncommittedUpdates;
+ }
+
+ res = 200 - exception.getSqlcode();
+ }
+
+ return res;
+}
+
int StorageDatabase::deleteRow(StorageConnection *storageConnection, Table* table, int recordNumber)
{
Connection *connection = storageConnection->connection;
@@ -592,7 +628,6 @@ int StorageDatabase::updateRow(StorageCo
return 0;
}
-
int StorageDatabase::createIndex(StorageConnection *storageConnection, Table* table, const char* indexName, const char* sql)
{
diff -Nrup a/storage/falcon/StorageDatabase.h b/storage/falcon/StorageDatabase.h
--- a/storage/falcon/StorageDatabase.h 2007-09-20 10:42:40 -05:00
+++ b/storage/falcon/StorageDatabase.h 2007-11-13 16:09:36 -06:00
@@ -58,6 +58,7 @@ public:
int savepointRelease(Connection* connection, int savePoint);
int savepointRollback(Connection* connection, int savePoint);
int deleteTable(StorageConnection* storageConnection,StorageTableShare *tableShare);
+ int truncateTable(StorageConnection* storageConnection, StorageTableShare *tableShare);
int createIndex(StorageConnection *storageConnection, Table* table, StorageIndexDesc* indexDesc);
int renameTable(StorageConnection* storageConnection, Table* table, const char* newName, const char *schemaName);
Bitmap* indexScan(Index* index, StorageKey *lower, StorageKey *upper, int searchFlags, StorageConnection* storageConnection, Bitmap *bitmap);
diff -Nrup a/storage/falcon/StorageTable.cpp b/storage/falcon/StorageTable.cpp
--- a/storage/falcon/StorageTable.cpp 2007-11-03 00:33:56 -05:00
+++ b/storage/falcon/StorageTable.cpp 2007-11-13 16:09:36 -06:00
@@ -81,6 +81,13 @@ int StorageTable::deleteTable(void)
return ret;
}
+int StorageTable::truncateTable(void)
+{
+ int ret = share->truncateTable(storageConnection);
+
+ return ret;
+}
+
int StorageTable::insert(void)
{
try
diff -Nrup a/storage/falcon/StorageTable.h b/storage/falcon/StorageTable.h
--- a/storage/falcon/StorageTable.h 2007-10-31 01:41:17 -05:00
+++ b/storage/falcon/StorageTable.h 2007-11-13 16:09:36 -06:00
@@ -68,6 +68,7 @@ public:
virtual int open(void);
virtual int deleteTable(void);
virtual int deleteRow(int recordNumber);
+ virtual int truncateTable(void);
virtual int setIndex(int numberIndexes, int indexId, StorageIndexDesc* storageIndex);
virtual int indexScan();
virtual int setIndex(int indexId);
diff -Nrup a/storage/falcon/StorageTableShare.cpp b/storage/falcon/StorageTableShare.cpp
--- a/storage/falcon/StorageTableShare.cpp 2007-10-30 16:24:58 -05:00
+++ b/storage/falcon/StorageTableShare.cpp 2007-11-13 16:09:36 -06:00
@@ -142,6 +142,13 @@ int StorageTableShare::deleteTable(Stora
return res;
}
+int StorageTableShare::truncateTable(StorageConnection *storageConnection)
+{
+ int res = storageDatabase->truncateTable(storageConnection, this);
+
+ return res;
+}
+
void StorageTableShare::cleanupFieldName(const char* name, char* buffer, int bufferLength)
{
char *q = buffer;
diff -Nrup a/storage/falcon/StorageTableShare.h b/storage/falcon/StorageTableShare.h
--- a/storage/falcon/StorageTableShare.h 2007-11-13 03:56:54 -06:00
+++ b/storage/falcon/StorageTableShare.h 2007-11-13 16:09:36 -06:00
@@ -107,6 +107,7 @@ public:
int getIndexId(const char* schemaName, const char* indexName);
int create(StorageConnection *storageConnection, const char* sql, int64 autoIncrementValue);
int deleteTable(StorageConnection *storageConnection);
+ int truncateTable(StorageConnection *storageConnection);
void load(void);
void registerTable(void);
void unRegisterTable(void);
diff -Nrup a/storage/falcon/Table.cpp b/storage/falcon/Table.cpp
--- a/storage/falcon/Table.cpp 2007-11-09 11:27:37 -06:00
+++ b/storage/falcon/Table.cpp 2007-11-13 16:09:37 -06:00
@@ -1453,6 +1453,70 @@ void Table::drop(Transaction *transactio
database->commitSystemTransaction();
}
+void Table::truncate(Transaction *transaction)
+{
+ // Absolutely no access until truncate complete
+
+ Sync syncObj(&syncObject, "Table::truncate");
+ syncObj.lock(Exclusive);
+
+ // Ensure control of system transaction commit
+
+ Sync syncConnection(&database->syncSysConnection, "Table::truncate");
+ syncConnection.lock(Shared);
+
+ // Keep scavenger out of the way
+
+ Sync syncScavenger(&syncScavenge, "Table::truncate");
+ syncScavenger.lock(Shared);
+
+ Transaction *sysTransaction = database->getSystemTransaction();
+
+ // Delete data and blob sections
+
+ expunge(sysTransaction);
+
+ // Recreate data and blob sections
+
+ dataSectionId = dbb->createSection(TRANSACTION_ID(sysTransaction));
+ blobSectionId = dbb->createSection(TRANSACTION_ID(sysTransaction));
+
+ // Update system.tables with new section ids
+
+ PreparedStatement *statement = database->prepareStatement("update Tables set dataSection=?, blobSection=? where tableId=?");
+ statement->setInt(1, dataSectionId);
+ statement->setInt(2, blobSectionId);
+ statement->setInt(3, tableId);
+ statement->executeUpdate();
+ statement->close();
+
+ // Commit the physical and system changes
+
+ syncConnection.unlock();
+ database->commitSystemTransaction();
+
+ if (records)
+ {
+ delete records;
+ records = NULL;
+ }
+
+ // Rebuild indexes
+
+ rebuildIndexes(sysTransaction, true);
+
+ // Reset select Table attributes
+
+ priorCardinality = cardinality; // forces update to system tables during scavenge
+ cardinality = 0;
+ ageGroup = database->currentGeneration;
+ emptySections->clear();
+ recordBitmap->clear();
+ debugThawedRecords = 0;
+ debugThawedBytes = 0;
+ alterIsActive = false;
+}
+
void Table::checkNullable(Record * record)
{
Value value;
@@ -2609,10 +2673,10 @@ void Table::collationChanged(Field *fiel
END_FOR;
}
-void Table::rebuildIndexes(Transaction *transaction)
+void Table::rebuildIndexes(Transaction *transaction, bool force)
{
FOR_INDEXES(index, this);
- if (index->rebuild)
+ if (index->rebuild || force)
{
index->rebuild = false;
rebuildIndex(index, transaction);
diff -Nrup a/storage/falcon/Table.h b/storage/falcon/Table.h
--- a/storage/falcon/Table.h 2007-10-31 01:41:22 -05:00
+++ b/storage/falcon/Table.h 2007-11-13 16:09:37 -06:00
@@ -92,7 +92,7 @@ public:
void insertView(Transaction *transaction, int count, Field **fieldVector, Value **values);
void bind (Table *table);
void clearIndexesRebuild();
- void rebuildIndexes (Transaction *transaction);
+ void rebuildIndexes (Transaction *transaction, bool force = false);
void collationChanged (Field *field);
void validateBlobs (int optionMask);
void cleanupRecords(RecordScavenge *recordScavenge);
@@ -148,6 +148,7 @@ public:
void addField (Field *field);
void checkNullable (Record *record);
virtual void drop(Transaction *transaction);
+ virtual void truncate(Transaction *transaction);
void updateInversion (Record *record, Transaction *transaction);
int getFieldId (const char *name);
ForeignKey* findForeignKey (ForeignKey *key);
diff -Nrup a/storage/falcon/Transaction.cpp b/storage/falcon/Transaction.cpp
--- a/storage/falcon/Transaction.cpp 2007-10-31 01:41:24 -05:00
+++ b/storage/falcon/Transaction.cpp 2007-11-13 16:09:37 -06:00
@@ -863,6 +863,22 @@ void Transaction::dropTable(Table* table
ptr = &rec->nextInTrans;
}
+void Transaction::truncateTable(Table* table)
+{
+ Sync sync(&syncIndexes, "Transaction::truncateTable");
+ sync.lock(Exclusive);
+
+ releaseDeferredIndexes(table);
+
+ // Keep exclusive lock to avoid race condition with writeComplete
+
+ for (RecordVersion **ptr = &firstRecord, *rec; (rec = *ptr);)
+ if (rec->format->table == table)
+ removeRecord(rec);
+ else
+ ptr = &rec->nextInTrans;
+}
+
bool Transaction::hasUncommittedRecords(Table* table)
{
for (RecordVersion *rec = firstRecord; rec; rec = rec->nextInTrans)
diff -Nrup a/storage/falcon/Transaction.h b/storage/falcon/Transaction.h
--- a/storage/falcon/Transaction.h 2007-10-31 01:41:26 -05:00
+++ b/storage/falcon/Transaction.h 2007-11-13 16:09:37 -06:00
@@ -108,6 +108,7 @@ public:
void waitForTransaction();
bool waitForTransaction (TransId transId);
void dropTable(Table* table);
+ void truncateTable(Table* table);
bool hasUncommittedRecords(Table* table);
void writeComplete(void);
void releaseDependency(void);
diff -Nrup a/storage/falcon/TransactionManager.cpp b/storage/falcon/TransactionManager.cpp
--- a/storage/falcon/TransactionManager.cpp 2007-11-10 13:12:54 -06:00
+++ b/storage/falcon/TransactionManager.cpp 2007-11-13 16:09:37 -06:00
@@ -141,6 +141,17 @@ void TransactionManager::dropTable(Table
committedTrans.unlock();
}
+void TransactionManager::truncateTable(Table* table, Transaction* transaction)
+{
+ Sync committedTrans (&committedTransactions.syncObject, "TransactionManager::truncateTable");
+ committedTrans.lock (Shared);
+
+ for (Transaction *trans = committedTransactions.first; trans; trans = trans->next)
+ trans->truncateTable(table);
+
+ committedTrans.unlock();
+}
+
bool TransactionManager::hasUncommittedRecords(Table* table, Transaction* transaction)
{
Sync syncTrans (&activeTransactions.syncObject, "TransactionManager::hasUncommittedRecords");
diff -Nrup a/storage/falcon/TransactionManager.h b/storage/falcon/TransactionManager.h
--- a/storage/falcon/TransactionManager.h 2007-09-25 00:14:42 -05:00
+++ b/storage/falcon/TransactionManager.h 2007-11-13 16:09:37 -06:00
@@ -33,6 +33,7 @@ public:
TransId findOldestActive();
Transaction* startTransaction(Connection* connection);
void dropTable(Table* table, Transaction* transaction);
+ void truncateTable(Table* table, Transaction* transaction);
bool hasUncommittedRecords(Table* table, Transaction* transaction);
void commitByXid(int xidLength, const UCHAR* xid);
void rollbackByXid(int xidLength, const UCHAR* xid);
diff -Nrup a/storage/falcon/ha_falcon.cpp b/storage/falcon/ha_falcon.cpp
--- a/storage/falcon/ha_falcon.cpp 2007-11-13 13:34:26 -06:00
+++ b/storage/falcon/ha_falcon.cpp 2007-11-13 16:09:37 -06:00
@@ -812,7 +812,6 @@ THR_LOCK_DATA **StorageInterface::store_
DBUG_RETURN(to);
}
-
int StorageInterface::delete_table(const char *tableName)
{
DBUG_ENTER("StorageInterface::delete_table");
@@ -859,13 +858,42 @@ int StorageInterface::delete_table(const
DBUG_RETURN(error(res));
}
+#ifdef TRUNCATE_ENABLED
+int StorageInterface::delete_all_rows()
+{
+ DBUG_ENTER("StorageInterface::delete_all_rows");
+
+ int ret = 0;
+ struct st_table_share *tableShare = table_share;
+ struct st_table *tableObj = table;
+ const char *tableName = tableShare->normalized_path.str;
+
+ if (!mySqlThread)
+ mySqlThread = current_thd;
+
+ if (!storageShare)
+ if ( !(storageShare = storageHandler->preDeleteTable(tableName)) )
+ DBUG_RETURN(0);
+
+ if (!storageConnection)
+ if ( !(storageConnection = storageHandler->getStorageConnection(storageShare, mySqlThread, mySqlThread->thread_id, OpenDatabase)) )
+ DBUG_RETURN(0);
+
+ if (!storageTable)
+ storageTable = storageConnection->getStorageTable(storageShare);
+
+ storageTable->truncateTable();
+
+ DBUG_RETURN(ret);
+}
+#endif
+
uint StorageInterface::max_supported_keys(void) const
{
DBUG_ENTER("StorageInterface::max_supported_keys");
DBUG_RETURN(MAX_KEY);
}
-
int StorageInterface::write_row(uchar *buff)
{
DBUG_ENTER("StorageInterface::write_row");
@@ -983,7 +1011,6 @@ int StorageInterface::delete_row(const u
DBUG_RETURN(0);
}
-
int StorageInterface::commit(handlerton *hton, THD* thd, bool all)
{
diff -Nrup a/storage/falcon/ha_falcon.h b/storage/falcon/ha_falcon.h
--- a/storage/falcon/ha_falcon.h 2007-11-12 17:12:50 -06:00
+++ b/storage/falcon/ha_falcon.h 2007-11-13 16:09:37 -06:00
@@ -93,7 +93,9 @@ public:
virtual int reset_auto_increment(ulonglong value);
virtual const COND* cond_push(const COND* cond);
virtual int optimize(THD* thd, HA_CHECK_OPT* check_opt);
-
+#ifdef TRUNCATE_ENABLED
+ virtual int delete_all_rows(void);
+#endif
void getDemographics(void);
int createIndex(const char *schemaName, const char *tableName,
KEY *key, int indexNumber);
| Thread |
|---|
| • bk commit into 6.0 tree (chris:1.2675) BUG#22173 | cpowers | 13 Nov |