Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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..!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
162 views
Welcome To Ask or Share your Answers For Others

1 Answer

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;


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...