我想问两个关于MySQL索引的问题:
1。是否可以在MyISAM 引擎中使用 HASH类型的索引?
2。是否可以在计算值上创建索引,例如
CREATE INDEX AD_MAIN_CATEGORY ON ad ((category_id % 100) ASC) USING BTREE;
我有查询选择所有类别并计算主要/子类别中的广告数量。每个广告只有subategory_id,可以从中计算main_category_id(subcategory_id = 120 => main_category_id = 100)。邪恶(慢)查询:
SELECT `c`.*, (SELECT COUNT(*) FROM ad WHERE IF(c.parent_id = 0,(ad.category_id DIV 100) * 100 = c.id,ad.category_id=c.id)) AS `count`, `ct`.`label` FROM `category` AS `c` INNER JOIN `category_translation` AS `ct` ON c.id = ct.category_id WHERE (ct.language_id = 1) ORDER BY `c`.`id` ASC
答案 0 :(得分:3)
问题1:
不,请看另一个问题:Why does MySQL not have hash indices on MyISAM or InnoDB?
问题2:
是和否否,你不能(主流)MySQL但