Very big data in mysql table. Even select statements take much time

梦想与她 提交于 2019-12-03 17:25:26

A common practice is, if you have huge amount of data, you ...

  1. should not SELECT * : You should only select the columns you want
  2. should Limit your fetch range to a smaller number: I bet you won't handle 50000 records at the same time. Try to fetch it batch by batch.

A common problem many database administrators face. The solution: Caching.

Break the Queries into more simpler and small queries. Use Memcached or other caching techniques and tools Memcached saves key vaue pairs, check for a data in memcache..if available, use it. If not fetch it from database and then use and cach. Next tie the data will be available from cahe.

You will have to develop own logic and change some queries. Memcached is available here:

http://memcached.org/

Many tutorials are available on the Web

enable in your my.conf the slow queries up to N seconds, then execute some queries and watch this log, this gives you some clues and maybe you could add some indexes to this table.

or do some queries with EXPLAIN. http://hackmysql.com/case1

A quick note that is usually an easy win ...

If you have any columns that are large text blobs, try selecting everything except for those fields. I've seen varchar(max) fields absolutely kill query efficiency.

You have a very wide average row size and 35 columns. You could try vertically partitioning the table, that is, split the table up into smaller tables that are related to each other 1:1 with a subset of columns from the table. InnoDB stores rows in pages and is not efficient for very wide rows.

If the data is append-only consider looking at ICE.

You might also look at TokuDB because it supports good compression.

You can consider using partitioning and Shard-Query (http://code.google.com/p/shard-query) to access data in parallel. You can also split data over more than one server for parallelism using Shard-Query.

Try adding WHERE clause: WHERE 1=1 If it doesn't give any effect then you should change your engine type to MyISAM.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!