Is it possible to use join?

In actual production, the problems about the use of join statements are generally concentrated in the following two categories:
1. Our DBA does not allow the use of join. What is the problem with using join?
2. If there are two tables of different sizes for join, which table should be used as the driving table?

In today's article, I will first tell you how the join statement is executed, and then answer these two questions.

In order to facilitate quantitative analysis, I still create two tables t1 and t2 to explain to you.

CREATE TABLE t2 (
id int(11) NOT NULL,
a int(11) DEFAULT NULL,
b int(11) DEFAULT NULL,
PRIMARY KEY (id),
KEY a (a)
) ENGINE=InnoDB;

drop procedure idata;
delimiter ;;
create procedure idata()
begin
declare i int;
set i=1;
while(i<=1000)do
insert into t2 values(i, i, i);
set i=i+1;
end while;
end;;
delimiter ;
call idata();

create table t1 like t2;
insert into t1 (select * from t2 where id<=100)

As you can see, both tables have a primary key index id and an index a, and there is no index on field b. live

Guess you like

Origin blog.csdn.net/yzh_2017/article/details/128698317