Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
175 views
in Technique[技术] by (71.8m points)

mysql - Expensive full table scan on select all without condition

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

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

1 Reply

0 votes
by (71.8m points)

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;


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...