search
HomeDatabaseSQLExecution of a SQL statement

Execution of a SQL statement

Recommended (free): SQL

Zero, database driver

  • The MySQL driver helps us connect to the database at the bottom level. Only after the connection is established can subsequent interactions be possible.

1. Database connection pool

  • Database connection pools include Druid, C3P0, and DBCP
  • Using connection pools saves a lot of money The overhead of constantly creating and destroying threads is the famous "pooling" idea. Whether it is a thread pool or an HTTP connection pool, you can see its presence

2. SQL interface

  • The thread that processes the request in MySQL obtains the SQL statement after obtaining the request and hands it to the SQL interface for processing.

3. Query parser

  • #Parses the SQL statement passed by the SQL interface and translates it into a language that MySQL can understand.

4. MySQL Query Optimizer

  • MySQL will choose to use the corresponding index based on the minimum cost principle
  • #Cost = IO cost CPU cost
  • IO cost: That is, the cost of loading data from disk to memory. By default, the IO cost of reading a data page is 1, MySQL reads data in the form of pages. That is, when a certain data is used, it will not only read this data, but also read the data adjacent to this data into the memory. This is a famous program. The principle of locality, so MySQL will read a whole page each time, and the cost of one page is 1. Therefore, the cost of IO is mainly related to the size of the page
  • CPU cost: After reading the data into the memory, it is also necessary to detect whether the data meets the conditions and the cost of sorting and other CPU operations. Obviously it is related to Depending on the number of rows, by default, the cost of detecting records is 0.2.
  • MySQL optimizer will calculate the "IO cost CPU" index with the smallest cost to execute

5. Storage engine

    The query optimizer will call the storage engine interface to execute SQL, which means that the actual
  • execution of SQL is completed in the storage engine.
  • Data is stored in memory or disk
  • Every time SQL is executed, its data will be loaded into memory. This memory is a very important component in InnoDB. :
  • Buffer Pool
##6. Executor

The executor finally goes according to a series of execution plans Call the storage engine interface to complete the execution of SQL

Execution of a SQL statement

7. Buffer Pool

Buffer Pool ( Buffer Pool) is a very important memory structure in the InnoDB storage engine. It plays the role of a cache.
  • Buffer Pool means that when we query for the first time, we will store the query results in the Buffer Pool, so that later When there is another request, it will first be queried from the buffer pool. If there is no search, it will be searched on the disk, and then placed in the Buffer Pool.
  • The data used in the Buffer Pool will be locked.

  • Buffer Pool
8. Three log files

1. Undo log file

: before the recorded data is modified Appearance

Function: Use undo log files to complete transaction rollback

Execution of a SQL statement

2. Redo log files

: Record the appearance of the modified data

redo records the value after the data modification, regardless of whether the transaction is submitted or not.
  • MySQL In order to improve efficiency, these operations are It is first placed in memory to complete. The updated data will be recorded in the redo log buffer, and then persisted to disk at a certain opportunity.

  • Execution of a SQL statement
3. Bin log log file:

Record the entire operation process

Implementation method to record Methodredo log records in a loop writing method. When writing to the end, it will return to the beginning to write logs in a loop. bin log is recorded by appending. When the file size is larger than the given value, subsequent logs will be recorded to new filesUsage scenarios
Property redo Log bin Log
File size The size of the redo log is fixed (it can also be set in the configuration, generally the default is enough) bin log can be set for each # through the configuration parameter max_bin log_size ##bin logThe size of the file (but it is generally not recommended to modify it).
redo log is implemented by the InnoDB engine layer (that is to say, Innodb storage causes excessive Yes) bin log is implemented by the MySQL layer, and all engines can use bin loglog
redo logSuitable for crash recovery (crash-safe) (this is actually very similar to the persistence feature of Redis) bin logSuitable for master From replication and data recovery
bin log records the entire operation record (this is very important for master-slave replication)

