TAILIEUCHUNG - MySQL Administrator's Bible- P14

MySQL Administrator's Bible- P14: Với tập trung đặc biệt vào việc phát hành lớn tiếp theo của MySQL, nguồn tài nguyên này cung cấp một khuôn khổ vững chắc cho bất cứ ai mới vào MySQL hoặc chuyển từ một nền tảng cơ sở dữ liệu, cũng như các quản trị MySQL kinh nghiệm. Các bộ đôi tác giả cao hồ sơ cung cấp bảo hiểm thiết yếu của các nguyên tắc cơ bản của phạm vi bảo hiểm cơ sở dữ liệu quản lý, bao gồm cả cách tiếp cận độc đáo MySQL của các tính năng cơ sở. | Query Analysis and Index Tuning 18 The reason this is a full table scan is that there are no suitable indexes to use. We can use the INFORMATION_SCHEMA table STATISTICS to show all the indexes on the rental table mysql SELECT COLUMN_NAME INDEX_NAME SEQ_IN_INDEX AS pos - FROM - WHERE TABLE_SCHEMA sakila AND TABLE_NAME rental --------------- --------------------- --- COLUMN_NAME INDEX_NAME pos --------------- --------------------- --- rental_id PRIMARY 1 rental_date rental_date 1 inventory_id rental_date 2 customer_id rental_date 3 inventory_id idx_fk_inventory_id 1 customer_id idx_fk_customer_id 1 staff_id idx_fk_staff_id 1 --------------- --------------------- --- 7 rows in set sec There is no index that includes the return_date field so add an index to optimize this query mysql USE sakila Database changed mysql ALTER TABLE rental ADD INDEX return_date Query OK 16044 rows affected sec Records 16044 Duplicates 0 Warnings 0 mysql EXPLAIN SELECT return_date FROM rental G 1. row id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE rental index NULL return_date 9 NULL 16249 Using index 1 row in set sec Now the type is index which means a full scan of an index is being done. The index being scanned is the return_date index key which we just created with a length key_len of 9. Is there a way to further optimize this query Looking at Table 18-1 data access strategy types below index involve using only parts of an index. The query we are analyzing returns every value of the return_date field. Therefore there is no way to avoid accessing every value in the return_date index. mysqld needs to 617 Part IV Extending Your Skills access a value in order to return it and every value is returned so every value must be accessed. This need to access every value is also shown by the lack of Using where in the Extra field. Index consequences In Chapter 6 we explained how indexes work. Indexes can make data retrieval .

TỪ KHÓA LIÊN QUAN
Đã 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.