search
HomeDatabaseMysql TutorialDoes mysql slow query have any impact?

Does mysql slow query have any impact?

Jan 06, 2021 am 11:29 AM
mysqlslow query

Mysql slow query has an impact, the reasons are: 1. There is no index or the index is not used; 2. The low IO throughput forms a bottleneck; 3. Insufficient memory; 4. The network speed is slow; 5. One query The amount of data is too large; 6. Deadlock occurs.

Does mysql slow query have any impact?

The operating environment of this tutorial: Windows 7 system, mysql version 8.0.22, DELL G3 computer. This method is suitable for all brands of computers.

Related free learning recommendations: mysql video tutorial

mysql slow query is influential.

Common reasons for slow queries include the following:

1. There is no index or no index is used.

PS: Indexes are used to quickly find records with specific values. All MySQL indexes are saved in the form of B-trees. If there is no index, when executing a query, MySQL must scan all records in the entire table starting from the first record until it finds a record that meets the requirements. The greater the number of records in the table, the higher the cost of this operation. If an index has been created on the column used as the search condition, MySQL can quickly get the location of the target record without scanning any records. If the table has 1000 records, finding the records through the index is at least 100 times faster than scanning the records sequentially.

Index type:

  • Ordinary index: This is the most basic index type, without restrictions such as uniqueness.

  • Unique index: basically the same as a normal index, but all index columns can only appear once to maintain uniqueness.

  • Primary key: The primary key is a unique index, but it must be specified as "PRIMARY KEY".

  • Full-text index: MYSQL supports full-text index and full-text search starting from 3.23.23. In MYSQL, the index type of full-text index is FULLTEXT. Full-text indexes can be created on VARCHAR or TEXT type columns.

#2. The low IO throughput forms a bottleneck.

PS: This is an analysis from the system layer that MYSQL consumes more IO. General database monitoring also pays more attention to IO.

Monitoring command: $iostat -d -k 1 10

The parameter -d indicates that the device (disk) usage status is displayed; -k some columns that use block units are forced to use Kilobytes. Unit; 1 10 means that the data display is refreshed every 1 second and is displayed 10 times in total.

3. Insufficient memory

Monitor memory usage: vmstat [-n] [Delay [number of times]]

Memory

swpd: Switch to the memory on the swap memory (default in KB)

• If the value of swpd is not 0, or is relatively large, such as more than 100M, but the long-term values ​​of si and so are 0, we don’t need to worry about this situation, it will not affect system performance.

free: free physical memory

buff: memory used as buffer cache, buffering the reading and writing of block devices

cache: memory used as page cache, file system cache• If the cache value is large, it means that there are many files in the cache. If frequently accessed files can be cached, the read IO bi of the disk will be very small.

4. The network speed is slow

ping IP -t to check whether there is packet loss.

5. The amount of data in one query is too large.

For example, if there is no paging query, tens of thousands of records can be extracted at one time. The database may be stuck.

6. Deadlock occurs

The so-called deadlock: refers to a situation caused by two or more processes competing for resources during execution. The phenomenon of waiting for each other, without external force, they will not be able to advance.

Show innodb status checks the engine status, and you can see which statements cause deadlock.

Execute show processlist to find the deadlock thread number. Then Kill processNo

7. Unnecessary rows or columns are returned

General query SQL statements Be sure to specify the fields explicitly. Do not use * to query

8. Pay attention to the difference between UNion and UNion all. UNION all is good

UNION will filter out duplicate records after table linking, so after table linking, it will sort the result set generated, delete duplicate records, and then return the results. Therefore, the efficiency of union all must be high!

The above is the detailed content of Does mysql slow query have any impact?. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How to Grant Permissions to New MySQL UsersHow to Grant Permissions to New MySQL UsersMay 09, 2025 am 12:16 AM

