求MYSQL 负载优化方案。
求MYSQL 负载优化方案。(PHP+mysql开发的)
比如 我有个表 table 有大概 50W 左右的记录,
使用limit 实现PHP的分页时候,就非常卡,经常脚本超时
后来发现了一种方案 ,用比较法
select * from table
where id >= ( select id from table limit 1,1) limit 20
这种
但是这种试过了 ,,如果进行复杂的where 或者非索引的字段进行 order by 操作 性能照样 差得很
不知道,哪位高手有好的方案,?
用存储过程实现分页?还是其他什么呢??
谢谢 。。。
如果 你将 limit 500,50
后面那个 offset 值设置在大点就很慢了 哦。。。
我是在研究 这个 PHP+MYSQL 分页的时候 的执行效率。。。
测试如下. 好象没有你所说的问题。 建议你给出你的查询语句,否则别人无法模拟理解你的问题。
SQL code:
mysql> select SQL_NO_CACHE id,col from t1 order by id limit 000000,50;
+----+------+
| id | col |
+----+------+
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
| 50 | 50 |
+----+------+
50 rows in set (0.00 sec)
mysql> select SQL_NO_CACHE id,col from t1 order by id limit 10000,50;
+-------+-------+
| id | col |
+-------+-------+
| 10001 | 10001 |
| 10002 | 10002 |
| 10003 | 10003 |
| 10050 | 10050 |
+-------+-------+
50 rows in set (0.03 sec)
mysql> select SQL_NO_CACHE id,col from t1 order by id limit 20000,50;
+-------+-------+
| i
相关问答:
我是用mysql自带的C API
if(mysql_real_connect(&mysql,"125.0.0.108","root","root","home",3306,NULL,0))
{
AfxMessageBox("数据库连接失败") ......
Winform+MySQL做项目,在注重性能的情况下,我该如何去完成这类型的项目呢!
请各位给以提示。
你这个范围太广了,我说2点重要的吧
1.WINFORM程序是单独运行的CS程序,和BS不同,BS的压力始终都在SERVER上的,对C ......
建表:插记录
SQL code:
create table tablename (id int,RQ1 datetime,RQ2 datetime)
-- select * from tablename
insert into tablename
select 1,'2009-01-01 10:00:00','2009-01-02 11:00:00' union
......
SQL code:
create PROCEDURE aa(SqlCMD1 varchar(8000),SqlCMD2 varchar(8000),SqlCMD3 varchar(8000))
begin
declare exit handler for sqlexception rollback;
start TRANSACTION;
EXECUTE SqlCMD1;
EXE ......
请高手指点,我对一张表查询后再更新,查询是子查询,报错:
You can't specify target table 'a_table' for update in from clause
完整SQL语句是
UPDATE a_table SET STATUS=0 WHERE ID=(SELECT MIN(ID) from a_tab ......