简体   繁体   English

下面提到的查询的内部流程是什么?

[英]What is Internal process of below mentioned queries?

Select * from table t1 inner join table t2 on t1.id=t2.id

Select * from table t1,table t2 where t1.id=t2.id

As per performance which query is optimistic query?根据性能,哪个查询是乐观查询?

First query is using standar ANSI join and second query is using old style explicit join.第一个查询使用标准 ANSI 联接,第二个查询使用旧式显式联接。

Standard ANSI joins are recomended to use as it is more neat and clean code.建议使用标准 ANSI 连接,因为它的代码更加整洁。

There is no difference between two query.两个查询没有区别。

Both will produce same output and there will be no difference in terms of performance.两者都将产生相同的 output 并且在性能方面没有差异。

Cheers!!干杯!!

create table t1 (id int primary key);
create table t2 (id int primary key);

explain select * from t1 inner join t2 on t1.id = t2.id;
id | select_type | table | partitions | type   | possible_keys | key     | key_len | ref                               | rows | filtered | Extra      
-: | :---------- | :---- | :--------- | :----- | :------------ | :------ | :------ | :-------------------------------- | ---: | -------: | :----------
 1 | SIMPLE      | t1    | null       | index  | PRIMARY       | PRIMARY | 4       | null                              |    1 |   100.00 | Using index
 1 | SIMPLE      | t2    | null       | eq_ref | PRIMARY       | PRIMARY | 4       | fiddle_NTBFHZQPZPTPOTLPGUEV.t1.id |    1 |   100.00 | Using index
explain select * from t1, t2 where t1.id = t2.id;
id | select_type | table | partitions | type   | possible_keys | key     | key_len | ref                               | rows | filtered | Extra      
-: | :---------- | :---- | :--------- | :----- | :------------ | :------ | :------ | :-------------------------------- | ---: | -------: | :----------
 1 | SIMPLE      | t1    | null       | index  | PRIMARY       | PRIMARY | 4       | null                              |    1 |   100.00 | Using index
 1 | SIMPLE      | t2    | null       | eq_ref | PRIMARY       | PRIMARY | 4       | fiddle_NTBFHZQPZPTPOTLPGUEV.t1.id |    1 |   100.00 | Using index

db<>fiddle here db<> 在这里摆弄

Both queries are functionnaly identical (id they produce the same result), and the optimizer produces the same explain plan for both of them (at least in this simple cas, and, probably also in more complicated queries).两个查询在功能上是相同的(它们产生相同的结果),优化器为它们产生相同的解释计划(至少在这个简单的 cas 中,并且可能在更复杂的查询中)。

However, most SQL experts will tell you that the implicit join syntax (using a comma in the from clause) is more complicated to follow, and that, since 1992, the ANSI SQL standard recommends using explicit joins (with the join... on... syntax).但是,大多数 SQL 专家会告诉您,隐式连接语法(在from子句中使用逗号)更难以遵循,而且自 1992 年以来,ANSI SQL 标准建议使用显式连接(使用join... on...语法)。 I would strongly suggest to follow that advice.我强烈建议遵循该建议。

Related readings:相关阅读:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM