+ -
当前位置:首页 → 问答吧 → 联接查询的问题

联接查询的问题

时间:2011-07-26

来源:互联网

菜鸟请教:

有两个表 t_table1,t_table2 从 表t_table1 中 找出 t_table2中col_other 大于0的列 下面两个语句有啥性能的区别,为啥?  
两个表都超过10万行
SQL code

create table t_table1
(
    key_col   bigint not null auto_increment,
    index_col bigint not null,
    col_1     int not null,
    col_2     int not null,
    primary key(key_col)
)engine = innodb;

create index index_name on t_table1(index_col);

create table t_table2
(
    key_col   bigint not null auto_increment,
    index_col bigint not null,
    col_other int not null,
    primary key(key_col)
)engine = innodb;

create index index2_name on t_table2(index_col);

select col_1, col_2 from t_table1, t_table2 where t_table2.col > 0 and 

t_table1.index_col = t_table2.index_col;

select col_1, col_2 from t_table1 right join t_table2 on t_table1.index_col = 

t_table2.index_col where t_table2.col_other > 0;



测试了下 下面的语句 为啥 第二条列上加表名的语句查询时间快 和不加的不是一个数量级
SQL code

select col_1, col_2 from t_table1, t_table2 where t_table2.col > 0 and 
t_table1.index_col = t_table2.index_col;

select t_table1.col_1, t_table1.col_2 from t_table1, t_table2 where t_table2.col > 0 and 
t_table1.index_col = t_table2.index_col;



作者: baggio1984   发布时间: 2011-07-26

第二条不是快,应该是缓冲了。

作者: ACMAIN_CHM   发布时间: 2011-07-26