Home > database >  About leftjoin on how to optimize the full table scan problem
About leftjoin on how to optimize the full table scan problem

Time:09-26

Left the join on the heel or more conditions, SQL for several seconds,

The code
The SELECT gar. *, SGR is_prepay, GSR. Is_prepay as gsr_is_prepay, SGR. Goods_pre_id as sgr_goods_pre_id, GSR. Goods_pre_id as gsr_goods_pre_id, gs. Id as goods_id, gs, goods_name, gs. Img, killing the username, gs. Module_id, killing merchant_id, killing short_name as merchant_short_name, killing phone as merchant_phone FROM ` gift_all_record ` gar
LEFT the JOIN ` send_gift_record ` SGR ON gar. Send_gift_record_id=SGR. Id
LEFT the JOIN ` gift_share_record ` GSR ON gar. Gift_share_record_id=GSR. Id
LEFT the JOIN ` goods_gift_code ` GGC ON gar. Goods_gift_code_id=GGC. Id
LEFT the JOIN ` break ` killing ON gar. Merchant_id=killing merchant_id
LEFT the JOIN ` goods ` gs ON SGR. Goods_id=$id OR GSR. Goods_id=$id OR GGC, goods_id=$id
WHERE 1 GROUP BY gar. Id ORDER BY gar. Create_time desc limit 0, 10



With the union and the duplicate data, how to optimize well,

CodePudding user response:

The volume of goods list, please? Whether there is an index on the id column?

CodePudding user response:

I only know that test development of library goods data volume is not large, online don't know, id have indexed, leftjoin on not the or soon after

CodePudding user response:

Can send_gift_record gift_share_record, goods_gift_code three tables union together to connect, so you don't use the OR

CodePudding user response:

references conveniently and reply to 1:3/f
can send_gift_record, gift_share_record, goods_gift_code three tables union together to connect, so you don't use the OR

This is currently processing, high efficiency a lot
  • Related