-
Notifications
You must be signed in to change notification settings - Fork 3.2k
SQL Server: Allow users to explicitly specify the target SQL Server version/type #30163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Oldest extended supported box version today is 2014 (12.x)
|
I'm assuming you mean "mainstream end date"; for "extended end date" the older versions are still supported no? (info).
According to the docs I'm seeing, OPENJSON is supported on SQL Server 2016 (13.x) and later (so compat level 130), and STRING_AGG and CONCAT_WS on SQL Server 2017 (14.x) and later (compat level 140). |
Yes, SQL Server 2014 and later is currently in extended support Compatibility level is not the same a SKU (product version) - for example Azure SQL supports compatibility level 100 to 160 currently. OPENJSON requires compatibility level 130 or newer, so not be running on a database with that. That can only happen with SQL Server 2016+ or Azure SQL STRING_AGG and CONCAT_WS runs on "any" compatibility level, but only on SQL Server 2017+ or Azure SQL. So compat level 140 is not required in this case. |
@ErikEJ So, would you recommend that we use compatibility level as the fundamental way to decide on behaviors? And, if we do that, are the compatibility levels consistent between SQL Server and Azure SQL? We could then potential add sugar to the API to set the default compatibility level given a product version. |
STRING_AGG and CONCAT_WS will actually work on Azure SQL even on a database with a compat level below 140. But maybe it is too theoretical.
Yes, they are. |
Yes. |
I looked at all this recently for #29427 (OPENJSON)... I think it should be sufficient to simply allow the user to determine the compatibility level (see this table). This sidesteps the complexity of SQL Server vs. Azure SQL, and also accounts for the fact that newer SQL Server versions can still be configured for an older compatibility level (with ALTER DATABASE). The downside is that users need to find out which compatibility level they want (i.e. instead just saying "I'm using SQL Server X, they need to look up the correct compat level value). What do you guys think? As long as we're discussing this, here are some additional design questions:
|
From past experience, I'd argue the default level should be "latest". That is, we assume you're using the latest version and all features are available unless you explicitly opt in to an earlier version.
No. I think it's reasonable to expect all databases used by the application are at the same compat level. |
FWIW with Npgsql the default version lags ~2 years behind the latest - it's a balancing act between having most things just work well/efficiently by default, and not breaking users not on the absolute latest version. For example, I think there are very few users already on SQL Server 2022 - note that even Azure SQL doesn't support compatibility level 2016 yet (i.e. 2022 features).
This is more about whether we should allow users to set the compat level in migrations with ALTER DATABASE (just like any other ALTER DATABASE thing), and whether that should be related to the context option or not. |
This could work. The main thing is that the default is something that automatically changes, and a specific value set by the application will override it and not automatically change when the application is updated.
We can discuss. |
Yep, agreed. The high-order bit for me is that new users get reasonably new features (and better perf relying on newer database features, e.g. better Contains via OPENJSON) without having to explicitly opt in or even think abuot anything. If you do need to explicitly set the version because you're using an old version, it becomes your responsibility to bump that when you upgrade your SQL Server version etc. |
Azure SQL certainly supports 160 - it is just not the default for new databases (yet) I think default should be 160 (latest), currently only EF Core users on 130 (2017) or lower will be affected. |
@ErikEJ you're right, I misread. |
Executive architect decision: we'll default to the latest compatibility level (currently 160, SQL Server 2022). In any case, we don't expect to use any super-new feature which would block users with slightly older databases. |
We have cases where we should vary our SQL based on the target SQL Server version (e.g. #30161); to support that, we should introduce a way for users to tell us the target version, in the DbContext options. We should default to "latest", allowing users to specify older versions. We should also allow users to explicitly tell us that they're using Azure SQL, as that could have an impact on some things (e.g. execution strategy).
The text was updated successfully, but these errors were encountered: