最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

performance - The optimizer does not use indexes in some queries after upgrading MariaDB 10.6 to 11.4 - Stack Overflow

programmeradmin1浏览0评论
    UPDATE empty_timetable_entries ete
    SET last_update_date = NOW()
    WHERE EXISTS(SELECT 1 AS a
         FROM tcs__slice_queue_filled_gaps tsqfg 
                  JOIN temp__queue_list tql
                       ON tql.guid = tsqfg.queue_uid
         WHERE ete.departure_station_id = tsqfg.crawler_station_code_from_id
           AND ete.arrival_station_id = tsqfg.crawler_station_code_to_id
           AND ete.departure_date = tql.departure_date);

this query is so slow in 11.4, because it doesn't use index idx_tcs_crawler_station_from_to

EXPLAIN: enter image description here

the instructions helped: FORCE INDEX (idx_tcs_crawler_station_from_to):

UPDATE empty_timetable_entries ete
SET last_update_date = NOW()
WHERE EXISTS(SELECT 1 AS a
     FROM tcs__slice_queue_filled_gaps tsqfg  FORCE INDEX (idx_tcs_crawler_station_from_to)
              JOIN temp__queue_list tql
                   ON tql.guid = tsqfg.queue_uid
     WHERE ete.departure_station_id = tsqfg.crawler_station_code_from_id
       AND ete.arrival_station_id = tsqfg.crawler_station_code_to_id
       AND ete.departure_date = tql.departure_date); 

EXPLAIN: enter image description here

query refactoring helped too:

UPDATE empty_timetable_entries ete
    JOIN tcs__slice_queue_filled_gaps tsqfg
      ON ete.departure_station_id = tsqfg.crawler_station_code_from_id
     AND ete.arrival_station_id = tsqfg.crawler_station_code_to_id
    JOIN temp__queue_list tql
      ON tql.guid = tsqfg.queue_uid
     AND ete.departure_date = tql.departure_date
    SET ete.last_update_date = NOW();   

is there a way to make the functionality the same as in 10.6 using configuration, because the solution contains many such cases and refactoring will take a lot of time?

SHOW CREATE TABLES:

CREATE TABLE `tcs__slice_queue_filled_gaps` (
  `guid` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'global unique identifier',
  `slice_uid` bigint(20) NOT NULL DEFAULT 0 COMMENT 'global unique slice identifier',
  `queue_uid` bigint(20) NOT NULL DEFAULT 0 COMMENT 'global unique file identifier',
  `slice_md5checksum` varchar(32) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL DEFAULT md5(concat(rand(),rand(),rand())) COMMENT 'slice md5 checksum',
  `file_md5checksum` varchar(32) NOT NULL DEFAULT md5(concat(rand(),rand(),rand())) COMMENT 'file md5 checksum',
  `load_date` date NOT NULL DEFAULT '1970-01-01',
  `route` varchar(256) NOT NULL DEFAULT '',
  `crawler_id` varchar(256) DEFAULT '',
  `plugin_type` varchar(256) NOT NULL DEFAULT '',
  `from_load_date_day_offset` int(11) NOT NULL DEFAULT 0,
  `date_depth` int(11) NOT NULL DEFAULT 0,
  `min_departure_date` date NOT NULL DEFAULT '1970-01-01',
  `max_departure_date` date NOT NULL DEFAULT '1970-01-01',
  `carrier_id` int(11) DEFAULT 0,
  `coach_class_id` int(11) DEFAULT 0,
  `crawler_station_code_from_id` int(11) DEFAULT 0,
  `crawler_station_code_to_id` int(11) DEFAULT 0,
  `train_brand_id` int(11) DEFAULT 0,
  `train_class_id` int(11) DEFAULT 0,
  `train_id` int(11) DEFAULT 0,
  `fare_code_id` int(11) DEFAULT 0,
  `change_stations` varchar(512) DEFAULT '0',
  PRIMARY KEY (`guid`),
  UNIQUE KEY `UK__slice_uid__queue_uid` (`slice_uid`,`queue_uid`),
  KEY `KEY__file_md5checksum` (`file_md5checksum`),
  KEY `KEY__slice_md5checksum` (`slice_md5checksum`),
  KEY `idx_tcs_queue_uid` (`queue_uid`),
  KEY `idx_tcs_crawler_station_from_to` (`crawler_station_code_from_id`,`crawler_station_code_to_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1024 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

CREATE TABLE `empty_timetable_entries` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `departure_station_id` int(10) NOT NULL,
  `arrival_station_id` int(10) NOT NULL,
  `departure_date` date NOT NULL,
  `is_sold_out` tinyint(3) NOT NULL DEFAULT 1,
  `last_update_date` datetime DEFAULT current_timestamp(),
  `creation_date` datetime DEFAULT current_timestamp(),
  PRIMARY KEY (`id`),
  KEY `dep_arr_id_dep_date_index` (`departure_station_id`,`arrival_station_id`,`departure_date`),
  KEY `dep_date_index` (`departure_date`)
) ENGINE=InnoDB AUTO_INCREMENT=3180529 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

CREATE TABLE `temp__queue_list` (
  `guid` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'global unique identifier',
  `load_time` datetime NOT NULL DEFAULT current_timestamp() COMMENT 'load time',
  `modification_time` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',
  `slice_md5checksum` varchar(32) NOT NULL DEFAULT md5('Legacy') COMMENT 'slice md5 checksum',
  `file_md5checksum` varchar(32) NOT NULL DEFAULT md5(concat(rand(),rand(),rand())) COMMENT 'md5 checksum - inserted value',
  `departure_date` date NOT NULL DEFAULT '1970-01-01',
  `code_from` varchar(512) NOT NULL DEFAULT '',
  `code_to` varchar(512) NOT NULL DEFAULT '',
  `coach_class` varchar(256) NOT NULL DEFAULT '',
  `train_brand_code` varchar(100) DEFAULT NULL,
  `train_class_code` varchar(256) DEFAULT NULL,
  `train_number` varchar(50) DEFAULT NULL,
  `departure_time_offset_sec` int(11) NOT NULL DEFAULT 0,
  `duration_time_offset_sec` int(11) NOT NULL DEFAULT 0,
  `price_value` decimal(20,6) NOT NULL DEFAULT 0.000000,
  `currency_code` varchar(4) NOT NULL DEFAULT '',
  `fare_code` varchar(255) NOT NULL DEFAULT '',
  `change_stations` varchar(512) NOT NULL DEFAULT 'NULL',
  `processed_code` tinyint(4) NOT NULL DEFAULT 100 COMMENT 'processed status of data in queue',
  `error_code` tinyint(4) NOT NULL DEFAULT 100 COMMENT 'error code',
  `carrier_code` varchar(20) DEFAULT 'NULL',
  PRIMARY KEY (`guid`)
) ENGINE=MEMORY AUTO_INCREMENT=292634985 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论