问题
I have a wide table with 210 columns (This might be a bad structure but all data is needed every time). There is a primary type index for the primary key.
Now when I do select * from my single table without any condition. It results in a full table scan.
It says the following: no useable indexes were found for the table
This also means the search range is so broad that the index is useless.
What could I do to avoid this full table scan?
Note: I need all the information every time so breaking the table will result in less performance..!
I am new to MySQL. So help would be appreciated. Thanks..!
回答1:
Refer below link for more details
https://dev.mysql.com/doc/refman/8.0/en/table-scan-avoidance.html
cause of full table scan is below
The table is so small that it is faster to perform a table scan than to bother with a key lookup. This is common for tables with fewer than 10 rows and a short row length.
There are no usable restrictions in the ON or WHERE clause for indexed columns.
You are comparing indexed columns with constant values and MySQL has calculated (based on the index tree) that the constants cover too large a part of the table and that a table scan would be faster
You are using a key with low cardinality (many rows match the key value) through another column. In this case, MySQL assumes that by using the key it probably will do many key lookups and that a table scan would be faster.
to avoid full table scan use below:
- Use ANALYZE TABLE tbl_name to update the key distributions for the scanned table.
Use FORCE INDEX for the scanned table to tell MySQL that table scans are very expensive compared to using the given index:
e.g. SELECT * FROM t1, t2 FORCE INDEX (index_for_column) WHERE t1.col_name=t2.col_name;
来源:https://stackoverflow.com/questions/57286511/expensive-full-table-scan-on-select-all-without-condition