Skip to content

Commit e87fbe9

Browse files
committed
Fix #8968 - Incorrect check of the limit on the number of local temporary tables
1 parent b5b5b0e commit e87fbe9

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

src/dsql/DdlNodes.epp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9464,6 +9464,13 @@ void CreateRelationNode::defineLocalTempTable(thread_db* tdbb, DsqlCompilerScrat
94649464
if (externalFile)
94659465
status_exception::raise(Arg::Gds(isc_random) << "External file is not allowed for local temporary tables");
94669466

9467+
if (attachment->att_local_temporary_tables.count() >= MAX_LTT_COUNT)
9468+
{
9469+
ERR_post(Arg::Gds(isc_imp_exc) <<
9470+
Arg::Gds(isc_random) <<
9471+
Arg::Str("Too many local temporary tables exist already"));
9472+
}
9473+
94679474
const auto ltt = FB_NEW_POOL(attPool) LocalTemporaryTable(attPool, name);
94689475
ltt->relationType = tempRowsFlag.value_or(REL_temp_tran) == REL_temp_tran ? rel_temp_delete : rel_temp_preserve;
94699476

@@ -9535,25 +9542,21 @@ void CreateRelationNode::defineLocalTempTable(thread_db* tdbb, DsqlCompilerScrat
95359542
// Assign LTT relation ID
95369543

95379544
if (!attachment->att_next_ltt_id.has_value())
9538-
attachment->att_next_ltt_id = MIN_LTT_ID;
9539-
else
9540-
{
9541-
if (attachment->att_next_ltt_id.value() >= MAX_LTT_ID)
9542-
attachment->att_next_ltt_id = MIN_LTT_ID;
9543-
else
9544-
++attachment->att_next_ltt_id.value();
9545-
}
9545+
attachment->att_next_ltt_id = MAX_LTT_ID;
95469546

9547-
const USHORT initialLttIdProbe = attachment->att_next_ltt_id.value();
9547+
const auto startLttId = attachment->att_next_ltt_id.value();
95489548

9549-
while (MetadataCache::getVersioned<Cached::Relation>(tdbb, attachment->att_next_ltt_id.value(), CacheFlag::ERASED))
9549+
while (true)
95509550
{
95519551
if (attachment->att_next_ltt_id.value() >= MAX_LTT_ID)
95529552
attachment->att_next_ltt_id = MIN_LTT_ID;
95539553
else
95549554
++attachment->att_next_ltt_id.value();
95559555

9556-
if (attachment->att_next_ltt_id.value() == initialLttIdProbe)
9556+
if (!MetadataCache::getVersioned<Cached::Relation>(tdbb, attachment->att_next_ltt_id.value(), CacheFlag::ERASED))
9557+
break;
9558+
9559+
if (attachment->att_next_ltt_id.value() == startLttId)
95579560
{
95589561
ERR_post(Arg::Gds(isc_imp_exc) <<
95599562
Arg::Gds(isc_random) <<

0 commit comments

Comments
 (0)