Comparison of query speed with and without index

Database structure:show create table api_test_history_detail;

 CREATE TABLE `api_test_history_detail` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `case_id` varchar(50) DEFAULT NULL,
  `case_number` varchar(50) DEFAULT NULL,
  `host` varchar(100) DEFAULT NULL,
  `url` varchar(100) DEFAULT NULL,
  `model` varchar(100) DEFAULT NULL,
  `name` varchar(100) DEFAULT NULL,
  `description` varchar(500) DEFAULT NULL,
  `request_type` varchar(50) DEFAULT NULL,
  `request_headers` varchar(500) DEFAULT NULL,
  `params_type` varchar(50) DEFAULT NULL,
  `params` longtext,
  `priority` varchar(50) DEFAULT NULL,
  `login_or_not` varchar(50) DEFAULT NULL,
  `platform` varchar(50) DEFAULT 'Android',
  `pre_case_id` varchar(50) DEFAULT NULL,
  `pre_case_data` varchar(500) DEFAULT NULL,
  `expect_whole` longtext,
  `expect_value` varchar(500) DEFAULT NULL,
  `expect_structure` longtext,
  `request_time_millisecond` int(11) DEFAULT '0',
  `run_time_seconds` int(11) DEFAULT '0',
  `start` datetime DEFAULT NULL,
  `end` datetime DEFAULT NULL,
  `result` varchar(50) DEFAULT NULL,
  `response` longtext,
  `reason` varchar(1000) DEFAULT NULL,
  `report_dir_name` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `report_dir_name_index` (`report_dir_name`)
) ENGINE=InnoDB AUTO_INCREMENT=80194 DEFAULT CHARSET=utf8mb4

Query statement: select * from api_test_history_detail where report_dir_name='20230725100814';
There is only one query result. When the index is not built, the query time takes 8s+ , but after the index is built, the query time is almost 0s

insert image description here

It can be seen that the efficiency of indexing to optimize query speed is still very high, and fields with high query frequency can be reasonably indexed.

In addition, there is another detail that needs to be paid attention to. In the query statement, the string value is best enclosed in quotation marks. If you do not use quotation marks, the query is still time-consuming! !
insert image description here

Guess you like

Origin blog.csdn.net/wzx77/article/details/131913649