Home > database >  Select inner join multiple tables of the federated query efficiency
Select inner join multiple tables of the federated query efficiency

Time:09-27

The first:
Select a4. * from a1
Inner join a2 on a1. Ordernum=a2. Reqorderid
Inner join a3 on a2. Orderid=a3. Orderno
Inner join a4 on a3. Id=a4. Orderid
Where a1. Num='888464' and a1. Operdate='20180719'
Query results time: 16 seconds

The second:
Select a4. * from (
The select a3. Id from a1
Inner join a2 on a1. Ordernum=a2. Reqorderid
Inner join a3 on a2. Orderid=a3. Orderno
Where a1. Num='888464' and a1. Operdate a3='20180719')
Inner join a4 on a3. Id=a4. Orderid
Query results time: 0.3 seconds

Relevant indexing, block_nested_loop=on

Explain the first written
1 SIMPLE a1 ref index_name index_ordernum, index_mercnum index_name 152 4124 Using const index condition; Using the where
1 SIMPLE a2 ref index_ord_3, index_ord_1 index_ord_1 oss. 93 a1. Ordernum 1 Using index condition
1 SIMPLE a4 ALL index_so_orderid 164750 Using the where; Using the join buffer (Block Nested Loop)
1 SIMPLE a3 eq_ref PRIMARY, index_sto_orderno PRIMARY 8 mall. A4. Orderid 1 Using the where

Excuse me Daniel, this is what causes, how should solve?
  • Related