@@ -126,6 +126,7 @@ static void save_trigger_data(thread_db*, TrigVector**, jrd_rel*, JrdStatement*,
126126 const TEXT*, FB_UINT64, SSHORT, USHORT, const MetaName&, const string&,
127127 const bid*, Nullable<bool> ssDefiner);
128128static void scan_partners(thread_db*, jrd_rel*);
129+ static void scan_relation(thread_db*, jrd_rel*);
129130static void store_dependencies(thread_db*, CompilerScratch*, const jrd_rel*,
130131 const MetaName&, int, jrd_tra*);
131132static bool verify_TRG_ignore_perm(thread_db*, const MetaName&);
@@ -3892,6 +3893,27 @@ void MET_scan_relation(thread_db* tdbb, jrd_rel* relation)
38923893 * Scan a relation for view RecordSelExpr, computed by expressions, missing
38933894 * expressions, and validation expressions.
38943895 *
3896+ **************************************/
3897+
3898+ while (!(relation->rel_flags & (REL_scanned | REL_deleted)))
3899+ {
3900+ scan_relation(tdbb, relation);
3901+ }
3902+ }
3903+
3904+
3905+ static void scan_relation(thread_db* tdbb, jrd_rel* relation)
3906+ {
3907+ /**************************************
3908+ *
3909+ * s c a n _ r e l a t i o n
3910+ *
3911+ **************************************
3912+ *
3913+ * Functional description
3914+ * Scan a relation for view RecordSelExpr, computed by expressions, missing
3915+ * expressions, and validation expressions.
3916+ *
38953917 **************************************/
38963918 SET_TDBB(tdbb);
38973919 TrigVector* triggers[TRIGGER_MAX];
@@ -3915,6 +3937,10 @@ void MET_scan_relation(thread_db* tdbb, jrd_rel* relation)
39153937 return;
39163938
39173939 relation->rel_flags |= REL_being_scanned;
3940+
3941+ LCK_lock(tdbb, relation->rel_rescan_lock, LCK_SR, LCK_WAIT);
3942+ relation->rel_flags &= ~REL_rescan;
3943+
39183944 dependencies = (relation->rel_flags & REL_get_dependencies) ? true : false;
39193945 sys_triggers = (relation->rel_flags & REL_sys_triggers) ? true : false;
39203946 relation->rel_flags &= ~(REL_get_dependencies | REL_sys_triggers);
@@ -4217,9 +4243,14 @@ void MET_scan_relation(thread_db* tdbb, jrd_rel* relation)
42174243 relation->replaceTriggers(tdbb, triggers);
42184244 }
42194245
4220- LCK_lock(tdbb, relation->rel_rescan_lock, LCK_SR, LCK_WAIT);
42214246 relation->rel_flags &= ~REL_being_scanned;
42224247
4248+ if (relation->rel_flags & REL_rescan)
4249+ {
4250+ LCK_release(tdbb, relation->rel_rescan_lock);
4251+ relation->rel_flags &= ~(REL_scanned | REL_rescan);
4252+ }
4253+
42234254 relation->rel_current_format = NULL;
42244255
42254256 } // try
@@ -4526,8 +4557,13 @@ static int rescan_ast_relation(void* ast_object)
45264557
45274558 AsyncContextHolder tdbb(dbb, FB_FUNCTION, relation->rel_rescan_lock);
45284559
4529- LCK_release(tdbb, relation->rel_rescan_lock);
4530- relation->rel_flags &= ~REL_scanned;
4560+ if (relation->rel_flags & REL_being_scanned)
4561+ relation->rel_flags |= REL_rescan;
4562+ else
4563+ {
4564+ LCK_release(tdbb, relation->rel_rescan_lock);
4565+ relation->rel_flags &= ~REL_scanned;
4566+ }
45314567 }
45324568 catch (const Firebird::Exception&)
45334569 {} // no-op
0 commit comments