จาก No2 ที่บอกว่า 5วิ นี้ช้าเกินไปครับ
วันนี้ผมเลยยอมเสียเวลาทดสอบดู ลองทดลองกันจริงๆไปเลย
ผมมีอยู่ 5 ตารางมา join กันครับ
tb1 มี 26 record
tb2 มี 13 record
tb3 มี 10,000 record
tb4 มี 10,000 record
tb5 มี 129,987 record
ลองดูความสัมพันธ์จาก query ด้านล่าง
select *
from tb5
inner join tb4
on tb5.tb4_id=tb4.id
inner join tb3
on tb4.id=tb3.tb4_id
inner join tb2
on tb2.id=tb4.tb2_id
inner joint tb1
on tb1.id=tb4.tb1_id
where tb4.id=5112
ใช้เวลาเฉลี่ย 0.0009 วินาที
ถ้าลอง เลือกแค่ tb5
select * from tb5 where id=5112
ใช้เวลาเฉลี่ย 0.0005 วินาที