Summary:"alias shouldn't be the same with column name or table name.",
Content:`表或列的别名与其真实名称相同, 这样的别名会使得查询更难去分辨。`,
},
"ALT.001":{
Summary:"修改表的默认字符集不会改表各个字段的字符集",
Summary:"modify the default character set will not modify the character set of each field in the table.",
Content:`很多初学者会将ALTER TABLE tbl_name [DEFAULT] CHARACTER SET 'UTF8'误认为会修改所有字段的字符集,但实际上它只会影响后续新增的字段不会改表已有字段的字符集。如果想修改整张表所有字段的字符集建议使用ALTER TABLE tbl_name CONVERT TO CHARACTER SET charset_name;`,
},
"ALT.002":{
Summary:"同一张表的多条ALTER请求建议合为一条",
Summary:"recommend to merge multiple ALTER request if it's in the same table.",
Summary:"IN (NULL)/NOT IN (NULL) , always false.",
Content:"正确的作法是col IN ('val1', 'val2', 'val3') OR col IS NULL",
},
"ARG.005":{
Summary:"IN要慎用,元素过多会导致全表扫描",
Summary:"Use IN with caution,too many elements will lead to a full table scan.",
Content:` 如:select id from t where num in(1,2,3)对于连续的数值,能用BETWEEN就不要用IN了:select id from t where num between 1 and 3。而当IN值过多时MySQL也可能会进入全表扫描导致性能急剧下降。`,
},
"ARG.006":{
Summary:"应尽量避免在WHERE子句中对字段进行NULL值判断",
Summary:"Try to avoid judge NULL values in WHERE clause.",
Content:`使用IS NULL或IS NOT NULL将可能导致引擎放弃使用索引而进行全表扫描,如:select id from t where num is null;可以在num上设置默认值0,确保表中num列没有null值,然后这样查询: select id from t where num=0;`,
Note that the difference between these two clauses lies in the fact that the WHERE clause introduces a condition on individual rows, while the HAVING clause introduces a condition on aggregations or results of a selection where a single result, such as MIN, MAX, SUM,… has been produced from multiple rows.
*/
"CLA.013":{
Summary:"不建议使用HAVING子句",
Summary:"The use of HAVING clause is not recommended.",
Content:`由于WHERE条件错误使得OUTER JOIN的外部表无数据返回,这会将查询隐式转换为 INNER JOIN 。如:select c from L left join R using(c) where L.a=5 and R.b=10。这种SQL逻辑上可能存在错误或程序员对OUTER JOIN如何工作存在误解,因为LEFT/RIGHT JOIN是LEFT/RIGHT OUTER JOIN的缩写。`,
},
"JOI.004":{
Summary:"不建议使用排它JOIN",
Summary:"The use of exclusive JOIN is not recommended.",
Content:`只在右侧表为NULL的带WHERE子句的LEFT OUTER JOIN语句,有可能是在WHERE子句中使用错误的列,如:“... FROM l LEFT OUTER JOIN r ON l.l = r.r WHERE r.z IS NULL”,这个查询正确的逻辑可能是 WHERE r.r IS NULL。`,
Summary:"UPDATE may have a logical error that causes data corruption.",
Content:"",
},
"RES.006":{
Summary:"永远不真的比较条件",
Summary:"Compare condition always false.",
Content:"查询条件永远非真,这将导致查询无匹配到的结果。",
},
"RES.007":{
Summary:"永远为真的比较条件",
Summary:"COmpare condition always true.",
Content:"查询条件永远为真,这将导致WHERE条件失效进行全表查询。",
},
"RES.008":{
Summary:"不建议使用LOAD DATA/SELECT ... INTO OUTFILE",
Summary:"The use of LOAD DATA/SELECT ... INTO OUTFILE is not recommended.",
Content:"SELECT INTO OUTFILE需要授予FILE权限,这通过会引入安全问题。LOAD DATA虽然可以提高数据导入速度,但同时也可能导致从库同步延迟过大。",
},
"SEC.001":{
Summary:"请谨慎使用TRUNCATE操作",
Summary:"Caution:using TRUNCATE operation.",
Content:`一般来说想清空一张表最快速的做法就是使用TRUNCATE TABLE tbl_name;语句。但TRUNCATE操作也并非是毫无代价的,TRUNCATE TABLE无法返回被删除的准确行数,如果需要返回被删除的行数建议使用DELETE语法。TRUNCATE操作还会重置AUTO_INCREMENT,如果不想重置该值建议使用DELETE FROM tbl_name WHERE 1;替代。TRUNCATE操作会对数据字典添加源数据锁(MDL),当一次需要TRUNCATE很多表时会影响整个实例的所有请求,因此如果要TRUNCATE多个表建议用DROP+CREATE的方式以减少锁时长。`,