在Django数据库访问优化中一开始的时候就有提到Django有一个Field.db_index的字段,用来帮你建立表索引,这在初始化数据库时是有效的。数据库建立完之后,再来添加这个参数就需要用south。
主要是针对MySql,查看对应表的索引
show index from table_name;
创建索引的语句
ALTER TABLE table_name ADD INDEX index_name (column_list);
/* for example add post alias index */
ALTER TABLE posts ADD INDEX alias_index (alias);
删除索引
ALTER TABLE table_name DROP INDEX index_name;
加上索引后,文章查询速度明显有所提升。