Below is the list of changes that have just been committed into a local
6.0-falcon repository of . When 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-05-21 16:30:57-04:00, jas@rowvwade. +17 -0
Added support for MySQL "optimize table" statement. This is still
a work in progress.
storage/falcon/Database.cpp@stripped, 2007-05-21 16:30:40-04:00, jas@rowvwade. +119 -12
Added extensions to core system tables to hold table cardinality
and records_per_value for index segments.
storage/falcon/Database.h@stripped, 2007-05-21 16:30:40-04:00, jas@rowvwade. +20 -18
Added extensions to core system tables to hold table cardinality
and records_per_value for index segments.
storage/falcon/FsbSort.cpp@stripped, 2007-05-21 16:30:41-04:00, jas@rowvwade. +34 -22
Stylistic revision in anticipation of large revision to support
derived table.
storage/falcon/Index.cpp@stripped, 2007-05-21 16:30:41-04:00, jas@rowvwade. +16 -2
Work in progress to manage records per index segment to
support MySQL optimizer.
storage/falcon/Index.h@stripped, 2007-05-21 16:30:42-04:00, jas@rowvwade. +4 -2
Work in progress to support MySQL optimizer data.
storage/falcon/NSelect.cpp@stripped, 2007-05-21 16:30:42-04:00, jas@rowvwade. +1 -1
Fixed bug in native Falcon "select count(distinct xyz)" implementaion.
storage/falcon/SQLError.cpp@stripped, 2007-05-21 16:30:42-04:00, jas@rowvwade. +0 -2
Eliminated dead code.
storage/falcon/Section.cpp@stripped, 2007-05-21 16:30:43-04:00, jas@rowvwade. +2 -2
Added code to estimate section cardinality. Probably won't be
used and will be elminated later.
storage/falcon/StorageConnection.cpp@stripped, 2007-05-21 16:30:44-04:00, jas@rowvwade. +5 -0
Added encapsulated method to fetch Falcon transaction object
for storage connection.
storage/falcon/StorageConnection.h@stripped, 2007-05-21 16:30:44-04:00, jas@rowvwade. +2 -0
Added encapsulated method to fetch Falcon transaction object
for storage connection.
storage/falcon/StorageTable.cpp@stripped, 2007-05-21 16:30:44-04:00, jas@rowvwade. +7 -0
Added support for MySQL optimize statement.
storage/falcon/StorageTable.h@stripped, 2007-05-21 16:30:45-04:00, jas@rowvwade. +2 -2
Added support for MySQL optimize statement.
storage/falcon/Table.cpp@stripped, 2007-05-21 16:30:45-04:00, jas@rowvwade. +28 -2
Added support for MySQL optimize statement to compute
optimizer data.
storage/falcon/Table.h@stripped, 2007-05-21 16:30:46-04:00, jas@rowvwade. +3 -2
Added support for MySQL optimize statement to compute
optimizer data.
storage/falcon/Transaction.cpp@stripped, 2007-05-21 16:30:46-04:00, jas@rowvwade. +1 -1
Added code to never decrement cardinality below zero.
storage/falcon/ha_falcon.cpp@stripped, 2007-05-21 16:30:46-04:00, jas@rowvwade. +13 -0
Added support for MySQL "optimize table" statement.
storage/falcon/ha_falcon.h@stripped, 2007-05-21 16:30:47-04:00, jas@rowvwade. +1 -0
Added support for MySQL "optimize table" statement.
# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: jas
# Host: rowvwade.
# Root: D:/MySQL/mysql-5.1-falcon
--- 1.60/storage/falcon/Database.cpp 2007-05-21 16:31:21 -04:00
+++ 1.61/storage/falcon/Database.cpp 2007-05-21 16:31:21 -04:00
@@ -112,6 +112,20 @@
viewDefinition clob,\
primary key (tableName, schema));";
+static const char *createOds3aTables =
+ "upgrade table Tables (\
+ tableName varchar (128) not null,\
+ schema varchar (128) not null,\
+ type varchar (16),\
+ dataSection int,\
+ blobSection int,\
+ tableId int,\
+ currentVersion int,\
+ remarks text,\
+ viewDefinition clob,\
+ cardinality bigint,\
+ primary key (tableName, schema));";
+
static const char *createOds2Fields =
"create table Fields (\
field varchar (128) not null,\
@@ -197,6 +211,17 @@
partial int,\
primary key (schema, indexName, field));";
+static const char *createOds3aIndexFields =
+ "upgrade table IndexFields (\
+ indexName varchar (128) not null,\
+ schema varchar (128) not null,\
+ tableName varchar (128) not null,\
+ field varchar (128) not null,\
+ position int,\
+ partial int,\
+ records_per_value int,\
+ primary key (schema, indexName, field));";
+
static const char *createForeignKeys =
"create table ForeignKeys (\
primaryTableId int not null,\
@@ -301,6 +326,24 @@
NULL
};
+static const char *ods3aUpgrade [] = {
+ createOds3aTables,
+ createOds3aIndexFields,
+ NULL
+ };
+
+static const char *changedTables [] = {
+ "TABLES",
+ "FIELDS",
+ "INDEXFIELDS",
+ //"INDEXES",
+ //"FORMATS",
+ //"FOREIGNKEYS",
+ //"DOMAINS",
+ //"REPOSITORIES",
+ NULL
+ };
+
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
@@ -364,6 +407,7 @@
serialLog = NULL;
pageWriter = NULL;
zombieTables = NULL;
+ updateCardinality = NULL;
}
@@ -873,9 +917,14 @@
Sync syncSystemTransaction(&syncSysConnection, "Database::findTable");
syncSystemTransaction.lock(Shared);
+
PreparedStatement *statement = prepareStatement (
- "select tableName,tableId,dataSection,blobSection,currentVersion,schema,viewDefinition \
- from Tables where tableName=? and schema=?");
+ (fieldExtensions) ?
+ "select tableName,tableId,dataSection,blobSection,currentVersion,schema,viewDefinition,cardinality \
+ from Tables where tableName=? and schema=?" :
+ "select tableName,tableId,dataSection,blobSection,currentVersion,schema,viewDefinition,0 \
+ from Tables where tableName=? and schema=?");
+
statement->setString (1, name);
statement->setString (2, schema);
ResultSet *resultSet = statement->executeQuery();
@@ -1213,7 +1262,7 @@
return table;
PreparedStatement *statement = prepareStatement (
- "select tableName,tableId,dataSection,blobSection,currentVersion,schema,viewDefinition \
+ "select tableName,tableId,dataSection,blobSection,currentVersion,schema,viewDefinition,cardinality \
from system.Tables where tableid=?");
statement->setInt (1, tableId);
ResultSet *resultSet = statement->executeQuery();
@@ -1234,8 +1283,8 @@
const char *name = getString (resultSet->getString(1));
int version = resultSet->getInt (5);
- const char *schemaName = getString (resultSet->getString (6));
- Table *table = new Table (this, schemaName, name, resultSet->getInt (2), version);
+ const char *schemaName = getString (resultSet->getString(6));
+ Table *table = new Table(this, schemaName, name, resultSet->getInt(2), version, resultSet->getLong(8));
int dataSection = resultSet->getInt (3);
@@ -1251,11 +1300,14 @@
{
CompiledStatement statement (systemConnection);
JString string;
+
// Do a little backward compatibility
- if (strncmp (viewDef, "create view ", strlen ("create view ")) == 0)
+
+ if (strncmp (viewDef, "create view ", strlen("create view ")) == 0)
string = viewDef;
else
string.Format ("create view %s.%s %s", schemaName, name, viewDef);
+
table->setView (statement.getView (string));
}
}
@@ -1342,8 +1394,10 @@
if (formatting)
{
Table **ptr;
+
for (ptr = &tableList; *ptr; ptr = &((*ptr)->next))
;
+
table->next = *ptr;
*ptr = table;
}
@@ -1388,6 +1442,12 @@
if (shuttingDown)
return;
+ if (updateCardinality)
+ {
+ updateCardinality->close();
+ updateCardinality = NULL;
+ }
+
shuttingDown = true;
if (systemConnection &&
@@ -1508,7 +1568,7 @@
void Database::scavenge()
{
- //OpSys::logParameters();
+ updateCardinalities();
// Start by scavenging compiled statements. If they're moldy and not in use,
// off with their heads!
@@ -1732,6 +1792,12 @@
void Database::upgradeSystemTables()
{
+ for (const char **tableName = changedTables; *tableName; ++tableName)
+ {
+ Table *table = findTable("SYSTEM", *tableName);
+ table->refreshFields();
+ }
+
Table *table = findTable ("SYSTEM", "SCHEMAS");
if (!table)
@@ -1745,10 +1811,7 @@
}
table = findTable ("SYSTEM", "FIELDS");
- table->refreshFields();
table->loadIndexes();
-
- //table = findTable ("SYSTEM", "FIELDS");
if (!table->findField ("PRECISION"))
{
@@ -1760,8 +1823,17 @@
statement->close();
}
- table = findTable ("SYSTEM", "INDEXFIELDS");
- table->refreshFields();
+ Table *tables = findTable("SYSTEM", "TABLES");
+
+ if (!tables->findField ("CARDINALITY"))
+ {
+ Statement *statement = createStatement();
+
+ for (const char **sql = ods3aUpgrade; *sql; ++sql)
+ statement->execute (*sql);
+
+ statement->close();
+ }
fieldExtensions = true;
}
@@ -2100,4 +2172,39 @@
void Database::getTransactionSummaryInfo(InfoTable* infoTable)
{
transactionManager->getSummaryInfo(infoTable);
+}
+
+void Database::updateCardinalities(void)
+{
+ Sync sync (&syncTables, "Database::updateCardinalities");
+ sync.lock (Shared);
+ Sync syncSystemTransaction(&syncSysConnection, "Database::updateCardinalities");
+ bool hit = false;
+
+ for (Table *table = tableList; table; table = table->next)
+ {
+ uint64 cardinality = table->cardinality;
+
+ if (cardinality != table->priorCardinality)
+ {
+ if (!hit)
+ {
+ if (!updateCardinality)
+ updateCardinality = prepareStatement(
+ "update system.tables set cardinality=? where schema=? and tablename=?");
+
+ syncSystemTransaction.lock(Exclusive);
+ hit = true;
+ }
+
+ updateCardinality->setLong(1, cardinality);
+ updateCardinality->setString(2, table->schemaName);
+ updateCardinality->setString(3, table->name);
+ updateCardinality->executeUpdate();
+ table->priorCardinality = cardinality;
+ }
+ }
+
+ if (hit)
+ commitSystemTransaction();
}
--- 1.28/storage/falcon/Database.h 2007-05-21 16:31:21 -04:00
+++ 1.29/storage/falcon/Database.h 2007-05-21 16:31:21 -04:00
@@ -205,6 +205,12 @@
void validateCache(void);
void commitByXid(int xidLength, const UCHAR* xid);
void rollbackByXid(int xidLength, const UCHAR* xid);
+ void getTransactionSummaryInfo(InfoTable* infoTable);
+ void updateCardinalities(void);
+ void getIOInfo(InfoTable* infoTable);
+ void getTransactionInfo(InfoTable* infoTable);
+ void getSerialLogInfo(InfoTable* infoTable);
+
Dbb *dbb;
Cache *cache;
@@ -245,23 +251,20 @@
Scheduler *internalScheduler;
Scavenger *scavenger;
Scavenger *garbageCollector;
- TemplateManager *templateManager;
- ImageManager *imageManager;
- SessionManager *sessionManager;
- RoleModel *roleModel;
- LicenseManager *licenseManager;
- SequenceManager *sequenceManager;
- SymbolManager *symbolManager;
- RepositoryManager *repositoryManager;
- TransactionManager *transactionManager;
- FilterSetManager *filterSetManager;
- SearchWords *searchWords;
- Thread *tickerThread;
- PageWriter *pageWriter;
-
- void getIOInfo(InfoTable* infoTable);
- void getTransactionInfo(InfoTable* infoTable);
- void getSerialLogInfo(InfoTable* infoTable);
+ TemplateManager *templateManager;
+ ImageManager *imageManager;
+ SessionManager *sessionManager;
+ RoleModel *roleModel;
+ LicenseManager *licenseManager;
+ SequenceManager *sequenceManager;
+ SymbolManager *symbolManager;
+ RepositoryManager *repositoryManager;
+ TransactionManager *transactionManager;
+ FilterSetManager *filterSetManager;
+ SearchWords *searchWords;
+ Thread *tickerThread;
+ PageWriter *pageWriter;
+ PreparedStatement *updateCardinality;
volatile time_t timestamp;
volatile int numberQueries;
@@ -279,7 +282,6 @@
int64 recordMemoryLower;
int64 lastRecordMemory;
time_t creationTime;
- void getTransactionSummaryInfo(InfoTable* infoTable);
};
#endif // !defined(AFX_DATABASE_H__5EC961D1_A406_11D2_AB5B_0000C01D2301__INCLUDED_)
--- 1.3/storage/falcon/FsbSort.cpp 2007-05-21 16:31:21 -04:00
+++ 1.4/storage/falcon/FsbSort.cpp 2007-05-21 16:31:21 -04:00
@@ -51,7 +51,7 @@
node = expr;
type = sortType;
numberKeys = node->count;
- parameters = new SortParameters [numberKeys];
+ parameters = new SortParameters[numberKeys];
sortSlot = statement->getSortSlot();
for (int n = 0; n < node->count; ++n)
@@ -68,32 +68,30 @@
}
int *ptr = contextIds;
- getStreams (&ptr);
+ getStreams(&ptr);
numberContexts = ptr - contextIds;
}
FsbSort::~FsbSort()
{
delete [] parameters;
-
- if (stream)
- delete stream;
+ delete stream;
}
void FsbSort::open(Statement * statement)
{
- statement->deleteSort (sortSlot);
- stream->open (statement);
+ statement->deleteSort(sortSlot);
+ stream->open(statement);
}
Row* FsbSort::fetch(Statement * statement)
{
SortRecord *record;
- Sort *sort = statement->sorts [sortSlot];
+ Sort *sort = statement->sorts[sortSlot];
if (sort == NULL)
{
- sort = new Sort (parameters, SORT_RUN_LENGTH, type == distinct);
+ sort = new Sort(parameters, SORT_RUN_LENGTH, type == distinct);
statement->sorts [sortSlot] = sort;
for (;;)
@@ -129,11 +127,11 @@
if (numberContexts)
{
- records = new Record* [numberContexts];
+ records = new Record*[numberContexts];
for (int n = 0; n < numberContexts; ++n)
{
- Record *record = statement->getContext (contextIds [n])->record;
+ Record *record = statement->getContext(contextIds [n])->record;
if (record)
record->addRef();
@@ -144,16 +142,29 @@
record = new SortRecord (statement, row, numberKeys, numberContexts, records);
+ for (int n = 0; n < numberKeys; ++n)
+ {
+ NNode *expr = node->children[n];
+
+ if (type == order)
+ expr = expr->children[0];
+
+ record->keys[n].setValue(expr->eval(statement), true);
+ }
+
+ /***
if (type != order)
for (int n = 0; n < numberKeys; ++n)
- record->keys[n].setValue (node->children [n]->eval (statement), true);
+ record->keys[n].setValue(node->children [n]->eval (statement), true);
else
for (int n = 0; n < numberKeys; ++n)
- record->keys[n].setValue (node->children [n]->children [0]->eval (statement), true);
+ record->keys[n].setValue(node->children [n]->children [0]->eval (statement), true);
+ ***/
}
- sort->add (record);
+ sort->add(record);
}
+
sort->sort();
}
@@ -162,30 +173,31 @@
if (record == NULL)
{
close(statement);
+
return NULL;
}
for (int n = 0; n < numberContexts; ++n)
- statement->getContext (contextIds [n])->setRecord (record->object [n]);
+ statement->getContext(contextIds [n])->setRecord (record->object [n]);
return record->row;
}
void FsbSort::close(Statement * statement)
{
- stream->close (statement);
- statement->deleteSort (sortSlot);
+ stream->close(statement);
+ statement->deleteSort(sortSlot);
}
void FsbSort::prettyPrint(int level, PrettyPrint *pp)
{
- pp->indent (level++);
- pp->put ("Sort\n");
- node->prettyPrint (level, pp);
- stream->prettyPrint (level, pp);
+ pp->indent(level++);
+ pp->put("Sort\n");
+ node->prettyPrint(level, pp);
+ stream->prettyPrint(level, pp);
}
void FsbSort::getStreams(int **ptr)
{
- stream->getStreams (ptr);
+ stream->getStreams(ptr);
}
--- 1.47/storage/falcon/Index.cpp 2007-05-21 16:31:21 -04:00
+++ 1.48/storage/falcon/Index.cpp 2007-05-21 16:31:21 -04:00
@@ -88,7 +88,12 @@
rebuild = false;
fields = new Field* [numberFields];
partialLengths = NULL;
+ recordsPerSegment = NULL;
rootPage = 0;
+ recordsPerSegment = new int[numberFields];
+
+ for (int n = 0; n < numberFields; ++n)
+ recordsPerSegment[n] = 0;
}
Index::~Index()
@@ -107,6 +112,7 @@
delete[] fields;
delete[] partialLengths;
+ delete[] recordsPerSegment;
}
void Index::addField(Field * fld, int position)
@@ -455,8 +461,8 @@
memset (fields, 0, sizeof (Field*) * numberFields);
const char *sql = (database->fieldExtensions) ?
- "select field,position,partial from IndexFields where indexName=? and schema=? and tableName=?" :
- "select field,position,0 from IndexFields where indexName=? and schema=? and tableName=?";
+ "select field,position,partial,records_per_value from IndexFields where indexName=? and schema=? and tableName=?" :
+ "select field,position,0,0 from IndexFields where indexName=? and schema=? and tableName=?";
PreparedStatement *statement = database->prepareStatement(sql);
statement->setString (1, name);
@@ -468,6 +474,7 @@
{
int position = set->getInt (2);
fields[position] = table->findField (set->getSymbol(1));
+ recordsPerSegment[position] = set->getInt(4);
setPartialLength(position, set->getInt(3));
}
@@ -776,12 +783,15 @@
int maxKeyLen = database->getMaxKeyLength() * RUN / (RUN - 1);
// All but the last field will be padded to the nearest RUN length
+
for (int s = 0; s < numberFields; s++)
{
fld = fields[s];
+
if ((fld->type == String) || (fld->type == Varchar) || (fld->type == Char))
{
len = getPartialLength(s);
+
if (len == 0)
len = fld->length;
}
@@ -801,4 +811,8 @@
throw SQLEXCEPTION (INDEX_OVERFLOW, "Maximum key length can be exceeded on index %s on table %s.%s",
(const char*) name, table->schemaName, table->name);
}
+}
+
+void Index::optimize(uint64 cardinality, Transaction *transaction)
+{
}
--- 1.18/storage/falcon/Index.h 2007-05-21 16:31:21 -04:00
+++ 1.19/storage/falcon/Index.h 2007-05-21 16:31:21 -04:00
@@ -101,6 +101,9 @@
void makeKey (Field *field, Value *value, int segment, IndexKey *key);
void detachDeferredIndex(DeferredIndex *deferredIndex);
+ UCHAR getPadByte(void);
+ int getRootPage(void);
+ void optimize(uint64 cardinality, Transaction *transaction);
static JString getTableName (Database *database, const char *schema, const char *indexName);
static void deleteIndex (Database *database, const char *schema, const char *indexName);
@@ -122,11 +125,10 @@
int indexVersion;
int type;
int *partialLengths;
+ int *recordsPerSegment;
bool savePending;
bool damaged;
bool rebuild;
- UCHAR getPadByte(void);
- int getRootPage(void);
};
#endif // !defined(AFX_INDEX_H__02AD6A44_A433_11D2_AB5B_0000C01D2301__INCLUDED_)
--- 1.6/storage/falcon/NSelect.cpp 2007-05-21 16:31:21 -04:00
+++ 1.7/storage/falcon/NSelect.cpp 2007-05-21 16:31:21 -04:00
@@ -288,7 +288,7 @@
stream = new FsbGroup (this, groups, stream);
}
- if (branch->getChild (0))
+ if (branch->getChild (0) || distinct)
stream = new FsbSort (statement, values, stream, distinct);
if (sort)
--- 1.8/storage/falcon/SQLError.cpp 2007-05-21 16:31:21 -04:00
+++ 1.9/storage/falcon/SQLError.cpp 2007-05-21 16:31:21 -04:00
@@ -182,8 +182,6 @@
{
#ifdef ENGINE
LogLock logLock;
- //Sync sync(&Log::syncObject, "SQLError::error");
- //sync.lock(Exclusive);
Log::log(LogException, "Exception: %s\n", string);
#endif
}
--- 1.43/storage/falcon/Section.cpp 2007-05-21 16:31:21 -04:00
+++ 1.44/storage/falcon/Section.cpp 2007-05-21 16:31:21 -04:00
@@ -1285,7 +1285,7 @@
{
if (sectionPage->level == 0)
{
- for (uint n = dbb->pagesPerSection - 1; n >= 0; --n)
+ for (int n = dbb->pagesPerSection - 1; n >= 0; --n)
if (sectionPage->pages[n])
{
Bdb *bdb = dbb->fetchPage(sectionPage->pages[n], PAGE_record_locator, Shared);
@@ -1299,7 +1299,7 @@
return -1;
}
- for (uint n = dbb->pagesPerSection - 1; n >= 0; --n)
+ for (int n = dbb->pagesPerSection - 1; n >= 0; --n)
if (sectionPage->pages[n])
{
Bdb *bdb = dbb->fetchPage(sectionPage->pages[n], PAGE_record_locator, Shared);
--- 1.26/storage/falcon/StorageConnection.cpp 2007-05-21 16:31:21 -04:00
+++ 1.27/storage/falcon/StorageConnection.cpp 2007-05-21 16:31:21 -04:00
@@ -435,3 +435,8 @@
traceStream->putCharacter('\n');
}
}
+
+Transaction* StorageConnection::getTransaction(void)
+{
+ return connection->getTransaction();
+}
--- 1.20/storage/falcon/StorageConnection.h 2007-05-21 16:31:21 -04:00
+++ 1.21/storage/falcon/StorageConnection.h 2007-05-21 16:31:21 -04:00
@@ -45,6 +45,7 @@
class StorageTableShare;
class StorageHandler;
class SQLException;
+class Transaction;
class StorageConnection
{
@@ -91,6 +92,7 @@
void disconnect(void);
void setMySqlThread(THD* thd);
void setCurrentStatement(const char* text);
+ Transaction* getTransaction(void);
Connection *connection;
Database *database;
--- 1.50/storage/falcon/StorageTable.cpp 2007-05-21 16:31:21 -04:00
+++ 1.51/storage/falcon/StorageTable.cpp 2007-05-21 16:31:21 -04:00
@@ -535,3 +535,10 @@
recordLocked = false;
}
}
+
+int StorageTable::optimize(void)
+{
+ share->table->optimize(storageConnection->getTransaction());
+
+ return 0;
+}
--- 1.18/storage/falcon/StorageTable.h 2007-05-21 16:31:21 -04:00
+++ 1.19/storage/falcon/StorageTable.h 2007-05-21 16:31:21 -04:00
@@ -90,7 +90,8 @@
virtual int isKeyNull(const unsigned char* key, int keyLength);
virtual void setPartialKey(void);
virtual void unlockRecord(void);
- //int lockRecord(void);
+ virtual void unlockRow(void);
+ virtual int optimize(void);
JString name;
StorageTable *collision;
@@ -109,7 +110,6 @@
Stream insertStream;
bool partialKey;
bool recordLocked;
- virtual void unlockRow(void);
};
#endif
--- 1.107/storage/falcon/Table.cpp 2007-05-21 16:31:21 -04:00
+++ 1.108/storage/falcon/Table.cpp 2007-05-21 16:31:21 -04:00
@@ -52,7 +52,7 @@
#include "Repository.h"
#include "Interlock.h"
#include "Collation.h"
-#include "Section.h"
+//#include "Section.h"
#ifndef STORAGE_ENGINE
#include "Trigger.h"
@@ -82,10 +82,12 @@
init(id, schema, tableName);
}
-Table::Table(Database *db, const char * schema, const char * tableName, int id, int version) : PrivilegeObject(db)
+Table::Table(Database *db, const char * schema, const char * tableName, int id, int version, uint64 numberRecords) : PrivilegeObject(db)
{
init(id, schema, tableName);
formatVersion = version;
+ priorCardinality = numberRecords;
+ cardinality = numberRecords;
}
Table::~Table()
@@ -782,6 +784,7 @@
thawedBytes = 0;
thawedRecords = 0;
cardinality = 0;
+ priorCardinality = 0;
}
Record* Table::fetch(int32 recordNumber)
@@ -3019,6 +3022,7 @@
int64 Table::estimateCardinality(void)
{
+ /***
if (cardinality)
return cardinality;
@@ -3026,6 +3030,28 @@
dataSection = dbb->findSection(dataSectionId);
cardinality = dataSection->estimateCardinality();
+ ***/
return cardinality;
+}
+
+void Table::optimize(Transaction *transaction)
+{
+ uint64 count = 0;
+ int recordNumber = 0;
+
+ for (Record *record; (record = fetchNext(recordNumber));)
+ {
+ recordNumber = record->recordNumber + 1;
+ record = record->fetchVersion(transaction);
+
+ if (record)
+ ++count;
+ }
+
+ cardinality = count;
+
+ FOR_INDEXES(index, this);
+ index->optimize(count, transaction);
+ END_FOR;
}
--- 1.22/storage/falcon/Table.h 2007-05-21 16:31:21 -04:00
+++ 1.23/storage/falcon/Table.h 2007-05-21 16:31:21 -04:00
@@ -70,7 +70,7 @@
class Table : public PrivilegeObject
{
public:
- Table(Database *db, const char * schema, const char * tableName, int id, int version);
+ Table(Database *db, const char * schema, const char * tableName, int id, int version, uint64 numberRecords);
Table(Database *db, int tableId, const char *schema, const char *name);
virtual ~Table();
@@ -176,6 +176,7 @@
bool hasUncommittedRecords(Transaction* transaction);
void checkAncestor(Record* current, Record* oldRecord);
int64 estimateCardinality(void);
+ void optimize(Transaction *transaction);
Record* fetchForUpdate(Transaction* transaction, Record* record);
RecordVersion* lockRecord(Record* record, Transaction* transaction);
@@ -215,6 +216,7 @@
Section *dataSection;
Section *blobSection;
uint64 cardinality;
+ uint64 priorCardinality;
int tableId;
int dataSectionId;
int blobSectionId;
@@ -233,7 +235,6 @@
protected:
const char *type;
-public:
};
#endif // !defined(AFX_TABLE_H__02AD6A42_A433_11D2_AB5B_0000C01D2301__INCLUDED_)
--- 1.87/storage/falcon/Transaction.cpp 2007-05-21 16:31:21 -04:00
+++ 1.88/storage/falcon/Transaction.cpp 2007-05-21 16:31:21 -04:00
@@ -264,7 +264,7 @@
for (RecordVersion *record = records; record; record = record->next)
if (!record->priorVersion)
++record->table->cardinality;
- else if (record->state == recDeleted)
+ else if (record->state == recDeleted && record->table->cardinality > 0)
--record->table->cardinality;
syncActiveTransactions.unlock();
--- 1.163/storage/falcon/ha_falcon.cpp 2007-05-21 16:31:21 -04:00
+++ 1.164/storage/falcon/ha_falcon.cpp 2007-05-21 16:31:21 -04:00
@@ -554,6 +554,19 @@
DBUG_RETURN(0);
}
+
+int StorageInterface::optimize(THD* thd, HA_CHECK_OPT* check_opt)
+{
+ DBUG_ENTER("StorageInterface::optimize");
+
+ int ret = storageTable->optimize();
+
+ if (ret)
+ DBUG_RETURN(error(ret));
+
+ DBUG_RETURN(0);
+}
+
uint8 StorageInterface::table_cache_type(void)
{
return HA_CACHE_TBL_TRANSACT;
--- 1.37/storage/falcon/ha_falcon.h 2007-05-21 16:31:21 -04:00
+++ 1.38/storage/falcon/ha_falcon.h 2007-05-21 16:31:21 -04:00
@@ -149,6 +149,7 @@
bool lockForUpdate;
key_range startKey;
key_range endKey;
+ virtual int optimize(THD* thd, HA_CHECK_OPT* check_opt);
};
class NfsPluginHandler
| Thread |
|---|
| • bk commit into 6.0-falcon tree (jas:1.2525) | U-ROWVWADEjas | 21 May |