Skip to content

Commit c62f060

Browse files
committed
Fixed DROP INDEX on temporary per-transaction table
1 parent ae6b497 commit c62f060

5 files changed

Lines changed: 18 additions & 50 deletions

File tree

src/dsql/DdlNodes.epp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12524,6 +12524,7 @@ void ModifyIndexNode::modify(thread_db* tdbb, jrd_tra* transaction)
1252412524
SET_TDBB(tdbb);
1252512525

1252612526
fb_assert(indexRelation);
12527+
indexRelation->fillPages(tdbb);
1252712528

1252812529
if (create)
1252912530
step2(tdbb, transaction);
@@ -13927,6 +13928,7 @@ void AlterIndexNode::step2(thread_db* tdbb, jrd_tra* transaction)
1392713928
{
1392813929
// One way or another the index was just created, finalize it
1392913930
StoreIndexNode storeNode(indexName, indexRelation, expressionIndex);
13931+
fb_assert(indexRelation->getBasePages()->rel_index_root);
1393013932
storeNode.step2(tdbb, transaction);
1393113933
return;
1393213934
}
@@ -14278,12 +14280,8 @@ void DropIndexNode::step2(thread_db* tdbb, jrd_tra* transaction)
1427814280

1427914281
fb_assert(idxId >= 0 && idxId < dbb->dbb_max_idx);
1428014282

14281-
RelationPages* relPages = indexRelation->getPages(tdbb, MAX_TRA_NUMBER, false);
14282-
if (relPages)
14283-
{
14284-
IDX_mark_index(tdbb, indexRelation, idxId);
14283+
if (IDX_mark_index(tdbb, indexRelation, idxId))
1428514284
indexRelation->eraseIndex(tdbb, idxId);
14286-
}
1428714285
}
1428814286

1428914287

src/jrd/Relation.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,12 @@ bool RelationPermanent::isReplicating(thread_db* tdbb)
276276
return oldState == Bool3State::True;
277277
}
278278

279-
RelationPages* RelationPermanent::fillPages(thread_db* tdbb)
279+
void RelationPermanent::fillPages(thread_db* tdbb)
280280
{
281281
if (!rel_pages_base.rel_index_root)
282282
DPM_scan_pages(tdbb);
283283

284284
fb_assert(rel_pages_base.rel_index_root);
285-
return &rel_pages_base;
286285
}
287286

288287
RelationPages* RelationPermanent::getPagesInternal(thread_db* tdbb, TraNumber tran, bool allocPages)

src/jrd/Relation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ class RelationPermanent : public Firebird::PermanentStorage
906906
};
907907

908908
RelationPages* getPages(thread_db* tdbb, TraNumber tran = MAX_TRA_NUMBER, bool allocPages = true);
909-
RelationPages* fillPages(thread_db* tdbb);
909+
void fillPages(thread_db* tdbb);
910910
RelationPages* getAttPages(thread_db* tdbb, RelationPages::InstanceId inst_id);
911911
bool delPages(thread_db* tdbb, TraNumber tran = MAX_TRA_NUMBER, RelationPages* aPages = NULL);
912912
void freePages(thread_db* tdbb);

src/jrd/idx.cpp

Lines changed: 12 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ bool IDX_activate_index(thread_db* tdbb, Cached::Relation* relation, MetaId id)
978978
}
979979

980980

981-
void IDX_mark_index(thread_db* tdbb, Cached::Relation* relation, MetaId id)
981+
bool IDX_mark_index(thread_db* tdbb, Cached::Relation* relation, MetaId id)
982982
{
983983
/**************************************
984984
*
@@ -992,13 +992,19 @@ void IDX_mark_index(thread_db* tdbb, Cached::Relation* relation, MetaId id)
992992
**************************************/
993993
SET_TDBB(tdbb);
994994

995-
auto* relPages = relation->fillPages(tdbb);
996-
fb_assert(relPages->rel_index_root);
995+
auto* relPages = relation->getPages(tdbb, MAX_TRA_NUMBER, false);
996+
if (relPages)
997+
{
998+
fb_assert(relPages->rel_index_root);
997999

998-
WIN window(relPages->rel_pg_space_id, relPages->rel_index_root);
999-
index_root_page* root = BTR_fetch_root_for_update(FB_FUNCTION, tdbb, &window);
1000+
WIN window(relPages->rel_pg_space_id, relPages->rel_index_root);
1001+
index_root_page* root = BTR_fetch_root_for_update(FB_FUNCTION, tdbb, &window);
10001002

1001-
BTR_mark_index_for_delete(tdbb, relation, id, &window, root, 0);
1003+
BTR_mark_index_for_delete(tdbb, relation, id, &window, root, 0);
1004+
return true;
1005+
}
1006+
1007+
return false;
10021008
}
10031009

