Does a full table scan in select * from a join b on a.id=b.a_id?

there are two tables an and a column a_id in bdepartment b that stores table an id as a foreign key and has indexes

select * from a join b on a.id=b.a_id

question 1: is the above sql full table scan for a table and index for table b?

select * from b join a on a.id=b.a_id

question 2: is table b scanned and table a uses index in the above sql (order of an and b before and after join)?

Jul.12,2022

unless you specify the driver table manually ( STRAIGHT_JOIN ), the mysql optimizer will use the least expensive table as the driver table, so the results of the above two statements are the same in no special cases. You can explain and take a look at

.

for the sql given by the subject, if an is a driven table (the number of an is relatively small), then a will scan the whole table and the a_id of b can use the index. When b is the driver table, you can also analyze it in this way


not necessarily the optimizer will judge who makes the driven table and who does the driven table, so the execution of your two statements may be exactly the same


the optimizer determines the driver table itself. If you want to force the driver to use STRAIGHT_JOIN


it is best not to use *


1. It must be a full table scan
2. It also produces Cartesian product

efficiency and its poor.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eae170-21a7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eae170-21a7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?