MYSQL-Profile analysis today, when analyzing an SQL statement, it is found that adding spaces at the end or at the beginning of the SQL statement does not affect obtaining the result directly from QC. In the reference manual, the query for www.2cto.com must be identical (in bytes) to be considered the same. In addition, the same query string may be considered different for other reasons. Queries using different databases, different protocol versions, or different default character sets are considered to be different queries and cache them separately. Since the SQL statements must be identical, the following two SQL statements should be different select count (*) from t1; select count (*) from t1; but in actual operation, mysql> show profiles executed as the same SQL statement; + ---------- + ------------ + ------------------------- + | Query_ID | Duration | Query | + ---------- + ------------ + ----------------------------- + | 1 | 0.00006925 | select count (*) from t1 | 2 | 0.08126275 | insert into t1 values (6) | 3 | 0.00043675 | select count (*) from t1 | 4 | 0. 00006850 | select count (*) from t1 | 5 | 0.00021075 | select count (*) from t1 | 6 | 0.00007150 | select count (*) from t1 | 7 | 0.00007300 | select count (*) from t1 | 8 | 0.00020975 | select count (*) from t1 | + ---------- + ------------ + ----------------------------- + 8 rows in set (0.00 sec) www.2cto.com, and only the SQL statement with spaces added before and after the preceding statement is obtained from QC directly, optimization and execution are not performed. Mysql> show profile for query 7; + running + ---------- + | Status | Duration | + -------------------------------- + ---------- + | starting | 0.000022 | checking query cache for query | 0.000007 | checking privileges on cached | 0.000005 | sending cached result to clien | 0.000034 | logging slow query | 0.000003 | cleaning up | 0.000003 | + ------------------------------ + -------- -- + 6 rows in set (0.00 sec) insert spaces in the middle of SQL to run as different SQL statements. Mysql> show profile for query 8; + running + ---------- + | Status | Duration | + -------------------------------- + ---------- + | starting | 0.000023 | www.2cto.com | checking query cache for query | 0.000049 | Opening tables | 0.000013 | System lock | 0.000005 | Table lock | 0.000037 | init | 0.000012 | optimizing | 0.000006 | executing | 0.000012 | end | 0.000004 | query e Nd | 0.000003 | freeing items | 0.000036 | storing result in query cache | 0.000006 | logging slow query | 0.000003 | cleaning up | 0.000002 | + ---------------------------- + ---------- + 14 rows in set (0.00 sec) as shown in the preceding figure, QC removes leading and trailing spaces when storing SQL statements. In addition, spaces at the beginning and end are automatically removed during the query and then compared in QC. Author 909413335