大家好。我用MySql和ASP.Net做了个小东西。
在我的程序中,有如下的SQL:String strSqlText =
"SELECT AVG(A1) AS avgA1 " +
"FROM tableA " +
"WHERE (date BETWEEN @startDate and @endDate) AND " +
"(time BETWEEN @startTime AND @endTime) AND " +
"(countvalueA BETWEEN @startCountA AND @endCountA) AND " +
"(countvalueB BETWEEN @startCountB AND @endCountB) AND " +
"(countvalueC BETWEEN @startCountC AND @endCountC)";客户端画面每次更新时,假设有300个不同的参数值
(
startCountA1, endCountA1, startCountB1, endCountB1, startCountC1 ,endCountC1;
startCountA2, endCountA2, startCountB2, endCountB2, startCountC2 ,endCountC2;
startCountA3, endCountA3, startCountB3, endCountB3, startCountC3 ,endCountC3;
......
)
被传入上面的语句,通过查询返回300个avgA1.现在的结果是,查询及计算速度非常慢。
如何提高,请经验者指导。谢谢。
在我的程序中,有如下的SQL:String strSqlText =
"SELECT AVG(A1) AS avgA1 " +
"FROM tableA " +
"WHERE (date BETWEEN @startDate and @endDate) AND " +
"(time BETWEEN @startTime AND @endTime) AND " +
"(countvalueA BETWEEN @startCountA AND @endCountA) AND " +
"(countvalueB BETWEEN @startCountB AND @endCountB) AND " +
"(countvalueC BETWEEN @startCountC AND @endCountC)";客户端画面每次更新时,假设有300个不同的参数值
(
startCountA1, endCountA1, startCountB1, endCountB1, startCountC1 ,endCountC1;
startCountA2, endCountA2, startCountB2, endCountB2, startCountC2 ,endCountC2;
startCountA3, endCountA3, startCountB3, endCountB3, startCountC3 ,endCountC3;
......
)
被传入上面的语句,通过查询返回300个avgA1.现在的结果是,查询及计算速度非常慢。
如何提高,请经验者指导。谢谢。
解决方案 »
- mysql存储过程执行一半的奇怪问题
- MySQL触发器写的数据不记录在二进制日志中?
- 一条执行时间超级长的SQL语句,急需高手优化!!!
- 一个关于链接数据库的问题,请教高手
- 为什么数据库不乱码
- 用sql将外键 的更新和删除修改为 casade
- 大家帮小妹看下出了什么错~小妹初学啊 Column count doesn't match value count at row 1; 谢谢 在线等待
- 如何写在字段批量更新记录的语句
- 请教:有没有方法获得Mysql表一条记录按某一字段排序的排序号是多少?
- mysql客户端dos命令行操作的历史记录怎么查询
- 急,mysql大数据量性能优化
- 求系统开发 合同样本
数据库的记录数是1395832。表的结构:
InfoID int Unchecked (primary key)
date nvarchar(8) Unchecked
time varchar(8) Unchecked
countvalueA decimal(10, 0) Unchecked
countvalueB decimal(10, 0) Unchecked
countvalueC decimal(10, 0) Unchecked
如果要建立索引,是否要这样做:
creat index idx_date on tableA(date);
creat index idx_time on tableA(time);
creat index idx_countvalueA on tableA(countvalueA);
creat index idx_countvalueB on tableA(countvalueB);
creat index idx_countvalueC on tableA(countvalueC);
另外,是否用PL/SQL做这样的处理会快一些?
explain 你的SQL语句
date可以为一天,可以为一个星期的,也可以是一个月的。
一个月的数据2600000 x 30--------------------------------
像这样的数据,开始设计时,就应该考虑分区或分表了
否则,你现在优化了,随着日期的增长,也会越来越慢
相对来说,符合date 和 time的记录数最多,
接着是符合(countvalueC BETWEEN @startCountC AND @endCountC)的记录数多,其次是
符合 (countvalueB BETWEEN @startCountB AND @endCountB)的记录数,次之是
符合 (countvalueA BETWEEN @startCountA AND @endCountA)的记录数。该如何建立索引?
create index on .... (countvalueA,countvalueB,countvalueC,date) 最少的放在最前面
http://dev.mysql.com/doc/refman/5.1/zh/partitioning.html
18.1. MySQL中的分区概述
18.2. 分区类型
18.2.1. RANGE分区
18.2.2. LIST分区
18.2.3. HASH分区
18.2.4. KEY分区
18.2.5. 子分区
18.2.6. MySQL分区处理NULL值的方式
18.3. 分区管理
18.3.1. RANGE和LIST分区的管理
18.3.2. HASH和KEY分区的管理
18.3.3. 分区维护
18.3.4. 获取关于分区的信息
select average(XXX) from table where (column = 'parameter')
}
上面的查询,总计循环执行150次,而且每次传进的parameter的数值各不相同。
怎样写才能提高查询速度?
当您的问题得到解答后请及时结贴.
http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html