Skip to content

Commit 06d1879

Browse files
committed
Some checks for object in use when doing DDL changes in LTTs
Problems reported by Pavel Zotov
1 parent 3a5a61b commit 06d1879

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

src/dsql/DdlNodes.epp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ using namespace Firebird;
7777

7878
static void checkForeignKeyTempScope(thread_db* tdbb, jrd_tra* transaction,
7979
const QualifiedName& childRelName, const QualifiedName& masterIndexName);
80+
static void checkLttNotInUse(thread_db* tdbb, jrd_tra* transaction, const LocalTemporaryTable* ltt);
8081
static void checkSpTrigDependency(thread_db* tdbb, jrd_tra* transaction,
8182
const QualifiedName& relationName, const MetaName& fieldName);
8283
static void checkViewDependency(thread_db* tdbb, jrd_tra* transaction,
@@ -221,6 +222,32 @@ static void checkForeignKeyTempScope(thread_db* tdbb, jrd_tra* transaction,
221222
}
222223
}
223224

225+
static void checkLttNotInUse(thread_db* tdbb, jrd_tra* transaction, const LocalTemporaryTable* ltt)
226+
{
227+
if (!ltt || !ltt->relation)
228+
return;
229+
230+
const auto attachment = transaction->tra_attachment;
231+
const Resource resource(Resource::rsc_relation, ltt->relation->rel_id,
232+
ltt->relation, nullptr, nullptr);
233+
234+
for (const auto* otherTransaction = attachment->att_transactions;
235+
otherTransaction;
236+
otherTransaction = otherTransaction->tra_next)
237+
{
238+
if (otherTransaction == transaction)
239+
continue;
240+
241+
if (otherTransaction->tra_resources.exist(resource))
242+
{
243+
string obj;
244+
obj.printf("TABLE %s", ltt->name.toQuotedString().c_str());
245+
246+
status_exception::raise(Arg::Gds(isc_no_meta_update) << Arg::Gds(isc_obj_in_use) << obj);
247+
}
248+
}
249+
}
250+
224251
// Check temporary table reference rules between just created child relation and all
225252
// its master relations.
226253
static void checkRelationTempScope(thread_db* tdbb, jrd_tra* transaction,
@@ -9197,6 +9224,7 @@ void AlterRelationNode::alterLocalTempTable(thread_db* tdbb, DsqlCompilerScratch
91979224
}
91989225

91999226
const auto ltt = *lttPtr;
9227+
checkLttNotInUse(tdbb, transaction, ltt);
92009228

92019229
// Run all statements under savepoint control
92029230
AutoSavePoint savePoint(tdbb, transaction);
@@ -9581,6 +9609,7 @@ void DropRelationNode::execute(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch
95819609
}
95829610

95839611
const auto ltt = *lttIt;
9612+
checkLttNotInUse(tdbb, transaction, ltt);
95849613

95859614
// Post deferred work to handle the LTT deletion at commit time
95869615
DFW_post_work(transaction, dfw_delete_relation,
@@ -11172,6 +11201,8 @@ void CreateIndexNode::defineLocalTempIndex(thread_db* tdbb, DsqlCompilerScratch*
1117211201
const auto attachment = transaction->tra_attachment;
1117311202
auto& attPool = *attachment->att_pool;
1117411203

11204+
checkLttNotInUse(tdbb, transaction, ltt);
11205+
1117511206
if (computed)
1117611207
{
1117711208
status_exception::raise(
@@ -11369,6 +11400,8 @@ void AlterIndexNode::alterLocalTempIndex(thread_db* tdbb, DsqlCompilerScratch* d
1136911400
const auto attachment = transaction->tra_attachment;
1137011401
auto& attPool = *attachment->att_pool;
1137111402

11403+
checkLttNotInUse(tdbb, transaction, ltt);
11404+
1137211405
// Register undo action with the savepoint
1137311406
transaction->tra_save_point->createLttAction(
1137411407
LttUndoItem::LTT_UNDO_ALTER, ltt->name, FB_NEW_POOL(attPool) LocalTemporaryTable(attPool, *ltt));
@@ -11470,6 +11503,8 @@ void SetStatisticsNode::setStatisticsLocalTempIndex(thread_db* tdbb, DsqlCompile
1147011503
{
1147111504
const auto attachment = transaction->tra_attachment;
1147211505

11506+
checkLttNotInUse(tdbb, transaction, ltt);
11507+
1147311508
// Register undo action with the savepoint
1147411509
transaction->tra_save_point->createLttAction(
1147511510
LttUndoItem::LTT_UNDO_ALTER, ltt->name, FB_NEW_POOL(*attachment->att_pool) LocalTemporaryTable(*attachment->att_pool, *ltt));
@@ -11581,6 +11616,8 @@ void DropIndexNode::dropLocalTempIndex(thread_db* tdbb, DsqlCompilerScratch* dsq
1158111616
Attachment* const attachment = transaction->tra_attachment;
1158211617
auto& attPool = *attachment->att_pool;
1158311618

11619+
checkLttNotInUse(tdbb, transaction, ltt);
11620+
1158411621
// Register undo action with the savepoint
1158511622
transaction->tra_save_point->createLttAction(
1158611623
LttUndoItem::LTT_UNDO_ALTER, ltt->name, FB_NEW_POOL(attPool) LocalTemporaryTable(attPool, *ltt));

0 commit comments

Comments
 (0)