TAILIEUCHUNG - Pro MySQL experts voice in open source phần 5

Tham khảo tài liệu 'pro mysql experts voice in open source phần 5', công nghệ thông tin, cơ sở dữ liệu phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 276 CHAPTER 7 ESSENTIAL SQL If you felt that a more efficient join order would be to use the order given in the SELECT statement you would use the STRAIGHT_JOIN hint as shown in Listing 7-37. Listing 7-37. Example of the STRAIGHT_JOINHint mysql EXPLAIN - SELECT - FROM Category c - STRAIGHTJOIN Product2Category p2c - STRAIGHTJOIN Product p - WHERE LIKE VideO - AND - AND G 1. row id 1 select_type SIMPLE table c type ALL possible_keys PRIMARY key NULL key_len NULL ref NULL rows 14 Extra Using where 2. row id 1 select_type SIMPLE table p2c type index possible_keys PRIMARY key PRIMARY key_len 8 ref NULL rows 8 Extra Using where Using index 3. row id 1 select_type SIMPLE table p type eq_ref possible_keys PRIMARY key PRIMARY key_len 4 ref rows 1 Extra 3 rows in set sec CHAPTER 7 ESSENTIAL SQL 277 As you can see MySQL dutifully follows your desired join order. The access pattern it comes up with in this case is suboptimal compared with the original MySQL-chosen access path. Where in the original EXPLAIN from Listing 7-36 you see MySQL using ref and eq_ref access types for the joins to Product2Category and Category in the STRAIGHT_JOIN EXPLAIN Listing 7-37 you see MySQL has reverted to using an index scan on Product2Category and an eq_ref to access Product. In this case the STRAIGHT_JOIN made things worse. In most cases MySQL will indeed choose the most optimal pattern for accessing tables in your SELECT statements. However if you encounter a situation in which you suspect a different order would produce speedier results you can use this technique to test your theories. Caution If you do find a situation in which you suspect changing the join order would speed up a query make sure that MySQL is using up-to-date statistics on your table before making any changes. After you run a baseline EXPLAIN to see MySQL s chosen access strategy for your query run an ANALYZE TABLE against the .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.