the subquery layer. The results do not depend on external queries.
Dependent subquery: The first select in the subquery layer, depending on external queries
In the UNION statement, all the SELECT statements after the second SELECT statement starts,
SIMPLE
UNION RESULT UNION
Table
Display the name of the table in the Database accessed in this step
Type
Table Acce
This SQL, execute, query all employees of the month's attendance record summary, display all the data takes 2.3 seconds
String sql = "Select Userid,orgid," + subquery, performance too slow, not applicable
"(select username from t_acl_userinfo where Userid=t.userid) Username," +
"(select count (state) from T_chk_manage where Userid=t.userid and state= '" +sqlappend+ ") state01," +
"(select count (state)
the data is to the back, the higher the query cost.As to why the latter is less efficient, we will analyze it later.
The test environment is centos 7, mysql 5.7, and the data in the test table is 500
Reproduce the classic page "optimized". When no filtering conditions are available, the sorting column will not improve the clustered index.
Here, the performance of the two statements in the next day wh
| table1 | ALL | PRIMARY |+----+-------------+--------+------+---------------+
We can clearly see that MySQL is the first selected table 2 and then matched. If we specify the STRAIGHT_JOIN method, for example:
explain select * from table1 straight_join table2 on table1.customer_id=table2.customer_id;
The main output of the preceding statement is as follows:
+----+-------------+--------+------+---------------+| id | select_type | table | type | p
environment is CentOS 7, MySQL 5.7, test table data is 500W Reproduce the classic paging "optimization", when there are no filter criteria, sorting is not improved when listed as a clustered indexHere's the next two ways to do this when a clustered index column is used as a sort conditionSELECT * FROM T order by ID limit m,n.SELECT * FROM tINNER JOIN (SELECT ID from T order by ID of limit m,n) t1 on t1.id
Generally, if you want to design a small database (with less code), but want to adapt to the performance requirements of massive data and access, the most effective method is for the main application scenarios.
Generally, if you want to design a small database (with less code), but want to adapt to the performance requirements of massive data and access, the most effective method is for the main application
This article explains how to split an SQL statement with one or more left JOIN or right join into multiple SQL statements. MySQL query efficiency is very low, especially large data, and high concurrency, the index can not solve the problem, the best way is to split the SQL statement into multiple single table query SQL.
Our company's electrical business website
High Performance MySQL Reading Notes-query performance optimization, high performance mysql
For high-performance database operations, it is not enough to design the optimal database table structure and build the best index. You al
EXPLAIN output rows covered by and would have Start temporary End temporary their rowid In the temporary table.
FirstMatch(tbl_name)In the Extra column indicates join Shortcutting.
loosescan ( m ). n ) in the extra column indicates use of The Loosescan strategy. m and n is key part numbers.
As of MySQL 5.6.7, temporary table use for materialization are indicated by rows wi
|
+----+-------------+--------+------+---------------+
As you can see, when you specify the Straight_join method, MySQL selects the Table1 table before matching it.
Then a reader asks, "What good is that?" Performance, or performance. Since I am here to test the data is relatively small, large data access, we specify Straight_join let
.
Then, based on A, filter the data again to obtain the required data and connect it to the left of the user table to obtain the final result.
From the above, the second execution plan is more efficient.
If you can use subqueries to greatly narrow the query scope, you can use subquery statements.
The above is a subquery of Mysql database
, forming a table of a.length*b.length data items. (No on required)
SELECT select_expressions from
table A cross JOIN TABLE B; Join Optimization sub-query technique:
General subquery notation: (data hours, not much impact, if the volume of data is large, then consume a large number of queries)
Select A.user_name, A.over, (select over from User2 where a.user_nam
leveraged, how your data tables are searched and sorted ... Wait, wait. Pick one of your SELECT statements (it is recommended to pick one of the most complex, multi-table joins) and add the keyword explain to the front. You can use phpMyAdmin to do this. Then, you'll see a table. In the following example, we forget to add the group_id index and have a table join: When we index the group_id field: As we can see, the previous result shows a search of 7
query execution (slightly) 4, MySQL query optimizer limitations associated subqueriesFor example: SELECT * from film where film_id in (SELECT film_id from film_actor where actor_id = 1); After the MySQL optimizer is optimized: SELECT * from film where EXISTS (select film_id from film_actor where actor_id = 1 and film_actor.film_id = fil M.FILM_ID); As can be seen from the optimizer optimization results,
statement to replace the subquery statement used to retrieve data from the same table.
* You can use the same table alias multiple times in a single statement.
The following is a simple example to help you understand the principle of auto-join.
Example:
The following statement queries all bus lines at the same station.
mysql> SELECT DISTINCT r2.num,r2.sto
to choose, The overall execution of complex query is inefficient. So, in order to make our query execution plan as optimal as possible, the most direct and effective way is to minimize join, and to reduce the join, we will inevitably need to be implemented by table field redundancy.Here we continue to analyze the differences in resource consumption further through an example of "The impact of schema design
the driver table, but when SQL is particularly complex, it does not rule out the wrong choice. In the way of the index nested link, if the association key of the non-driver table is the primary key, so the performance will be very high, if not the primary key, if the number of rows returned, the efficiency will be particularly low, because the table operation to multiple times. The index is associated first, and then the table-back operation is perfo
|+----+-------------+------------+-------+-----------------+------------+---------+--------+------+------------- -----------------+Efficiency of execution similar to not inThe basic principle of database optimization: To make the Cartesian product occur between the smallest possible set, MySQL can be scanned directly through the index when the join, and embedded in the
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.