我必须使用linq构建一个大型查找查询。由于我使用聚合查询的原因很繁琐,由于(可能)缺少索引,查询速度很慢,问题是如何为约20个字段创建复合索引,这样行得通吗?
这是我的linq查询:
var listFlight = CacheFlightsPair.AsQueryable(new AggregateOptions() { AllowDiskUse = true })
.Where(x => x.CreateDate > minDateForResults && ((!string.IsNullOrEmpty(slotRule.ExternalId) && x.Source.ExternalId == slotRule.ExternalId)
|| ((x.Source.OutDepartureDate.Value >= slotRule.FromDate && x.Source.OutDepartureDate.Value < slotRule.FromDate.AddDays(1))
&& (x.Source.InArrivalDate.HasValue && x.Source.InArrivalDate.Value >= slotRule.ToDate && x.Source.InArrivalDate.Value < slotRule.ToDate.AddDays(1))
&& (slotRule.SupplierId == 0 || (x.Source.Supplier != null && x.Source.Supplier.ID == slotRule.SupplierId))
&& (slotRule.CityId == 0 || x.Source.OutArrivalAirportID.City.ID == slotRule.CityId)
&& (slotRule.PriceFrom == 0) || ((x.Source.CurrencyID.ID == (int)CommonUtil.Cu_Currencies.EUR && x.Source.Price >= minPriceCurrencies[(int)CommonUtil.Cu_Currencies.EUR]) ||
(x.Source.CurrencyID.ID == (int)CommonUtil.Cu_Currencies.USD && x.Source.Price >= minPriceCurrencies[(int)CommonUtil.Cu_Currencies.USD]) ||
(x.Source.CurrencyID.ID == (int)CommonUtil.Cu_Currencies.ILS && x.Source.Price >= minPriceCurrencies[(int)CommonUtil.Cu_Currencies.ILS])
)
&& (slotRule.PriceTo == 0) || ((x.Source.CurrencyID.ID == (int)CommonUtil.Cu_Currencies.EUR && x.Source.Price <= maxPriceCurrencies[(int)CommonUtil.Cu_Currencies.EUR]) ||
(x.Source.CurrencyID.ID == (int)CommonUtil.Cu_Currencies.USD && x.Source.Price <= maxPriceCurrencies[(int)CommonUtil.Cu_Currencies.USD]) ||
(x.Source.CurrencyID.ID == (int)CommonUtil.Cu_Currencies.ILS && x.Source.Price <= maxPriceCurrencies[(int)CommonUtil.Cu_Currencies.ILS])
)
&& (slotRule.FlightTypeId == 0 || (x.Source.FlightType != null && x.Source.FlightType.ID == slotRule.FlightTypeId))
&& (slotRule.NumberOfAdults == 0 || x.Source.NumberOfAdults == slotRule.NumberOfAdults)
&& x.Source.NumberOfChildren == slotRule.NumberOfChildren
&& x.Source.NumberOfBabies == slotRule.NumberOfBabies
&& x.Source.NumberOfPensioners == slotRule.NumberOfPensioners
&& x.Source.NumberOfPensioners == slotRule.NumberOfStudents
)));
如果我应该使用其他方法,请告诉我。