本文共 2266 字,大约阅读时间需要 7 分钟。
43、知道何时拆分复杂的查询,以及何时合并小的查询。
44、调试(Debugging)为下,测试(testing)为上。
45、尽量一次删除较少的数据。
46、通过 ARCHIVE 表和 MERGE 表将旧数据归档。
47、使用 INET_ATON 和 INET_NTOA 保存 ip 地址,而不是 CHAR 或 VARCHAR。
48、养成把 email 地址 REVERSE() 的习惯,这样能方便地查找域名。
49、--skip-name-resolve
50、增加 myisam_sort_buffer_size 的值可以优化大量数据插入(这是一个 per-connection 变量)。
51、为插入时缓存找到内存调整参数。
52、对于数据仓库,需要增加临时表大小(缺省为 32Mb),这样就不会被写到磁盘(同时也受到 max_heap_table_size 的限制,缺省为 16Mb)
53、首先要符合范式,适当的地方非范式。
54、数据库不是电子表格,尽管电子表格有点像 Access。不过,Access 不是真正的数据库。
55、在 5.1 版本中,BOOL/BIT NOT NULL 类型是 1 bit,在以前的版本中是 1 byte。
56、NULL 数据类型会比 NOT NULL 类型占用更多的存储空间。
57、选择合适的字符集,UTF16 每个字符要占用两字节,不管是否需要,latin1 比 UTF8 更快。
58、使类似的查询保持一致性,便于使缓存得到利用。
59、保持良好的 SQL 查询标准。
60、不要使用不推荐的功能。
61、合理使用触发器。
62、以 SQL_MODE=STRICT 方式运行,将有助于获得警告信息。
63、Turning OR on multiple index fields (<5.0) into UNION may speed things up (with LIMIT), after 5.0 the index_merge should pick stuff up.
64、/tmp 目录放到有后备电源和写缓存的设备上。
65、对 innodb 日志文件有后备电源的 RAM。
66、use min_rows and max_rows to specify approximate data size so space can be pre-allocated and reference points can be calculated.
67、as your data grows, indexing may change (cardinality and selectivity change). Structuring may want to change. Make your schema as modular as your code. Make your code able to scale. Plan and embrace change, and get developers to do the same.
68、削减 cron 脚本
69、建立一个测试环境
70、在选定存储引擎前,现在测试环境里对一些表进行测试。
71、Use HASH indexing for indexing across columns with similar data prefixes
72、对 int 类型的数据采用 myisam_pack_keys
73、Don’t use COUNT * on Innodb tables for every search, do it a few times and/or summary tables, or if you need it for the total # of rows, use SQL_CALC_FOUND_ROWS and SELECT FOUND_ROWS()
74、在客户端使用 --safe-updates
75、Redundant data is redundant
76、Use INSERT … ON DUPLICATE KEY update (INSERT IGNORE) to avoid having to SELECT
77、use groupwise maximum instead of subqueries
78、be able to change your schema without ruining functionality of your code
79、source control schema and config files
80、for LVM innodb backups, restore to a different instance of MySQL so Innodb can roll forward
81、use multi_query if appropriate to reduce round-trips
82、partition appropriately
83、partition your database when you have real data
84、segregate tables/databases that benefit from different configuration variables
转载地址:http://moodl.baihongyu.com/