@@ -126,6 +126,7 @@ static void save_trigger_data(thread_db*, TrigVector**, jrd_rel*, JrdStatement*,
126126 const TEXT*, FB_UINT64, bool, USHORT, const MetaName&, const string&,
127127 const bid*);
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&);
@@ -3800,6 +3801,27 @@ void MET_scan_relation(thread_db* tdbb, jrd_rel* relation)
38003801 * Scan a relation for view RecordSelExpr, computed by expressions, missing
38013802 * expressions, and validation expressions.
38023803 *
3804+ **************************************/
3805+
3806+ while (!(relation->rel_flags & (REL_scanned | REL_deleted)))
3807+ {
3808+ scan_relation(tdbb, relation);
3809+ }
3810+ }
3811+
3812+
3813+ static void scan_relation(thread_db* tdbb, jrd_rel* relation)
3814+ {
3815+ /**************************************
3816+ *
3817+ * s c a n _ r e l a t i o n
3818+ *
3819+ **************************************
3820+ *
3821+ * Functional description
3822+ * Scan a relation for view RecordSelExpr, computed by expressions, missing
3823+ * expressions, and validation expressions.
3824+ *
38033825 **************************************/
38043826 SET_TDBB(tdbb);
38053827 TrigVector* triggers[TRIGGER_MAX];
@@ -3819,10 +3841,13 @@ void MET_scan_relation(thread_db* tdbb, jrd_rel* relation)
38193841
38203842 try {
38213843
3822- if (relation->rel_flags & (REL_scanned | REL_deleted))
3823- return;
3844+ fb_assert(!(relation->rel_flags & (REL_scanned | REL_deleted)));
38243845
38253846 relation->rel_flags |= REL_being_scanned;
3847+
3848+ LCK_lock(tdbb, relation->rel_rescan_lock, LCK_SR, LCK_WAIT);
3849+ relation->rel_flags &= ~REL_rescan;
3850+
38263851 dependencies = (relation->rel_flags & REL_get_dependencies) ? true : false;
38273852 sys_triggers = (relation->rel_flags & REL_sys_triggers) ? true : false;
38283853 relation->rel_flags &= ~(REL_get_dependencies | REL_sys_triggers);
@@ -4128,9 +4153,14 @@ void MET_scan_relation(thread_db* tdbb, jrd_rel* relation)
41284153 MET_release_triggers(tdbb, &tmp_vector);
41294154 }
41304155
4131- LCK_lock(tdbb, relation->rel_rescan_lock, LCK_SR, LCK_WAIT);
41324156 relation->rel_flags &= ~REL_being_scanned;
41334157
4158+ if (relation->rel_flags & REL_rescan)
4159+ {
4160+ LCK_release(tdbb, relation->rel_rescan_lock);
4161+ relation->rel_flags &= ~(REL_scanned | REL_rescan);
4162+ }
4163+
41344164 relation->rel_current_format = NULL;
41354165
41364166 } // try
@@ -4424,8 +4454,13 @@ static int rescan_ast_relation(void* ast_object)
44244454
44254455 AsyncContextHolder tdbb(dbb, FB_FUNCTION, relation->rel_rescan_lock);
44264456
4427- LCK_release(tdbb, relation->rel_rescan_lock);
4428- relation->rel_flags &= ~REL_scanned;
4457+ if (relation->rel_flags & REL_being_scanned)
4458+ relation->rel_flags |= REL_rescan;
4459+ else
4460+ {
4461+ LCK_release(tdbb, relation->rel_rescan_lock);
4462+ relation->rel_flags &= ~REL_scanned;
4463+ }
44294464 }
44304465 catch (const Firebird::Exception&)
44314466 {} // no-op
0 commit comments