У меня действительно действительно большая таблица (4 миллиона строк, и она станет намного больше), на которой у меня есть кластерный индекс. Но планировщик MySQL решает не использовать его, предположительно потому, что считает, что это быстрее не использовать.
Но я не понимаю, как это может быть, если у него есть зеленый индекс для использования, а он не Не нужно выполнять сортировку файлов, она должна быть действительно быстрой?
Могу ли я что-нибудь сделать, чтобы сделать этот запрос быстрым?
Accommodation_warehouse_sorted_group_index: inventoryContextID, взрослые, дети, младенцы, код продукта , totalCost
select prices.*
from `prices` force index (accommodation_warehouse_sorted_group_index)
where `adults` = 2
and `children` = 0
and `infants` = 0
and `productCode` = 'mv219'
and `warehouseContextID` = '8f3795fb-9e61-45a5-8942-2488968955f0'
order by `totalCost` asc
limit 10
Без форсирования индекса:
Форсирование индекса:
CREATE TABLE `prices` (
`id` char(36) COLLATE utf8mb4_unicode_ci NOT NULL,
`oneHotelPP` decimal(8,2) DEFAULT NULL,
`twoHotelPP` decimal(8,2) DEFAULT NULL,
`threeHotelPP` decimal(8,2) DEFAULT NULL,
`fourHotelPP` decimal(8,2) DEFAULT NULL,
`hotelNet` decimal(8,2) DEFAULT NULL,
`firstChildHotel` decimal(8,2) DEFAULT NULL,
`secondChildHotel` decimal(8,2) DEFAULT NULL,
`infantHotel` decimal(8,2) DEFAULT NULL,
`boardBasis` varchar(3) COLLATE utf8mb4_unicode_ci NOT NULL,
`adultFlight` decimal(8,2) DEFAULT NULL,
`childFlight` decimal(8,2) DEFAULT NULL,
`infantFlight` decimal(8,2) DEFAULT NULL,
`outDepartDateTime` datetime NOT NULL,
`outArrivalDateTime` datetime NOT NULL,
`outFlightNo` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL,
`inDepartDateTime` datetime NOT NULL,
`inArrivalDateTime` datetime NOT NULL,
`inFlightNo` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL,
`outboundDepartureAirportID` char(36) COLLATE utf8mb4_unicode_ci NOT NULL,
`outboundDepair` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
`outboundDepairName` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`inboundDepartureAirportID` char(36) COLLATE utf8mb4_unicode_ci NOT NULL,
`inboundDepair` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
`inboundDepairName` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`outboundDestinationAirportID` char(36) COLLATE utf8mb4_unicode_ci NOT NULL,
`outboundDestair` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
`outboundDestairName` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`inboundDestinationAirportID` char(36) COLLATE utf8mb4_unicode_ci NOT NULL,
`inboundDestair` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
`inboundDestairName` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`outOperator` varchar(60) COLLATE utf8mb4_unicode_ci NOT NULL,
`outOperatorIATA` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
`inOperator` varchar(60) COLLATE utf8mb4_unicode_ci NOT NULL,
`inOperatorIATA` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
`currency` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
`adultCost` decimal(8,2) DEFAULT NULL,
`childrenCost` decimal(8,2) DEFAULT NULL,
`infantsCost` decimal(8,2) DEFAULT NULL,
`productCode` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL,
`outboundCabinClass` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
`inboundCabinClass` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
`nights` smallint(6) NOT NULL,
`roomType` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`maxOccupancy` int(11) DEFAULT NULL,
`minOccupancy` int(11) DEFAULT NULL,
`netCost` decimal(8,2) DEFAULT NULL,
`totalCost` decimal(8,2) NOT NULL,
`source` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL,
`priceType` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL,
`appliedModifiers` json NOT NULL,
`accommodationID` char(36) COLLATE utf8mb4_unicode_ci NOT NULL,
`packageID` char(36) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`occupancy` int(11) DEFAULT NULL,
`countryID` char(36) COLLATE utf8mb4_unicode_ci NOT NULL,
`externalEngineID` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`accommodationName` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`regionID` char(36) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`atol` decimal(8,2) DEFAULT NULL,
`manualBlackout` tinyint(1) DEFAULT NULL,
`adults` int(11) DEFAULT NULL,
`children` int(11) DEFAULT NULL,
`infants` int(11) DEFAULT NULL,
`flightCost` decimal(8,2) DEFAULT NULL,
`transferDetails` json DEFAULT NULL,
`updated_at` datetime NOT NULL,
`created_at` datetime NOT NULL,
`perPersonCost` decimal(8,2) DEFAULT NULL,
`supplierAccommodationID` char(36) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`flightSourceCode` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`roomID` char(36) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`totalFlightCost` decimal(8,2) DEFAULT NULL,
`totalRoomCost` decimal(8,2) DEFAULT NULL,
`grossRoomTotalCost` decimal(8,2) DEFAULT NULL,
`grossFlightTotalCost` decimal(8,2) DEFAULT NULL,
`grossTransferTotalCost` decimal(8,2) DEFAULT NULL,
`outboundFlightID` char(36) COLLATE utf8mb4_unicode_ci NOT NULL,
`inboundFlightID` char(36) COLLATE utf8mb4_unicode_ci NOT NULL,
`outboundLegs` int(11) DEFAULT NULL,
`inboundLegs` int(11) DEFAULT NULL,
`outOperatorID` char(36) COLLATE utf8mb4_unicode_ci NOT NULL,
`inOperatorID` char(36) COLLATE utf8mb4_unicode_ci NOT NULL,
`flightSourceID` char(36) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`quoteSourceID` char(36) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`recommendedRetailPrice` decimal(8,2) DEFAULT NULL,
`discountAmount` decimal(8,2) DEFAULT NULL,
`discountPercentage` decimal(8,2) DEFAULT NULL,
`subscriberExclusiveOriginalPrice` decimal(8,2) DEFAULT NULL,
`whatChangedInFlightCost` json DEFAULT NULL,
`whatChangedInRoomOrPackage` json DEFAULT NULL,
`offerDetails` json DEFAULT NULL,
`seatsLeft` int(11) DEFAULT NULL,
`roomsLeft` int(11) DEFAULT NULL,
`sourcePrice` decimal(8,2) DEFAULT NULL,
`warehouseContextID` char(36) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`warehouseContext` varchar(40) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`departDate` date NOT NULL,
`offerID` char(36) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`outboundAirlineID` char(36) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`inboundAirlineID` char(36) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`isComplete` tinyint(1) DEFAULT NULL,
`quoteID` char(36) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`rawRoomID` char(36) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`flightRateID` char(36) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`roomSourceCode` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`deposit` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`type` varchar(15) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `prices_temp_outbounddepartureairportid_index` (`outboundDepartureAirportID`),
KEY `prices_temp_inbounddepartureairportid_index` (`inboundDepartureAirportID`),
KEY `prices_temp_outbounddestinationairportid_index` (`outboundDestinationAirportID`),
KEY `prices_temp_inbounddestinationairportid_index` (`inboundDestinationAirportID`),
KEY `prices_temp_totalcost_index` (`totalCost`),
KEY `prices_temp_accommodationid_index` (`accommodationID`),
KEY `prices_temp_countryid_index` (`countryID`),
KEY `prices_temp_regionid_index` (`regionID`),
KEY `prices_departDate_index` (`departDate`),
KEY `prices_grouped_index` (`nights`,`boardBasis`,`outboundDepair`,`productCode`,`adults`,`children`,`updated_at`,`departDate`),
KEY `occupancy_index` (`adults`,`children`,`infants`),
KEY `prices_adults_index` (`adults`),
KEY `prices_children_index` (`children`),
KEY `prices_infants_index` (`infants`),
KEY `prices_productcode_index` (`productCode`),
KEY `prices_boardbasis_index` (`boardBasis`),
KEY `prices_quotesourceid_index` (`quoteSourceID`),
KEY `prices_nights_index` (`nights`),
KEY `prices_outbounddepair_index` (`outboundDepair`),
KEY `prices_outboundcabinclass_index` (`outboundCabinClass`),
KEY `prices_inboundcabinclass_index` (`inboundCabinClass`),
KEY `prices_outboundlegs_index` (`outboundLegs`),
KEY `prices_inboundlegs_index` (`inboundLegs`),
KEY `prices_warehousecontextid_index` (`warehouseContextID`),
KEY `prices_temp_quoteid_index` (`quoteID`),
KEY `prices_temp_roomsourcecode_index` (`roomSourceCode`),
KEY `prices_temp_rawroomid_index` (`rawRoomID`),
KEY `prices_temp_flightrateid_index` (`flightRateID`),
KEY `prices_temp_flightrateid_rawroomid_index` (`flightRateID`,`rawRoomID`),
KEY `accommodation_alfred_sorted_group_index` (`adults`,`children`,`infants`,`productCode`,`nights`,`boardBasis`,`departDate`,`totalCost`),
KEY `country_alfred_sorted_group_index` (`adults`,`children`,`infants`,`countryID`,`nights`,`boardBasis`,`departDate`,`totalCost`),
KEY `accommodation_warehouse_sorted_group_index` (`warehouseContextID`,`adults`,`children`,`infants`,`productCode`,`totalCost`),
KEY `country_warehouse_sorted_group_index` (`warehouseContextID`,`adults`,`children`,`infants`,`countryID`,`totalCost`),
KEY `accommodation_warehouse_sorted_date_group_index` (`warehouseContextID`,`adults`,`children`,`infants`,`productCode`,`departDate`,`totalCost`),
KEY `country_warehouse_sorted_date_group_index` (`warehouseContextID`,`adults`,`children`,`infants`,`countryID`,`departDate`,`totalCost`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci