Fix SQLServer 2016 tag table compatibility bug#581
Merged
Aaronontheweb merged 2 commits intoMar 26, 2026
Merged
Conversation
Aaronontheweb
approved these changes
Mar 26, 2026
| { | ||
| get | ||
| { | ||
| if (_connection.DataProvider is SqlServerDataProvider sqlServerProvider) |
| /// Fallback implementation for providers that do not support STRING_AGG (e.g., SQL Server < 2017). | ||
| /// Fetches journal rows first, then queries tags separately and joins them client-side. | ||
| /// </summary> | ||
| private static async Task<List<JournalRow>> AddTagDataFromTagTableClientSideAsync( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix TagTable mode on SQL Server < 2017
Problem
When using
tag-write-mode = TagTablewith SQL Server 2016 (or any version prior to 2017), the read journal throws:This happens because LinqToDB's
StringAggregatemaps to SQL Server'sSTRING_AGGfunction, which was introduced in SQL Server 2017. Users on SQL Server 2016 or earlier cannot use TagTable mode at all.Solution
Added runtime SQL Server version detection via LinqToDB's
SqlServerDataProvider.Versionproperty. When the detected version is below 2017, tag aggregation falls back to a client-side implementation that:WHERE OrderingId IN (...)This is transparent to the user -- no configuration changes needed. The generic
provider-name = "SqlServer"works correctly because LinqToDB auto-detects the version by queryingsys.databasesfor the database compatibility level.Changes
Core fix (2 files):
AkkaDataConnection.cs-- AddedSupportsStringAggregateproperty that checksSqlServerDataProvider.Version >= v2017at runtime. Returnstruefor all non-SQL Server providers (PostgreSQL, MySQL, SQLite all support equivalent functions).BaseByteReadArrayJournalDao.cs-- SplitAddTagDataFromTagTableAsyncinto two paths:AddTagDataFromTagTableWithStringAggregateAsync(existing SQL path) andAddTagDataFromTagTableClientSideAsync(new fallback). The dispatcher checksconnection.SupportsStringAggregateto choose.Test infrastructure (2 files):
SqlServer2016Container.cs-- Runs SQL Server 2022 but setsCOMPATIBILITY_LEVEL = 130to simulate SQL Server 2016. Uses generic"SqlServer"provider name for auto-detection.SqlServer2016PersistenceSpec.cs-- xUnit collection definition for the 2016 compat fixture.Tests (9 files):
SupportsStringAggregateSpec.cs-- Unit tests verifying version detection returns correct values for v2005-v2016 (false), v2017+ (true), and non-SQL Server providers (true). No database required.SqlServer2016EventsByTagSpec.cs-- Includes a proof test that directly callsStringAggregateand asserts it throws on compat level 130, plus the standard TCK EventsByTag tests running through the fallback path.SqlServer2016CurrentEventsByTagSpec.cs,SqlServer2016AllEventsSpec.cs,SqlServer2016CurrentAllEventsSpec.cs,SqlServer2016EventsByPersistenceIdSpec.cs,SqlServer2016PersistenceIdsSpec.cs,SqlServer2016QueryThrottleSpecs.cs-- Full TagTable integration test suite running against the 2016 compat container.