Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF Core keeps complaining about non existent indexes

I have a bunch log complains from EF Core during runtime, that looks like this:

[10:56:14 DBG] The index {'InvoiceId'} was not created on entity type 'CompleteCase' as the properties are already covered by the index {'InvoiceId', 'Code'}.
[10:56:14 DBG] The index {'ReportPeriodId'} was not created on entity type 'FixedBill' as the properties are already covered by the index {'ReportPeriodId', 'MedCompanyTypeId', 'FixedBillTypeId'}.
[10:56:14 DBG] The index {'CasePeriodId'} was not created on entity type 'Invoice' as the properties are already covered by the index {'CasePeriodId', 'ReportPeriodId', 'MedCompanyTypeId'}.
[10:56:14 DBG] The index {'InvoiceId'} was not created on entity type 'InvoiceFixedBillMap' as the properties are already covered by the index {'InvoiceId', 'FixedBillId'}.
[10:56:14 DBG] The index {'MedCompanyDepartmentTypeId'} was not created on entity type 'MedCompanyDepartmentDoctorMap' as the properties are already covered by the index {'MedCompanyDepartmentTypeId', 'MedCompanyDoctorTypeId', 'DoctorSpecialtyTypeId', 'StartDate', 'EndDate'}.
[10:56:14 DBG] The index {'VMPMethodTypeId'} was not created on entity type 'VMPMethodMKBMap' as the properties are already covered by the index {'VMPMethodTypeId', 'MKBTypeId'}.
[10:56:14 DBG] The index {'KSGBaseRateTypeId'} was not created on entity type 'KSGBaseRate' as the properties are already covered by the index {'KSGBaseRateTypeId', 'StartDate', 'EndDate'}.
[10:56:14 DBG] The index {'KSGTypeId'} was not created on entity type 'KSGIndexRate' as the properties are already covered by the index {'KSGTypeId', 'KSGIndexTypeId', 'StartDate', 'EndDate'}.
[10:56:14 DBG] The index {'MedCompanyTypeId'} was not created on entity type 'MedCompanyKSGIndexRate' as the properties are already covered by the index {'MedCompanyTypeId', 'MedCompanyUnitTypeId', 'MedCompanyDepartmentTypeId', 'UMPTypeId', 'KSGIndexTypeId', 'StartDate', 'EndDate'}.
[10:56:14 DBG] The index {'UserId'} was not created on entity type 'UserRole' as the properties are already covered by the index {'UserId', 'RoleId'}.
[10:56:14 DBG] The index {'UserId'} was not created on entity type 'IdentityUserToken<Guid>' as the properties are already covered by the index {'UserId', 'LoginProvider', 'Name'}.

I can see the reason for these - since there are composite indexes which use these columns they make separate indexes useless. And these columns are all foreign keys, which EF Core creates automatically during migrations.

But none of these indexes actually exists in migrations or the database itself (Code first). I have checked very closely. Even removed all the migrations and created them from scratch - nothing. But during runtime I get these every time.

Is it safe to ignore or perhaps some actions should be taken from my side?

P.S. Tested on 3.1.8 using SQL Server as a DB provider.

like image 835
Kasbolat Kumakhov Avatar asked Oct 19 '25 22:10

Kasbolat Kumakhov


1 Answers

But none of these indexes actually exists in migrations or the database itself (Code first).

Sure they don't, what you see here is just a warnings telling you that some indexes have been removed (ignored) from the model. Probably the confusing part is that you didn't explicitly request such indexes, as you say, they are automatically created by EF (and btw can't be removed externally) so EF Core shouldn't warn you.

But it is what it is. Not generating index for column(s) being leading of another index is perfectly fine. You can safely ignore that, and suppress it by adding the following to OnConfiguring override:

optionsBuilder.ConfigureWarnings(warnings => warnings
    .Ignore(CoreEventId.RedundantIndexRemoved);
like image 148
Ivan Stoev Avatar answered Oct 21 '25 14:10

Ivan Stoev