2 つのテーブルを見てみましょう。
CREATE TABLE `orders_products` (
`ORDER_ID` int(10) unsigned NOT NULL,
`PRODUCT_ID` int(10) unsigned NOT NULL,
`QUANTITY` tinyint(3) unsigned NOT NULL,
`USER_ID` int(10) unsigned NOT NULL,
PRIMARY KEY (`ORDER_ID`,`PRODUCT_ID`,`USER_ID`) USING BTREE,
KEY `FK_orders_products_3` (`USER_ID`),
KEY `FK_orders_products_2` (`PRODUCT_ID`) **USING BTREE**,
CONSTRAINT `FK_orders_products_1` FOREIGN KEY (`ORDER_ID`) REFERENCES `orders` (`ID`) ON DELETE CASCADE,
CONSTRAINT `FK_orders_products_2` FOREIGN KEY (`PRODUCT_ID`) REFERENCES `products` (`ID`) ON DELETE CASCADE,
CONSTRAINT `FK_orders_products_3` FOREIGN KEY (`USER_ID`) REFERENCES `users` (`ID`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
別:
CREATE TABLE `products_pictures_comments` (
`PICTURE_ID` int(10) unsigned NOT NULL,
`USER_ID` int(10) unsigned NOT NULL,
`COMMENT` text NOT NULL,
`DATEAT` datetime NOT NULL,
PRIMARY KEY (`PICTURE_ID`,`USER_ID`,`DATEAT`),
KEY `FK_products_pictures_comments_2` (`USER_ID`),
CONSTRAINT `FK_products_pictures_comments_1` FOREIGN KEY (`PICTURE_ID`) REFERENCES `products_pictures` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `FK_products_pictures_comments_2` FOREIGN KEY (`USER_ID`) REFERENCES `users` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ご覧のとおり、不明な理由で USING BTREE が表示されます。コマンドでテーブルを確認したところshow index from
、すべて Index_type が BTREE でした。ただし、FK_orders_products_2 外部キーにのみ表示されます。なんで?
編集: これらのテーブル定義は、SHOW CREATE TABLE! によって生成されました。