01. Steps in SQL Query Execution (MySQL)
Steps in SQL Query Execution (MySQL)
1. Client Sends Query to Server
- The SQL statement is sent to the MySQL server over a connection (e.g., via JDBC or a query tool like MySQL Workbench).
2. Parser / Syntax Check
- The parser checks the SQL syntax.If there are any syntax errors, it throws an error immediately.
3. Pre-processor
- Verifies privileges and permissions for the user executing the query.
- Resolves object names (like table or column aliases).
4. Query Optimization
- The optimizer evaluates multiple strategies to execute the query. It considers:
Which indexes to use.
Join order (for multi-table queries).
Whether to use temporary tables.
Cost of different execution paths.
- The optimizer chooses select the most efficient query plan (Cost effective -> memory, CPU etc).
5. Query Execution Plan (Most cost effective query plan)
- The query plan is a blueprint of how MySQL will fetch the data.
- You can view this with the EXPLAIN keyword in front of your query.
6. Query Execution
- The storage engine (like InnoDB) executes the plan:
7. Result Sent to Client
- The result set is sent back to the client in chunks.
Comments
Post a Comment