The above is the detailed content of Execution of a SQL statement. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:CSDN. If there is any infringement, please contact admin@php.cn delete
SQL and MySQL: Understanding the Core DifferencesSQL and MySQL: Understanding the Core DifferencesApr 17, 2025 am 12:03 AM

SQL is a standard language for managing relational databases, while MySQL is a specific database management system. SQL provides a unified syntax and is suitable for a variety of databases; MySQL is lightweight and open source, with stable performance but has bottlenecks in big data processing.

SQL: The Learning Curve for BeginnersSQL: The Learning Curve for BeginnersApr 16, 2025 am 12:11 AM

The SQL learning curve is steep, but it can be mastered through practice and understanding the core concepts. 1. Basic operations include SELECT, INSERT, UPDATE, DELETE. 2. Query execution is divided into three steps: analysis, optimization and execution. 3. Basic usage is such as querying employee information, and advanced usage is such as using JOIN connection table. 4. Common errors include not using alias and SQL injection, and parameterized query is required to prevent it. 5. Performance optimization is achieved by selecting necessary columns and maintaining code readability.

SQL: The Commands, MySQL: The EngineSQL: The Commands, MySQL: The EngineApr 15, 2025 am 12:04 AM

SQL commands are divided into five categories in MySQL: DQL, DDL, DML, DCL and TCL, and are used to define, operate and control database data. MySQL processes SQL commands through lexical analysis, syntax analysis, optimization and execution, and uses index and query optimizers to improve performance. Examples of usage include SELECT for data queries and JOIN for multi-table operations. Common errors include syntax, logic, and performance issues, and optimization strategies include using indexes, optimizing queries, and choosing the right storage engine.

SQL for Data Analysis: Advanced Techniques for Business IntelligenceSQL for Data Analysis: Advanced Techniques for Business IntelligenceApr 14, 2025 am 12:02 AM

Advanced query skills in SQL include subqueries, window functions, CTEs and complex JOINs, which can handle complex data analysis requirements. 1) Subquery is used to find the employees with the highest salary in each department. 2) Window functions and CTE are used to analyze employee salary growth trends. 3) Performance optimization strategies include index optimization, query rewriting and using partition tables.

MySQL: A Specific Implementation of SQLMySQL: A Specific Implementation of SQLApr 13, 2025 am 12:02 AM

MySQL is an open source relational database management system that provides standard SQL functions and extensions. 1) MySQL supports standard SQL operations such as CREATE, INSERT, UPDATE, DELETE, and extends the LIMIT clause. 2) It uses storage engines such as InnoDB and MyISAM, which are suitable for different scenarios. 3) Users can efficiently use MySQL through advanced functions such as creating tables, inserting data, and using stored procedures.

SQL: Making Data Management Accessible to AllSQL: Making Data Management Accessible to AllApr 12, 2025 am 12:14 AM

SQLmakesdatamanagementaccessibletoallbyprovidingasimpleyetpowerfultoolsetforqueryingandmanagingdatabases.1)Itworkswithrelationaldatabases,allowinguserstospecifywhattheywanttodowiththedata.2)SQL'sstrengthliesinfiltering,sorting,andjoiningdataacrosstab

SQL Indexing Strategies: Improve Query Performance by Orders of MagnitudeSQL Indexing Strategies: Improve Query Performance by Orders of MagnitudeApr 11, 2025 am 12:04 AM

SQL indexes can significantly improve query performance through clever design. 1. Select the appropriate index type, such as B-tree, hash or full text index. 2. Use composite index to optimize multi-field query. 3. Avoid over-index to reduce data maintenance overhead. 4. Maintain indexes regularly, including rebuilding and removing unnecessary indexes.

How to delete constraints in sqlHow to delete constraints in sqlApr 10, 2025 pm 12:21 PM

To delete a constraint in SQL, perform the following steps: Identify the constraint name to be deleted; use the ALTER TABLE statement: ALTER TABLE table name DROP CONSTRAINT constraint name; confirm deletion.

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment