Get the App
SLTechnology News&Howtos  ›  Database  › 

What is the MySQL SQL optimization method?

Shulou Source: shulou.com Published: 2022-05-31 13:59:17 11月14日 Update

This article mainly explains "what is the MySQL SQL optimization method". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn what the MySQL SQL optimization method is.

A sql was found in slowlog for more than 10 seconds.

# Time: 2017-03-02T18:41:50.201376+08:00

# User@Host: oms_ readonly[ oms _ readonly] @ [10.xx.xx.xx] Id: 54124620

# Query_time: 11.005894 Lock_time: 0.000223 Rows_sent: 20 Rows_examined: 1838114

SET timestamp=1488451310

Select * from customers where `type` = 1 AND `status`

< 7 AND `isarea` = 6 AND `into_time`>

= '2016-12-01'AND `into_ time` explain select * from customers where `type` = 1 AND `status`

< 7 AND `isarea` = 6 AND `into_time`>

= '2016-12-01'AND `into_ time` select count (*) from customers where `type` = 1

+-+

| | count (*) |

+-+

| | 2373175 |

+-+

1 row in set (1.53 sec)

Mysql > select count (*) from customers where `status`

< 7; ->

+-+

| | count (*) |

+-+

| | 2494232 |

+-+

1 row in set (3.16 sec)

Mysql > select count (*) from customers where `isarea` = 6

+-+

| | count (*) |

+-+

| | 135347 |

+-+

1 row in set (0.15 sec)

Mysql > select count (*) from customers where `into_ time` > = '2016-12-01'AND `into_ time` explain select * from customers use index (isarea) where `type` = 1 AND `status`

< 7 AND `isarea` = 6 AND `into_time`>

= '2016-12-01'AND `into_ time`

Tags: Methods learning content index results selectivity selection obviously that is ideas situations articles more knowledge knowledge points articles follow problems practice compulsion Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn NVidia Linux Shulou Technology Docker