Sql execution order problem

sql executes sequential from,on,join. reference article

there are two tables, posts 10000 data, post_slugs 14 records, and posts, two tables are associated by post_id. Use mysql

SELECT * from posts,post_slugs where post_slugs.post_id=posts.post_id , in the order of sql execution, from is followed by the Dikal product of two tables, so the data actually operated by the where condition should be 10000X14 records.

SELECT * from posts join post_slugs on post_slugs.post_id=posts.post_id in the order of sql execution, from reads the data of the posts table to generate a virtual table T1, and according to the on condition to read the data that post_slugs meets the conditions to generate a virtual table T2, and then according to the join method, insert the data that needs to be retained. In fact, the amount of data after join should be 14 records.

however, there is actually no difference in execution time between the two statements. Is this because the mysql optimizer handles it or is the execution sequence misunderstood?

Nov.01,2021

join has left join,right join,inner join;
join is inner join. This is the inner link.
the results of inner join and where are the same unless the results produced by left join,right join are different, that is, the query for the main table, such as
A left join B ON a.id = b.id
, in this case, the data of table An as the main table will be queried


.

SELECT * from posts,post_slugs the decal product of two tables
SELECT * from posts,post_slugs where post_slugs.post_id=posts.post_id is conditionally automatically optimized to the following statement
SELECT * from posts inner join post_slugs on post_slugs.post_id=posts.post_id
the difference between the two is that join must have conditional on, and the former can be unconditional.
the behavior of both before and after explain analyze analysis in postgresql is completely consistent, and the join time is slightly better than that of 0.05ms, which is estimated to be the time of multi-table optimization

.
explain analyze select * from t_xmxx_x a, t_shwzcmx b where a.f_xmid=b.f_xmid;
+----------------------------------------------------------------------------------------------------------------------------------------+
| QUERY PLAN                                                                                                                             |
|----------------------------------------------------------------------------------------------------------------------------------------|
| Nested Loop  (cost=0.29..8514.09 rows=27592 width=1412) (actual time=0.017..53.627 rows=27586 loops=1)                                 |
|   ->  Seq Scan on t_xmxx_x a  (cost=0.00..2578.49 rows=6149 width=955) (actual time=0.003..1.977 rows=6149 loops=1)                    |
|   ->  Index Scan using t_shwzcmx_index on t_shwzcmx b  (cost=0.29..0.89 rows=8 width=457) (actual time=0.002..0.005 rows=4 loops=6149) |
|         Index Cond: ((f_xmid)::text = (a.f_xmid)::text)                                                                                |
| Total runtime: 55.362 ms                                                                                                               |
+----------------------------------------------------------------------------------------------------------------------------------------+
EXPLAIN
Time: 0.061s


explain analyze select * from t_xmxx_x a join t_shwzcmx b on a.f_xmid=b.f_xmid;
+----------------------------------------------------------------------------------------------------------------------------------------+
| QUERY PLAN                                                                                                                             |
|----------------------------------------------------------------------------------------------------------------------------------------|
| Nested Loop  (cost=0.29..8514.09 rows=27592 width=1412) (actual time=0.020..53.727 rows=27586 loops=1)                                 |
|   ->  Seq Scan on t_xmxx_x a  (cost=0.00..2578.49 rows=6149 width=955) (actual time=0.002..1.879 rows=6149 loops=1)                    |
|   ->  Index Scan using t_shwzcmx_index on t_shwzcmx b  (cost=0.29..0.89 rows=8 width=457) (actual time=0.002..0.005 rows=4 loops=6149) |
|         Index Cond: ((f_xmid)::text = (a.f_xmid)::text)                                                                                |
| Total runtime: 55.319 ms                                                                                                               |
+----------------------------------------------------------------------------------------------------------------------------------------+
EXPLAIN
Time: 0.061s

data is too small and basically makes no difference
1 million. Try


SELECT * from posts,post_slugs where post_slugs.post_id=posts.post_id
SELECT * from posts join post_slugs on post_slugs.post_id=posts.post_id
these are just two different grammatical ways of writing, meaning and execution are the same.
the first SQL is not filtered through Cartesian product and then where. The following is
select * from (SELECT a.post_id as ida,b.post_id as idb from posts a postcards slugs b) c where c.idafuc.idb;

Menu