mysql 索引配置_Mysql索引配置

我有一张450000排新闻的桌子.

表模式是这样的:

CREATE TABLE IF NOT EXISTS `news` (

`id` int(11) NOT NULL auto_increment,

`cat_id` int(11) NOT NULL,

`title` tinytext NOT NULL,

`content` text NOT NULL,

`date` int(11) NOT NULL,

`readcount` int(11) NOT NULL default '0',

PRIMARY KEY (`id`),

KEY `cat_id` (`cat_id`),

KEY `cat_id_2` (`cat_id`,`id`),

KEY `cat_id_date` (`cat_id`,`date`)

) ENGINE=MyISAM DEFAULT CHARSET=latin5 AUTO_INCREMENT=462679 ;

当我运行如下的sql命令为类别页面的页面“x”获取一些新闻时,如果x超过100则需要超过15秒:

select * news where cat_id='4' order by id desc limit 150000,10;

解释说明它使用“where”和索引“cat_id_2”

在写这个问题时,我还检查了一个更简单的SQL查询,这也花了近一分钟:

select * from haberler order by id desc limit 40000,10;

如果sql如下所示,只需几毫秒:

select * from haberler order by id desc limit 20,10;

我的my.cnf配置是这样的:

skip-locking

skip-innodb

query_cache_limit=1M

query_cache_size=256M

query_cache_type=1

max_connections=30

interactive_timeout=600000

#wait_timeout=5

#connect_timeout=5

thread_cache_size=384

key_buffer=256M

join_buffer=4M

max_allowed_packet=16M

table_cache=1024

record_buffer=1M

sort_buffer_size=64M

read_buffer_size=16M

max_connect_errors=10

# Try number of CPU's*2 for thread_concurrency

thread_concurrency=2

myisam_sort_buffer_size=128M

long_query_time = 1

log_slow_queries = /var/log/mysql/mysql-slow.log

max_heap_table_size=512M

该网站运行在core2duo上,内存为2GB.

我认为问题可能是由sort_buffer_size引起的,但我不确定.

提前致谢.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值