我正在使用两个表,如下所示:
CREATE TABLE `tb_purchase_event_join` (
`ind` int(10) unsigned NOT NULL AUTO_INCREMENT,
`wtime` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`event_ind` int(11) NOT NULL,
`id` varchar(120) COLLATE utf8mb4_unicode_ci NOT NULL,
`point` int(11) NOT NULL DEFAULT '0',
`cnt` int(255) NOT NULL DEFAULT '1',
`memo` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
`purchase_ind` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`ind`), KEY `id` (`id`),
KEY `event_ind` (`event_ind`)
);
然后
CREATE TABLE `tb_user` (
`ind` int(11) NOT NULL AUTO_INCREMENT,
`id` varchar(128) NOT NULL,
....
KEY `id` (`id`),
);
我测试了两个sql,并显示了'explain'的结果。
select tpej.*, tu.nickname, tu.level from tb_purchase_event_join tpej left join tb_user tu on tu.id = tpej.id
说明结果:
1 SIMPLE tpej ALL 37 100.00
1 SIMPLE tu ALL 137876 100.00 Using where; Using join buffer (Block Nested Loop)
还有,
select tpej.*, tu.nickname, tu.level from tb_purchase_event_join tpej join tb_user tu on tu.id = tpej.id
说明结果:
1 SIMPLE tu ALL 137877 100.00
1 SIMPLE tpej ref id id 482 func 1 100.00 Using index condition
为什么不离开联接使用索引?
怎么了?