protected sealed override int CompleteTileCore(TileInfo tileInfo)
        {
            IEnvelope tileEnvelope = tileInfo.CurrentEnvelope;

            IEnvelope testRunEnvelope = tileInfo.AllBox;

            return(tileEnvelope == null
                                       ? NoError
                                       : CrossTileFeatureState.ReportErrors(ReportErrors,
                                                                            tileEnvelope,
                                                                            testRunEnvelope));
        }
        protected sealed override int ExecuteCore(IRow row, int tableIndex)
        {
            if (_queryFilter == null)
            {
                InitFilter();
                Assert.NotNull(_queryFilter, "_queryFilter");
            }

            if (_relevantRelationCondition == null)
            {
                _relevantRelationCondition =
                    new RelevantRelationCondition(_relevantRelationConditionSql,
                                                  GetSqlCaseSensitivity());
            }

            if (tableIndex >= _firstOtherClassIndex)
            {
                // it's a row from the other feature classes, ignore
                return(NoError);
            }

            var feature = (IFeature)row;

            if (CrossTileFeatureState.IsFeatureKnownOK(tableIndex, feature.OID))
            {
                return(NoError);
            }

            IGeometry shape = feature.Shape;

            bool      searchGeometryIsExpanded;
            IGeometry searchGeometry = GetSearchGeometry(feature, tableIndex,
                                                         out searchGeometryIsExpanded);

            var anyRelated = false;

            if (searchGeometry != null && !searchGeometry.IsEmpty)
            {
                for (int relatedTableIndex = _firstOtherClassIndex;
                     relatedTableIndex < _totalClassesCount;
                     relatedTableIndex++)
                {
                    foreach (IFeature relatedFeature in
                             GetRelatedFeatures(searchGeometry, relatedTableIndex,
                                                feature.Shape))
                    {
                        if (relatedFeature == feature)
                        {
                            continue;                             // same feature instance
                        }

                        if (relatedFeature.OID == feature.OID &&
                            relatedFeature.Table == feature.Table)
                        {
                            continue;                             // same feature
                        }

                        if (!_relevantRelationCondition.IsFulfilled(row, tableIndex,
                                                                    relatedFeature,
                                                                    relatedTableIndex))
                        {
                            continue;                             // the pair does not fulfill the condition
                        }

                        // this check can be expensive, so do this after the condition check
                        if (!IsValidRelation(shape, relatedFeature))
                        {
                            continue;
                        }

                        // a relevant related feature is found -> correct
                        anyRelated = true;
                        CrossTileFeatureState.FlagFeatureAsOK(tableIndex, feature);
                    }
                }
            }

            if (!anyRelated)
            {
                // could be an error; but maybe there's a related feature in a later tile
                FlagFeatureAsSuspicious(tableIndex, feature);
            }

            return(NoError);
        }