@@ -127,6 +127,7 @@ static void save_trigger_data(thread_db*, TrigVector**, jrd_rel*, Statement*, bl
127127 const QualifiedName*, FB_UINT64, SSHORT, USHORT, const MetaName&, const string&,
128128 const bid*, TriState ssDefiner);
129129static void scan_partners(thread_db*, jrd_rel*);
130+ static void scan_relation(thread_db*, jrd_rel*);
130131static bool verify_TRG_ignore_perm(thread_db*, const QualifiedName&);
131132
132133
@@ -3917,6 +3918,27 @@ void MET_scan_relation(thread_db* tdbb, jrd_rel* relation)
39173918 * Scan a relation for view RecordSelExpr, computed by expressions, missing
39183919 * expressions, and validation expressions.
39193920 *
3921+ **************************************/
3922+
3923+ while (!(relation->rel_flags & (REL_scanned | REL_deleted)))
3924+ {
3925+ scan_relation(tdbb, relation);
3926+ }
3927+ }
3928+
3929+
3930+ static void scan_relation(thread_db* tdbb, jrd_rel* relation)
3931+ {
3932+ /**************************************
3933+ *
3934+ * s c a n _ r e l a t i o n
3935+ *
3936+ **************************************
3937+ *
3938+ * Functional description
3939+ * Scan a relation for view RecordSelExpr, computed by expressions, missing
3940+ * expressions, and validation expressions.
3941+ *
39203942 **************************************/
39213943 SET_TDBB(tdbb);
39223944 TrigVector* triggers[TRIGGER_MAX];
@@ -3935,10 +3957,13 @@ void MET_scan_relation(thread_db* tdbb, jrd_rel* relation)
39353957
39363958 try {
39373959
3938- if (relation->rel_flags & (REL_scanned | REL_deleted))
3939- return;
3960+ fb_assert(!(relation->rel_flags & (REL_scanned | REL_deleted)));
39403961
39413962 relation->rel_flags |= REL_being_scanned;
3963+
3964+ LCK_lock(tdbb, relation->rel_rescan_lock, LCK_SR, LCK_WAIT);
3965+ relation->rel_flags &= ~REL_rescan;
3966+
39423967 dependencies = (relation->rel_flags & REL_get_dependencies) ? true : false;
39433968 relation->rel_flags &= ~REL_get_dependencies;
39443969
@@ -4232,9 +4257,14 @@ void MET_scan_relation(thread_db* tdbb, jrd_rel* relation)
42324257 // It's now time to place them at their rightful place inside the relation block.
42334258 relation->replaceTriggers(tdbb, triggers);
42344259
4235- LCK_lock(tdbb, relation->rel_rescan_lock, LCK_SR, LCK_WAIT);
42364260 relation->rel_flags &= ~REL_being_scanned;
42374261
4262+ if (relation->rel_flags & REL_rescan)
4263+ {
4264+ LCK_release(tdbb, relation->rel_rescan_lock);
4265+ relation->rel_flags &= ~(REL_scanned | REL_rescan);
4266+ }
4267+
42384268 relation->rel_current_format = NULL;
42394269
42404270 } // try
@@ -4542,8 +4572,13 @@ static int rescan_ast_relation(void* ast_object)
45424572
45434573 AsyncContextHolder tdbb(dbb, FB_FUNCTION, relation->rel_rescan_lock);
45444574
4545- LCK_release(tdbb, relation->rel_rescan_lock);
4546- relation->rel_flags &= ~REL_scanned;
4575+ if (relation->rel_flags & REL_being_scanned)
4576+ relation->rel_flags |= REL_rescan;
4577+ else
4578+ {
4579+ LCK_release(tdbb, relation->rel_rescan_lock);
4580+ relation->rel_flags &= ~REL_scanned;
4581+ }
45474582 }
45484583 catch (const Firebird::Exception&)
45494584 {} // no-op
0 commit comments