TograntpermissionstonewMySQLusers,followthesesteps:1)AccessMySQLasauserwithsufficientprivileges,2)CreateanewuserwiththeCREATEUSERcommand,3)UsetheGRANTcommandtospecifypermissionslikeSELECT,INSERT,UPDATE,orALLPRIVILEGESonspecificdatabasesortables,and4)

How to Add Users in MySQL: A Step-by-Step GuideHow to Add Users in MySQL: A Step-by-Step GuideMay 09, 2025 am 12:14 AM

ToaddusersinMySQLeffectivelyandsecurely,followthesesteps:1)UsetheCREATEUSERstatementtoaddanewuser,specifyingthehostandastrongpassword.2)GrantnecessaryprivilegesusingtheGRANTstatement,adheringtotheprincipleofleastprivilege.3)Implementsecuritymeasuresl

MySQL: Adding a new user with complex permissionsMySQL: Adding a new user with complex permissionsMay 09, 2025 am 12:09 AM

ToaddanewuserwithcomplexpermissionsinMySQL,followthesesteps:1)CreatetheuserwithCREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password';.2)Grantreadaccesstoalltablesin'mydatabase'withGRANTSELECTONmydatabase.TO'newuser'@'localhost';.3)Grantwriteaccessto'

MySQL: String Data Types and CollationsMySQL: String Data Types and CollationsMay 09, 2025 am 12:08 AM

The string data types in MySQL include CHAR, VARCHAR, BINARY, VARBINARY, BLOB, and TEXT. The collations determine the comparison and sorting of strings. 1.CHAR is suitable for fixed-length strings, VARCHAR is suitable for variable-length strings. 2.BINARY and VARBINARY are used for binary data, and BLOB and TEXT are used for large object data. 3. Sorting rules such as utf8mb4_unicode_ci ignores upper and lower case and is suitable for user names; utf8mb4_bin is case sensitive and is suitable for fields that require precise comparison.

MySQL: What length should I use for VARCHARs?MySQL: What length should I use for VARCHARs?May 09, 2025 am 12:06 AM

The best MySQLVARCHAR column length selection should be based on data analysis, consider future growth, evaluate performance impacts, and character set requirements. 1) Analyze the data to determine typical lengths; 2) Reserve future expansion space; 3) Pay attention to the impact of large lengths on performance; 4) Consider the impact of character sets on storage. Through these steps, the efficiency and scalability of the database can be optimized.

MySQL BLOB : are there any limits?MySQL BLOB : are there any limits?May 08, 2025 am 12:22 AM

MySQLBLOBshavelimits:TINYBLOB(255bytes),BLOB(65,535bytes),MEDIUMBLOB(16,777,215bytes),andLONGBLOB(4,294,967,295bytes).TouseBLOBseffectively:1)ConsiderperformanceimpactsandstorelargeBLOBsexternally;2)Managebackupsandreplicationcarefully;3)Usepathsinst

MySQL : What are the best tools to automate users creation?MySQL : What are the best tools to automate users creation?May 08, 2025 am 12:22 AM

The best tools and technologies for automating the creation of users in MySQL include: 1. MySQLWorkbench, suitable for small to medium-sized environments, easy to use but high resource consumption; 2. Ansible, suitable for multi-server environments, simple but steep learning curve; 3. Custom Python scripts, flexible but need to ensure script security; 4. Puppet and Chef, suitable for large-scale environments, complex but scalable. Scale, learning curve and integration needs should be considered when choosing.

MySQL: Can I search inside a blob?MySQL: Can I search inside a blob?May 08, 2025 am 12:20 AM

Yes,youcansearchinsideaBLOBinMySQLusingspecifictechniques.1)ConverttheBLOBtoaUTF-8stringwithCONVERTfunctionandsearchusingLIKE.2)ForcompressedBLOBs,useUNCOMPRESSbeforeconversion.3)Considerperformanceimpactsanddataencoding.4)Forcomplexdata,externalproc

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools