I wrote it a few months ago. It was messy and it was released from my mailbox.
Mysql select
It is said that when writing a SELECT statement, try to write the name of the selected column instead of using select *. In fact, simple tables do not matter. However, when table join or complex query is involved, this item will be effective. Assume there are four tables: t_A ID B _id col1 col2 created_by created_att_ B ID c_id col1 col2t_c ID col1 col2 col3 col4t_a There are 100,000 records T_ B there are 10,000 records T_c there are 100 records there is a query like this: select * From T_A A, T_ B B, T_c cwhere. created_by <1000and. B _id = B. idand B. c_id = C. idorder by. created_at DESC assume that there are 100 results in the query, and the fields required for the query results are incomplete. At this time, "*" is used for independent writing, which can be of great impact. Cause: This query is a Cartesian product first to generate a temporary table. If select * is used, the number of columns in this temporary table is the sum of the columns in the three tables: 6 + 4 + 5 = 15. However, if select a. *, B. * is used, the list of this temporary table is the number of columns in the select clause, plus the number of attributes used in the WHERE clause. In addition, because of the number of columns, the memory space occupied by the generated table is different, such as whether to add a varchar or field. When the memory size configured for the database server cannot be fully loaded, you need to write the temporary table to the disk space and perform subsequent operations. In addition, the limit function of MySQL seems to be quite simple to implement. In case of a query, the limit statement is different. Select * From XXXXX where XXXXXXXXX limit 0, 20 select * From XXXXX where XXXXXXXXX limit 100000, 20 the two queries, the latter one needs to write the temporary table to the disk space, not the first one...