8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 06:43:04 +01:00
This commit is contained in:
robocop 2009-08-16 05:25:30 +00:00
parent 59909ed2f6
commit 8ce0cf3e79
5 changed files with 151 additions and 79 deletions

View File

@ -88,10 +88,12 @@ enum LocType { locEqual, locLess, locGreat, locGreatEqual, locLessEqual };
// 1) Items in the tree MUST be unique (this is performance optimization),
// you can always convert set of non-unique items to a set of unique items with count
// like this:
// struct TreeItem {
// struct TreeItem
// {
// Value value;
// int count;
// static const Key& generate(void *sender, const TreeItem& item) {
// static const Key& generate(void *sender, const TreeItem& item)
// {
// return KeyOfValue::generate(sender, value);
// }
// }
@ -137,7 +139,8 @@ public:
defaultAccessor.curr = NULL;
// Do not deallocate root page if tree is shallow
if (level == 0) {
if (level == 0)
{
if (root) {
((ItemList*) root)->clear();
}
@ -152,7 +155,8 @@ public:
// Delete all items pages
NodeList *lists = items->parent;
while (items) {
while (items)
{
ItemList *t = items->next;
items->~ItemList();
pool->deallocate(items);
@ -160,10 +164,12 @@ public:
}
// Delete all upper layers of tree
while (lists) {
while (lists)
{
NodeList *list = lists;
lists = lists->parent;
while (list) {
while (list)
{
NodeList *t = list->next;
list->~NodeList();
pool->deallocate(list);
@ -223,7 +229,8 @@ public:
if (level != other.level)
return level > other.level;
if (level == 0) {
if (level == 0)
{
if (root == NULL)
return other.root == NULL;
if (other.root == NULL)
@ -281,7 +288,8 @@ public:
// This is slow approach especially when used for assignment.
// Optimize it when need arises.
ConstAccessor accessor(&from);
if (accessor.getFirst()) {
if (accessor.getFirst())
{
do {
add(accessor.current());
} while (accessor.getNext());
@ -350,7 +358,8 @@ private:
}
static void setNodeParentAndLevel(void* node, const int level, NodeList* parent)
{
if (level) {
if (level)
{
((NodeList *)node)->parent = parent;
((NodeList *)node)->level = level - 1;
}
@ -389,7 +398,8 @@ public:
if (!list)
return false; // Uninitalized tree
for (int lev = tree->level; lev; lev--) {
for (int lev = tree->level; lev; lev--)
{
size_t pos;
if (!((NodeList *)list)->find(key, pos))
{
@ -406,7 +416,8 @@ public:
case locEqual:
return found;
case locGreatEqual:
if (curPos == curr->getCount()) {
if (curPos == curr->getCount())
{
curr = curr->next;
curPos = 0;
}
@ -416,7 +427,8 @@ public:
return true;
// NOTE: fall into next case statement
case locLess:
if (curPos == 0) {
if (curPos == 0)
{
curr = curr->prev;
if (!curr)
return false;
@ -428,7 +440,8 @@ public:
case locGreat:
if (found)
curPos++;
if (curPos == curr->getCount()) {
if (curPos == curr->getCount())
{
curr = curr->next;
curPos = 0;
}
@ -461,7 +474,8 @@ public:
for (int i = tree->level; i > 0; i--)
items = (*(NodeList*) items)[((NodeList*) items)->getCount() - 1];
curr = (ItemList *)items;
if (((ItemList*) items)->getCount()) {
if (((ItemList*) items)->getCount())
{
curPos = ((ItemList*) items)->getCount() - 1;
return true;
}
@ -472,12 +486,15 @@ public:
bool getNext()
{
curPos++;
if (curPos >= curr->getCount()) {
if (curr->next) {
if (curPos >= curr->getCount())
{
if (curr->next)
{
curr = curr->next;
curPos = 0;
}
else {
else
{
// If we reached end of the list just return false and do not invalidate position
curPos--;
return false;
@ -489,12 +506,15 @@ public:
// getLast() or locate() before you can call this method
bool getPrev()
{
if (curPos == 0) {
if (curr->prev) {
if (curPos == 0)
{
if (curr->prev)
{
curr = curr->prev;
curPos = curr->getCount() - 1;
}
else {
else
{
// If we reached beginning of the list just return false and do not invalidate position
curPos = 0;
return false;
@ -548,7 +568,8 @@ public:
if (this != &tree->defaultAccessor)
tree->defaultAccessor.curr = NULL;
if (!tree->level) {
if (!tree->level)
{
this->curr->remove(this->curPos);
return this->curPos < this->curr->getCount();
}
@ -558,24 +579,28 @@ public:
// because is would invalidate our tree structure
fb_assert(this->curPos == 0);
ItemList* temp;
if ((temp = this->curr->prev) && NEED_MERGE(temp->getCount(), LeafCount)) {
if ((temp = this->curr->prev) && NEED_MERGE(temp->getCount(), LeafCount))
{
temp = this->curr->next;
tree->_removePage(0, this->curr);
this->curr = temp;
return this->curr;
}
if ((temp = this->curr->next) && NEED_MERGE(temp->getCount(), LeafCount)) {
if ((temp = this->curr->next) && NEED_MERGE(temp->getCount(), LeafCount))
{
tree->_removePage(0, this->curr);
this->curr = temp;
return true;
}
if ((temp = this->curr->prev)) {
if ((temp = this->curr->prev))
{
(*this->curr)[0] = (*temp)[temp->getCount() - 1];
temp->shrink(temp->getCount() - 1);
this->curr = this->curr->next;
return this->curr;
}
if ((temp = this->curr->next)) {
if ((temp = this->curr->next))
{
(*this->curr)[0] = (*temp)[0];
temp->remove(0);
return true;
@ -586,7 +611,9 @@ public:
}
this->curr->remove(this->curPos);
ItemList *temp;
if ((temp = this->curr->prev) && NEED_MERGE(temp->getCount() + this->curr->getCount(), LeafCount)) {
if ((temp = this->curr->prev) &&
NEED_MERGE(temp->getCount() + this->curr->getCount(), LeafCount))
{
// After join upper levels of the tree remain stable because join doesn't change
// key of the page. The same applies to lower case too.
this->curPos += temp->getCount();
@ -595,14 +622,18 @@ public:
this->curr = temp;
// The code below will adjust current position if needed
}
else {
if ((temp = this->curr->next) && NEED_MERGE(temp->getCount() + this->curr->getCount(), LeafCount)) {
else
{
if ((temp = this->curr->next) &&
NEED_MERGE(temp->getCount() + this->curr->getCount(), LeafCount))
{
this->curr->join(*temp);
tree->_removePage(0, temp);
return true;
}
}
if (this->curPos >= this->curr->getCount()) {
if (this->curPos >= this->curr->getCount())
{
fb_assert(this->curPos == this->curr->getCount());
this->curPos = 0;
this->curr = this->curr->next;
@ -644,7 +675,8 @@ bool BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp>::add(const Value& item,
// Find leaf page for our item
void *vList = this->root;
const Key& key = KeyOfValue::generate(NULL, item);
for (int lev = this->level; lev > 0 ; lev--) {
for (int lev = this->level; lev > 0; lev--)
{
size_t pos;
if (!((NodeList *)vList)->find(key, pos))
{
@ -657,15 +689,18 @@ bool BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp>::add(const Value& item,
ItemList *leaf = (ItemList *)vList;
size_t pos;
if (leaf->find(key, pos)) {
if (accessor) {
if (leaf->find(key, pos))
{
if (accessor)
{
accessor->curr = leaf;
accessor->curPos = pos;
}
return false;
}
if (leaf->getCount() < LeafCount) {
if (leaf->getCount() < LeafCount)
{
leaf->insert(pos, item);
return true;
}
@ -677,12 +712,14 @@ bool BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp>::add(const Value& item,
if ((temp = leaf->next) && temp->getCount() < LeafCount)
{
// Found space on the next page
if (pos == LeafCount) {
if (pos == LeafCount)
{
// This would be ok if items were unique: temp->insert(0, item);
// The same applies to all simular cases below
temp->insert(0, item);
}
else {
else
{
// Maybe splitting array by half would make things faster ?
// It should do it in case of random size items.
// It would make things slower in case of sequental items addition.
@ -700,7 +737,8 @@ bool BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp>::add(const Value& item,
if (pos == 0) {
temp->insert(temp->getCount(), item);
}
else {
else
{
temp->insert(temp->getCount(), (*leaf)[0]);
leaf->remove(0);
leaf->insert(pos - 1, item);
@ -723,11 +761,13 @@ bool BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp>::add(const Value& item,
size_t recovery_map[MAX_TREE_LEVEL];
const size_t MAP_NEW_PAGE = ~((size_t) 0);
if (pos == LeafCount) {
if (pos == LeafCount)
{
newLeaf->insert(0, item);
recovery_map[0] = MAP_NEW_PAGE;
}
else {
else
{
newLeaf->insert(0, (*leaf)[LeafCount - 1]);
leaf->shrink(leaf->getCount() - 1);
leaf->insert(pos, item);
@ -741,7 +781,8 @@ bool BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp>::add(const Value& item,
while (nodeList)
{
// Easy case. We've got some space on the node page
if (nodeList->getCount() < NodeCount) {
if (nodeList->getCount() < NodeCount)
{
NodeList::setNodeParentAndLevel(newNode, curLevel, nodeList);
nodeList->add(newNode);
return true;
@ -751,13 +792,16 @@ bool BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp>::add(const Value& item,
nodeList->find(NodeList::generate(nodeList, newNode), pos);
NodeList *list;
if ((list = nodeList->next) && list->getCount() < NodeCount) {
if ((list = nodeList->next) && list->getCount() < NodeCount)
{
// Found space on the next page
if (pos == NodeCount) {
if (pos == NodeCount)
{
NodeList::setNodeParentAndLevel(newNode, curLevel, list);
list->insert(0, newNode);
}
else {
else
{
void *t = (*nodeList)[NodeCount - 1];
NodeList::setNodeParent(t, curLevel, list);
list->insert(0, t);
@ -768,13 +812,16 @@ bool BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp>::add(const Value& item,
return true;
}
if ((list = nodeList->prev) && list->getCount() < NodeCount) {
if ((list = nodeList->prev) && list->getCount() < NodeCount)
{
// Found space on the previous page
if (pos == 0) {
if (pos == 0)
{
NodeList::setNodeParentAndLevel(newNode, curLevel, list);
list->insert(list->getCount(), newNode);
}
else {
else
{
void *t = (*nodeList)[0];
NodeList::setNodeParent(t, curLevel, list);
list->insert(list->getCount(), t);
@ -792,12 +839,14 @@ bool BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp>::add(const Value& item,
// are cleaned up lower
NodeList *newList = new(this->pool->allocate(sizeof(NodeList))) NodeList(nodeList);
if (pos == NodeCount) {
if (pos == NodeCount)
{
NodeList::setNodeParentAndLevel(newNode, curLevel, newList);
newList->insert(0, newNode);
recovery_map[curLevel + 1] = MAP_NEW_PAGE;
}
else {
else
{
void *t = (*nodeList)[NodeCount - 1];
NodeList::setNodeParent(t, curLevel, newList);
newList->insert(0, t);
@ -832,7 +881,8 @@ bool BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp>::add(const Value& item,
if (recovery_map[curLevel] == MAP_NEW_PAGE) {
lower = (*itemL)[0];
}
else {
else
{
lower = (*itemL->prev)[recovery_map[curLevel]];
itemL->prev->remove(recovery_map[curLevel]);
itemL->prev->insert(itemL->prev->getCount(), (*itemL)[0]);
@ -844,7 +894,8 @@ bool BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp>::add(const Value& item,
curLevel--;
}
ItemList *itemL2 = reinterpret_cast<ItemList*>(newNode);
if (recovery_map[0] != MAP_NEW_PAGE) {
if (recovery_map[0] != MAP_NEW_PAGE)
{
itemL2->prev->remove(recovery_map[0]);
itemL2->prev->insert(itemL2->prev->getCount(), (*itemL2)[0]);
}
@ -860,7 +911,8 @@ void BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp>::_removePage(const int n
{
NodeList *list;
// Get parent and adjust the links
if (nodeLevel) {
if (nodeLevel)
{
NodeList *temp = (NodeList *)node;
if (temp->prev)
temp->prev->next = temp->next;
@ -868,7 +920,8 @@ void BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp>::_removePage(const int n
temp->next->prev = temp->prev;
list = temp->parent;
}
else {
else
{
ItemList *temp = (ItemList *)node;
if (temp->prev)
temp->prev->next = temp->next;
@ -890,12 +943,14 @@ void BePlusTree<Value, Key, Allocator, KeyOfValue, Cmp>::_removePage(const int n
_removePage(nodeLevel + 1, list);
}
else
if ((temp = list->prev)) {
if ((temp = list->prev))
{
NodeList::setNodeParent(((*list)[0] = (*temp)[temp->getCount() - 1]), nodeLevel, list);
temp->shrink(temp->getCount() - 1);
}
else
if ((temp = list->next)) {
if ((temp = list->next))
{
NodeList::setNodeParent(((*list)[0] = (*temp)[0]), nodeLevel, list);
temp->remove(0);
}

View File

@ -1462,7 +1462,7 @@ table_constraint_definition : constraint_name_opt table_constraint
constraint_name_opt : CONSTRAINT symbol_constraint_name
{ $$ = $2; }
|
{ $$ = NULL ;}
{ $$ = NULL; }
;
table_constraint : unique_constraint
@ -2905,8 +2905,8 @@ character_keyword : CHARACTER
national_character_keyword : NCHAR
| NATIONAL CHARACTER
| NATIONAL KW_CHAR
;
| NATIONAL KW_CHAR
;
@ -3231,7 +3231,7 @@ tbl_reserve_options: RESERVING restr_list
lock_type : KW_SHARED
{ $$ = (dsql_nod*) NOD_SHARED; }
| PROTECTED
{ $$ = (dsql_nod*) NOD_PROTECTED ; }
{ $$ = (dsql_nod*) NOD_PROTECTED; }
|
{ $$ = (dsql_nod*) 0; }
;
@ -5928,7 +5928,7 @@ int Parser::yylexAux()
FB_UINT64 number = 0;
FB_UINT64 limit_by_10 = MAX_SINT64 / 10;
for (--lex.ptr ; lex.ptr < lex.end ; lex.ptr++)
for (--lex.ptr ; lex.ptr < lex.end; lex.ptr++)
{
c = *lex.ptr;
if (have_exp_digit && (! (classes(c) & CHR_DIGIT)))

View File

@ -718,7 +718,7 @@ static void gen_based( const act* action, int column)
default:
sprintf(s2, "datatype %d unknown\n", field->fld_dtype);
return ;
return;
}
for (p = s2; *p; p++, q++)

View File

@ -78,7 +78,8 @@ void Manager::init()
void Manager::addProvider(Provider* provider)
{
for (const Provider* prv = m_providers; prv; prv = prv->m_next) {
for (const Provider* prv = m_providers; prv; prv = prv->m_next)
{
if (prv->m_name == provider->m_name) {
return;
}
@ -91,7 +92,8 @@ void Manager::addProvider(Provider* provider)
Provider* Manager::getProvider(const string& prvName)
{
for (Provider* prv = m_providers; prv; prv = prv->m_next) {
for (Provider* prv = m_providers; prv; prv = prv->m_next)
{
if (prv->m_name == prvName) {
return prv;
}
@ -572,13 +574,13 @@ void Transaction::start(thread_db* tdbb, TraScope traScope, TraModes traMode,
jrd_tra* tran = tdbb->getTransaction();
switch (m_scope)
{
case traCommon :
case traCommon:
this->m_nextTran = tran->tra_ext_common;
this->m_jrdTran = tran;
tran->tra_ext_common = this;
break;
case traTwoPhase :
case traTwoPhase:
// join transaction
// this->m_jrdTran = tran;
// tran->tra_ext_two_phase = ext_tran;
@ -639,7 +641,8 @@ Transaction* Transaction::getTransaction(thread_db* tdbb, Connection* conn, TraS
ext_tran = conn->createTransaction();
TraModes traMode = traConcurrency;
if (tran->tra_flags & TRA_read_committed) {
if (tran->tra_flags & TRA_read_committed)
{
if (tran->tra_flags & TRA_rec_version)
traMode = traReadCommitedRecVersions;
else
@ -883,7 +886,8 @@ void Statement::close(thread_db* tdbb)
if (m_transaction && m_transaction->getScope() == traAutonomous)
{
bool commitFailed = false;
if (!m_error) {
if (!m_error)
{
try {
m_transaction->commit(tdbb, false);
}
@ -898,7 +902,8 @@ void Statement::close(thread_db* tdbb)
}
}
if (m_error || commitFailed) {
if (m_error || commitFailed)
{
try {
m_transaction->rollback(tdbb, false);
}
@ -924,7 +929,8 @@ void Statement::close(thread_db* tdbb)
void Statement::deallocate(thread_db* tdbb)
{
if (isAllocated()) {
if (isAllocated())
{
try {
doClose(tdbb, true);
}
@ -955,7 +961,8 @@ static TokenType getToken(const char** begin, const char* end)
case '"':
while (p < end)
{
if (*p++ == c) {
if (*p++ == c)
{
ret = ttString;
break;
}
@ -967,8 +974,10 @@ static TokenType getToken(const char** begin, const char* end)
{
ret = ttBrokenComment;
p++;
while (p < end) {
if (*p++ == '*' && p < end && *p == '/') {
while (p < end)
{
if (*p++ == '*' && p < end && *p == '/')
{
p++;
ret = ttComment;
break;
@ -981,9 +990,12 @@ static TokenType getToken(const char** begin, const char* end)
break;
case '-':
if (p < end && *p == '-') {
while (p < end) {
if (*p++ == '\n') {
if (p < end && *p == '-')
{
while (p < end)
{
if (*p++ == '\n')
{
p--;
ret = ttComment;
break;
@ -1044,7 +1056,8 @@ void Statement::preprocess(const string& sql, string& ret)
tok = getToken(&p, end);
}
if (p >= end || tok != ttIdent) {
if (p >= end || tok != ttIdent)
{
// Execute statement preprocess SQL error
// Statement expected
ERR_post(Arg::Gds(isc_eds_preprocess) <<
@ -1064,7 +1077,8 @@ void Statement::preprocess(const string& sql, string& ret)
i2 = p;
tok = getToken(&p, end);
}
if (p >= end || tok != ttIdent) {
if (p >= end || tok != ttIdent)
{
// Execute statement preprocess SQL error
// Statement expected
ERR_post(Arg::Gds(isc_eds_preprocess) <<
@ -1118,7 +1132,8 @@ void Statement::preprocess(const string& sql, string& ret)
}
m_sqlParamsMap.add(m_sqlParamNames[n]);
}
else {
else
{
// Execute statement preprocess SQL error
// Parameter name expected
ERR_post(Arg::Gds(isc_eds_preprocess) <<
@ -1172,7 +1187,8 @@ void Statement::setInParams(thread_db* tdbb, int count, const string* const* nam
m_error = (names && ((int) m_sqlParamNames.getCount() != count || !count)) ||
(!names && m_sqlParamNames.getCount());
if (m_error) {
if (m_error)
{
// Input parameters mismatch
status_exception::raise(Arg::Gds(isc_eds_input_prm_mismatch));
}
@ -1500,7 +1516,8 @@ void EngineCallbackGuard::init(thread_db* tdbb, Connection& conn)
m_tdbb->getTransaction()->tra_callback_count++;
}
if (m_tdbb->getAttachment()) {
if (m_tdbb->getAttachment())
{
fb_assert(!m_tdbb->getAttachment()->att_ext_connection);
m_tdbb->getAttachment()->att_ext_connection = &conn;
}

View File

@ -1858,7 +1858,7 @@ void TracePluginImpl::log_event_trigger_execute(TraceConnection* connection, Tra
{
case res_successful:
event_type = started ? "EXECUTE_TRIGGER_START" :
"EXECUTE_TRIGGER_FINISH" ;
"EXECUTE_TRIGGER_FINISH";
break;
case res_failed:
event_type = started ? "FAILED EXECUTE_TRIGGER_START" :