diff --git a/src/ShardingCore/Sharding/MergeEngines/EnumeratorStreamMergeEngines/EnumeratorStreamMergeEngineFactory.cs b/src/ShardingCore/Sharding/MergeEngines/EnumeratorStreamMergeEngines/EnumeratorStreamMergeEngineFactory.cs index 5268e908..d86deff9 100644 --- a/src/ShardingCore/Sharding/MergeEngines/EnumeratorStreamMergeEngines/EnumeratorStreamMergeEngineFactory.cs +++ b/src/ShardingCore/Sharding/MergeEngines/EnumeratorStreamMergeEngines/EnumeratorStreamMergeEngineFactory.cs @@ -114,11 +114,11 @@ namespace ShardingCore.Sharding.MergeEngines.EnumeratorStreamMergeEngines } } - if (isShardingDataSource&& dataSourceSequenceOrderConfig != null) - { - return new AppendOrderSequenceEnumeratorAsyncStreamMergeEngine(_streamMergeContext, dataSourceSequenceOrderConfig, tableSequenceOrderConfig, _shardingPageManager.Current.RouteQueryResults); - } - else if (isShardingTable && tableSequenceOrderConfig != null) + var useSequenceEnumeratorMergeEngine = isShardingDataSource && (dataSourceSequenceOrderConfig != null || + (isShardingTable && + !_streamMergeContext.IsCrossDataSource)) || (!isShardingDataSource && isShardingTable && tableSequenceOrderConfig != null); + + if (useSequenceEnumeratorMergeEngine) { return new AppendOrderSequenceEnumeratorAsyncStreamMergeEngine(_streamMergeContext, dataSourceSequenceOrderConfig, tableSequenceOrderConfig, _shardingPageManager.Current.RouteQueryResults); } @@ -158,22 +158,12 @@ namespace ShardingCore.Sharding.MergeEngines.EnumeratorStreamMergeEngines } } - if (isShardingDataSource) + var useSequenceEnumeratorMergeEngine = isShardingDataSource && (dataSourceSequenceOrderConfig != null || + (isShardingTable && + !_streamMergeContext.IsCrossDataSource)) || (!isShardingDataSource&&isShardingTable && tableSequenceOrderConfig != null); + if (useSequenceEnumeratorMergeEngine) { - if (dataSourceSequenceOrderConfig != null) - { - return new SequenceEnumeratorAsyncStreamMergeEngine(_streamMergeContext, dataSourceSequenceOrderConfig, tableSequenceOrderConfig, _shardingPageManager.Current.RouteQueryResults, primaryOrder.IsAsc); - } - } - else - { - if (isShardingTable) - { - if(tableSequenceOrderConfig != null) - { - return new SequenceEnumeratorAsyncStreamMergeEngine(_streamMergeContext, dataSourceSequenceOrderConfig, tableSequenceOrderConfig, _shardingPageManager.Current.RouteQueryResults, primaryOrder.IsAsc); - } - } + return new SequenceEnumeratorAsyncStreamMergeEngine(_streamMergeContext, dataSourceSequenceOrderConfig, tableSequenceOrderConfig, _shardingPageManager.Current.RouteQueryResults, primaryOrder.IsAsc); } var total = _shardingPageManager.Current.RouteQueryResults.Sum(o => o.QueryResult);