-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Reverse engineering: Scaffolding reads and creates "hypothetical" indexes #7665
Comments
These are not "statistics", these are user indexes created by a user via the Database Tuning Advisor (notice _dta in the name) - so they are "normal" indexes... |
Then why the "The index StatisticName on the table Employees has 49 columns in that key list. The maximum limit for index key column list is 16" error if this is a normal index? And how about .HasKey naming? |
Thanks for explanation ! |
Aah, missed that - then please provide the CREATE TABLE and CREATE INDEX statements for the table in question |
And what SQL Server version are you on? |
For Table: CREATE INDEX [dta_index_Employees_5_1429580131__K14_K34_K1_K2_K3_K4_K5_K9_K10_K11_K13_K15_K33_6_7_8_12_16_17_18_19_20_21_22_23_24_25_26_27] ON [Employees] ([name], [CNP], [employeePhone], [notes], [idMedInst_Lab], [saveInProgress], [beingEditedBy], [editStartTimestamp], [lastDDTProcessedTask], [datePlannedMedExR_man], [datePlannedMedExD_man], [datePlannedMedExC_man], [datePassedMedExP_man], [dateNextMedExP_calc], [datePlannedPsiExR_man], [datePassedPsiExP_man], [dateNextPsiExP_calc], [minMedExDate], [minMedExType], [minPsiExDate], [minPsiExType], [isDeleted], [idCurrentEmployeeState], [idEmployee], [nextMedicalCheckUp], [idMedicalCheckUpType], [nextPsycologicalCheckUp], [isControlledByDispatchPoint], [idMedInst_Poli], [currentWeeklyWorkHours]); I will talk tomorrow with my data admin ( database management isn't my responsability ) for solving with this indexes... Anyway those indexes are not visible in the Index folder under the table Employees so I didn't know about their existence. I'm running SQL Server 2014 Enterprise, version 12.2.5000.0 |
You need to share your Migration code, I do not see anything here that would cause Migrations to fail - but notice that roundtripping from Scaffolding to Migrations is not really fully supported, it is either the code first migrations workflow or scaffolding workflow that are the choices |
Code that is in my datehours_init migration :
table.PrimaryKey("_dta_index_Employees_5_1429580131__K1", x =>x.idEmployee);
.........
}
......
migrationBuilder.CreateIndex(
name: "_dta_index_Employees_5_1429580131__K14_K34_1_2_3_4_5_6_7_8_9_10_11_12_13_15_16_17_18_19_20_21_22_23_24_25_26_27_28_29_30_31_32_",
table: "Employees",
columns: new[] { "idEmployee", "name", "CNP", "employeePhone", "nextMedicalCheckUp", "idMedicalCheckUpType", "nextPsycologicalCheckUp", "notes", "isControlledByDispatchPoint", "idMedInst_Poli", "idMedInst_Lab", "saveInProgress", "beingEditedBy", "editStartTimestamp", "lastDDTProcessedTask", "datePlannedMedExR_man", "datePlannedMedExD_man", "datePlannedMedExC_man", "datePassedMedExP_man", "dateNextMedExP_calc", "datePlannedPsiExR_man", "datePassedPsiExP_man", "dateNextPsiExP_calc", "minMedExDate", "minMedExType", "minPsiExDate", "minPsiExType", "currentWeeklyWorkHours", "isDeleted", "idCurrentEmployeeState" });
.........
When I'm trying to run this migration to update/generate my database it fails at creating those X column indexes ( X > 16 ). |
OK, so first:
So you have two questions: 1: A primary key is actually a Unique Index - so that just happens to be the (crazy) name of your primary key. 2: It looks like there is an issue with included columns being generated by the Reverse engineer process, causing too many index columns @lajones @bricelam ?? |
I noticed that those indexes are hypothetical, they are not actual indexes. "_dta_index_Employees_5_1429580131__K14_K34" is marked as hypothetical for example. |
Interesting - Where do you see that? |
Running a select from sys.indexes shows me that info. Column is_hypothetical is 1 for that index example. |
Found it: sys.index is_hypothetical ! OK, suggest you drop it (then index) then, and I will do a PR for a fix to exclude hypothetical indexes - could you change the title of this issue? |
Done. I started to drop them but they are about ~ 200 ... |
And promise never to use DTA again! 😄 |
I promise as I am a developer! |
(for example created by Database Tuning Advisor - DTA) fixes dotnet#7665
Thanks for helping!! An old colleague of mine played with DTA and it seems he created those indexes. I found about hy indexes 20 minutes ago :)) |
I used EF Core CLI to generate my classes and DBContext from my production database but I observed some behaviour that I do not understand: for each table where I have statistics EF Core generates a new HasIndex entry. For example:
I have a table named Employees with 2 indexes (one clustered one non-clustered) and about 100 statistics generated.
EF core generates an entity.HasIndex(e=> new {....}).HasName("StatisticName") for every statistic. I observed this issue when I tried to make a migration but I recived an error: "The index StatisticName on the table Employees has 49 columns in that key list. The maximum limit for index key column list is 16".
I also noticed that it defines the PK with the name "StatisticName". I attached a picture with the code.
Steps to reproduce
Scaffold a database with table statistics.
Further technical details
Version:
"Microsoft.EntityFrameworkCore": "1.1.0",
"Microsoft.EntityFrameworkCore.Design": "1.1.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0",
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final"
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10 x64 latest version
IDE: Visual Studio Enterprise 2015 Update 3
The text was updated successfully, but these errors were encountered: