摘要:
当前mysql列存储引擎在语义上支持primary key, 但是在功能上却出现错误。
本文的目标不是分析mysql列存储引擎primay key的错误的原因, 而是对该模块的功能的目标做分析,分析要达到的目标,以及当前的情况下所能采取的策略。
mysql index
https://dev.mysql.com/doc/refman/5.7/en/optimization-indexes.html
8.3 Optimization and Indexes
8.3.1 How MySQL Uses Indexes
8.3.2 Primary Key Optimization
8.3.3 Foreign Key Optimization
8.3.4 Column Indexes
8.3.5 Multiple-Column Indexes
8.3.6 Verifying Index Usage
8.3.7 InnoDB and MyISAM Index Statistics Collection
8.3.8 Comparison of B-Tree and Hash Indexes
8.3.9 Use of Index Extensions
8.3.10 Optimizer Use of Generated Column Indexes
8.3.11 Indexed Lookups from TIMESTAMP Columns
The best way to improve the performance of SELECT operations is to create indexes on one or more of the columns that are tested in the query. The index entries act like pointers to the table rows, allowing the query to quickly determine which rows match a condition in the WHERE
clause, and retrieve the other column values for those rows. All MySQL data types can be indexed.
Although it can be tempting to create an indexes for every possible column used in a query, unnecessary indexes waste space and waste time for MySQL to determine which indexes to use. Indexes also add to the cost of inserts, updates, and deletes because each index must be updated. You must find the right balance to achieve fast queries using the optimal set of indexes.
当前阶段所能采取的策略:
一. 在创建表时直接忽略primary key, 在 语义上直接忽略该功能
优点:
- 修改简单, 需要投入的人力成本较低
缺点:
- 查看表结构时, 将会与创建时的SQL语句指令不一致
二. 将primary key功能开发完成
所需人力:
- 考虑到现在的团队人力对mysql源码的熟悉程度远不如mysql自身的开发人员, 至少需要mysql人员开发主键索引两倍的功能
- 其中一半时间用于熟悉相关代码模块, 另外一半时间与mysql人员开发相同的开发周期来进行
优点:
- 可以完整的支持主键的语义
- 可以通过主键索引来提升查询速度
缺点:
- 存在风险, 不一定能写的出来
三. 做个假的primary key, SQL上支持, 但是功能上不做支持
优点:
- 对用户来说查看表结构与创建时的SQL能保持一致
缺点:
- 需要对primay key涉及到的所有的逻辑做一次梳理
- 能否保持primay key与普通的rnd_next接口的兼容性, 需要进一步调研