10041010
void IDX_mark_temp(thread_db* tdbb, RelationPermanent* relation, MetaId id, Attachment* current, TraNumber tran)
@@ -1087,40 +1093,6 @@ void IDX_delete_indices(thread_db* tdbb, RelationPermanent* relation, RelationPa
10871093
}
10881094

10891095

1090-
void IDX_mark_indices(thread_db* tdbb, Cached::Relation* relation)
1091-
{
1092-
/**************************************
1093-
*
1094-
* I D X _ m a r k _ i n d i c e s
1095-
*
1096-
**************************************
1097-
*
1098-
* Functional description
1099-
* Mark all known indices for delete in preparation for deleting a
1100-
* complete relation.
1101-
*
1102-
**************************************/
1103-
SET_TDBB(tdbb);
1104-
1105-
auto* relPages = relation->fillPages(tdbb);
1106-
fb_assert(relPages->rel_index_root);
1107-
1108-
WIN window(relPages->rel_pg_space_id, relPages->rel_index_root);
1109-
index_root_page* root = BTR_fetch_root_for_update(FB_FUNCTION, tdbb, &window);
1110-
1111-
// loop through pagespaces and mark for delete %%%%%%
1112-
// if ((relation->rel_flags & REL_temp_conn) && (relPages->rel_instance_id != 0))
1113-
1114-
for (USHORT i = 0; i < root->irt_count; i++)
1115-
{
1116-
BTR_mark_index_for_delete(tdbb, relation, i, &window, root, 0);
1117-
root = BTR_fetch_root_for_update(FB_FUNCTION, tdbb, &window);
1118-
}
1119-
1120-
CCH_RELEASE(tdbb, &window);
1121-
}
1122-
1123-
11241096
void IDX_erase(thread_db* tdbb, record_param* rpb, jrd_tra* transaction)
11251097
{
11261098
/**************************************

src/jrd/idx_proto.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,10 @@ void IDX_check_access(Jrd::thread_db*, Jrd::CompilerScratch*, Jrd::Cached::Relat
4343
bool IDX_check_master_types (Jrd::thread_db*, Jrd::index_desc&, Jrd::Cached::Relation*, int&);
4444
void IDX_create_index(Jrd::thread_db*, Jrd::IdxCreate createMethod, Jrd::jrd_rel*, Jrd::index_desc*,
4545
const Jrd::QualifiedName&, USHORT*, Jrd::jrd_tra*, Jrd::SelectivityList&);
46-
void IDX_mark_index(Jrd::thread_db*, Jrd::Cached::Relation*, MetaId);
46+
bool IDX_mark_index(Jrd::thread_db*, Jrd::Cached::Relation*, MetaId);
4747
void IDX_mark_temp(Jrd::thread_db* tdbb, Jrd::RelationPermanent* relation, MetaId id, Jrd::Attachment* current,
4848
TraNumber tran);
4949
void IDX_delete_indices(Jrd::thread_db*, Jrd::RelationPermanent*, Jrd::RelationPages*, bool);
50-
void IDX_mark_indices(Jrd::thread_db*, Jrd::Cached::Relation*);
5150
void IDX_erase(Jrd::thread_db*, Jrd::record_param*, Jrd::jrd_tra*);
5251
void IDX_garbage_collect(Jrd::thread_db*, Jrd::record_param*, Jrd::RecordStack&, Jrd::RecordStack&);
5352
void IDX_modify(Jrd::thread_db*, Jrd::record_param*, Jrd::record_param*, Jrd::jrd_tra*);

0 commit comments

Comments
 (0)