-
Notifications
You must be signed in to change notification settings - Fork 538
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
Creating a model from an existing database takes a few minutes with recent versions of SQL Server #4
Comments
If this part is removed from the TableColumns query, the offending query runs as expected (and returns correct number of rows)
|
It would be really useful if the change would make sure that the performance is fixed for all suported SQL Server versions. To give an example, we have a model with 459 tables.
If there is anything I can do to test the possible result, you can always contact me |
Another workaround mentioned by the SQL Server folks looking into this issue, in case it helps anyone: update statistics sys.syscolpars
update statistics sys.sysschobjs It seems that in fact the perf issue can be caused by stale statistics on system tables. Still investigating why that happens. |
@divega Update statistics had no effect for me, on a brand new WWI as per the @julielerman repro |
@ErikEJ apparently updating statistics can help with the "full" version of the sample database but not the "standard" version. Still pending investigation by the SQL Server folks. |
For the "standard" sample database the following has been reported to work: update statistics sys.syscolpars
update statistics sys.sysschobjs
update statistics sys.syssingleobjrefs
update statistics sys.sysiscols |
@divega Running all 4 update stats statements has no effect on my test Server (2016 CU1) - removing the lines mentioned abovce does.... |
I updated the sample DBs at the download location: On my test server reverse engineering performs well. |
@ErikEJ another thing you may want to try before you download the new version of the sample database is to clear the query cache after updating statistics with |
I built my test database from scripts! - will try the backup files... (and freeproccache) |
Adding the actual slow query... |
Tried freeproccache on my test db - no luck. Restored WWI-Std database backup - ran if 4 secs! 😄 @jodebrui : What secret "updates" did you do to the sample database ? |
I ran the following statements: UPDATE STATISTICS sys.syscolpars I incorporated them also in the source files: So if you recreate the DB from the latest source files, reverse engineering should perform well. Thanks, From: Erik Ejlskov Jensen [mailto:notifications@github.com] Tried freeproccache on my test db - no luck. Restored WWI-Std database backup - ran if 4 secs! 😄 @jodebruihttps://github.com/jodebrui : What secret "updates" did you do to the sample database ? — |
I will close this issue as there doesn't seem to be anything actionable left on the EF side. However I suspect there maybe something to follow up on in the SQL Server side: why the statistics become stale on system tables? @jodebrui what do you think? |
Makes sense to close this issue from the EF side. |
FWIW, I am still stuck with a "slow" (test) WWI database - stats update has no effect (only switching to LEGACY_CARDINALITY_ESTIMATION) |
Changing the compatibility level to an earlier version is also reported to work, as noted at http://stackoverflow.com/questions/32700540/update-wizard-not-responding. That SO question is about the problem with SQL 2014 but the compatibility level fix worked for us on SQL 2016. |
Any update from the SQL Server team on this? Do they have anywhere public to see progress? Just tripped over this and lost half a day. Is there really no way EF can fix this without a change in SQL Server? I'm not always going to be able to get clients to update their SQL Server installs, and some projects don't work without full SQL Server. I'm running:
with
Updating to
did not fix the problem and there's currently nothing newer available for either. This version of SQL Express that I was using before I installed full SQL Server works fine:
Normal "Entity Data Model" output (sql express)
Slow running under full SQL Server:
Version info from WorkaroundThanks @ErikEJ for the suggestion on stackoverflow to use EntityFramework Reverse POCO Code First Generator instead, this could potentially be a great way of entirely avoiding the problem. |
@timabell Not sure if @jodebrui will have the time to provide an update here. Consider opening a Microsoft Connect issue as suggested in #4 (comment). |
https://connect.microsoft.com/SQLServer/feedback/details/3110039 not that I have any faith in connect achieving anything from past experience. (and omg what an awful website) |
Thanks for filing the Connect item. That always helps us with visibility and prioritization of issues. Jos From: Tim Abell [mailto:notifications@github.com] not that I have any faith in connect achieving anything from past experience. — |
I just tried appending OPTION (MERGE JOIN) on one of these queries and it seems to help. @MikeYeager @tranceporter @ErikEJ @lukeatron could you confirm? |
These results show total elapsed seconds against WideWorldImporters with SQL Server 2016 SP1 on my box.
We should test with older versions of SQL Server to verify that it does not cause regressions, but |
Nice! That looks like a winner! |
In the EF reverse poco generator I have a flag which users can set to true: // If SqlServer 2014 appears frozen / take a long time when this file is saved,
// try setting this to true (you will also need elevated privileges).
IncludeQueryTraceOn9481Flag = false; This appends the following SQL to the queries to obtain the tables/columns/views: OPTION (QUERYTRACEON 9481) You should also take a look at the SQL I have in this generator. It's been hand-crafted, peer reviewed, and optimised. |
@sjh37 FYI: Diego's suggestion is based on the community effort in the EF Reverse POCO project! |
@divega Here is the thread where we discussed and tried a fair number of options including MERGE JOIN. The optimised query Simon pointed to above, was derived from the this discussion. sjh37/EntityFramework-Reverse-POCO-Code-First-Generator#262 (comment) |
@tranceporter @sjh37 like @ErikEJ said, I have seen that thread (Erik pointed me to it in a tweet) and I noticed that you have handcrafted a query for the reverse POCO generator, which is great. What I am trying to solve here, is how to workaround the SQL Server performance regression with minimal changes to our current schema discovery queries. We actually attempted this long time ago with I also learned in your discussion that a simple switch to a |
Clearing up milestone to discuss taking this earlier. |
Using VS 2017 Ver 15.5.7, |
Notes for self:
|
Fix for issue #4 - improve perf of metadata queries on SQL Server - use merge joins.
Added Note: this was added as a quirk i.e. you can this turn this addition off by adding the following to the devenv.exe.config file for the instance of VS you are using:
See #503 for details. |
Setting LEGACY_CARDINALITY_ESTIMATION like suggested is NOT working for me. |
FYI, "Change DB compatibility level to 110" did NOT work for me. Sql Server 2016 and Visual Studio 2019. |
This was originally reported by @julielerman at microsoft/sql-server-samples#57 while trying the OLTP version of the new SQL Server 2016 sample databases, WorldWideImporters (https://github.com/Microsoft/sql-server-samples/releases/tag/wide-world-importers-v1.0).
I have created this issue on our side to follow up with the SQL Server team.
Repro steps:
Observed result:
It takes about 3 minutes.
Expected result:
It should take about 10 seconds max.
Cause:
What we know so far is that this is a regression caused by differences in SQL Server 2016's cardinality estimator (CE). There have been similar issues in SQL Server 2014, which we tried to workaround by introducing
OPTION (QUERYTRACEON 9481)
on our reverse engineering queries but that didn't work for customers that didn't have enough permissions to useQUERYTRACEON
.Workaround:
It should be possible to temporarily downgrade the cardinality estimator on a specific database to use previous behaviors:
ALTER DATABASE SCOPED CONFIGURATION SET LEGACY_CARDINALITY_ESTIMATION=ON
on the databaseALTER DATABASE SCOPED CONFIGURATION SET LEGACY_CARDINALITY_ESTIMATION=OFF
on the databaseFollow up actions:
We are in contact with the SQL Server team regarding this issue and the follow up action is to work with them to see if the CE can be tweaked to eliminate the regression or if there is anything we can do on the EF side.
cc @jodebrui
The text was updated successfully, but these errors were encountered: