社区
基础编程
帖子详情
15万条数据的查询
szdhsoft
2011-05-08 09:44:40
数据库:mysql.
数据记录:158000条
对数据进行查询统计,统计费用字段,按时间段和区域进行横向统计。
查询的时候PHP页面显示超时。大概有一分钟的样子。
请问有没有更好的办法解决速度问题????
...全文
301
19
打赏
收藏
15万条数据的查询
数据库:mysql. 数据记录:158000条 对数据进行查询统计,统计费用字段,按时间段和区域进行横向统计。 查询的时候PHP页面显示超时。大概有一分钟的样子。 请问有没有更好的办法解决速度问题????
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
19 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
quanzi0214
2011-05-10
打赏
举报
回复
优化数据库吧,最好把时间字段用时间戳保存,int做索引还是很快的!优化得当0.1秒内绝对能查询完成!
转身
2011-05-09
打赏
举报
回复
你自己可以用explain来看看sql语句的好坏
转身
2011-05-09
打赏
举报
回复
表documents中加一个trans_fee,start_station,end_station的联合索引
转身
2011-05-09
打赏
举报
回复
首先这句'select ID from start_station order by id asc' 把order by id asc去掉,数据库默认就是升序的,使用order by很难用到索引,并且速度慢很多
kaifadi
2011-05-09
打赏
举报
回复
是SQL语句问题,像楼上所说。开始的查询并没有条件。等于15万的ID一起获得。
而且这个mysql_db_query在PHP4以后就不推荐使用了。你的代码里居然还在使用。用
mysql_select_db和mysql_query来代替它,具体用法百度找下。很简单的。
helloyou0
2011-05-09
打赏
举报
回复
所有表的表结构,
你里面多个表,哪个的数据是15万?
其它表里数据多少?
查这种性能问题,最好是自己做测试,不要想当然,
查出具体哪一部分的速度太慢,再做优化,
黄袍披身
2011-05-09
打赏
举报
回复
1.检查一下硬盘
2.优化一下 MYSQL.INI
3.检查一下自己的SQL语句 尽量不要使用 LIKE
...
szdhsoft
2011-05-09
打赏
举报
回复
<tr>
<td align="center" bgcolor="#CCCCCC"><strong>代收款</strong></td>
<?
mysql_data_seek($result,0);
while($row10=mysql_fetch_array($result))
{
?>
<td align="center" bgcolor="#FFFFFF"><?
$sql2='select sum(dai_fee) from documents where start_station='.$row10['ID'].' and end_station='.$end_station.' and (create_date between \''.$tj_date.'\' and \''.$tj_date2.'\')';
$result2=mysql_db_query($MYSQL_DB,$sql2,$conn);
$row2=mysql_fetch_row($result2);
if($row2[0]==NULL)
{
echo '0';
}
else
{
echo $row2[0];
}
mysql_free_result($result2);
?></td>
<?
}
?>
<td align="center" bgcolor="#FFFFFF"><?
//代收总计
$sql3='select sum(dai_fee) from documents where (create_date between \''.$tj_date.'\' and \''.$tj_date2.'\') and end_station='.$end_station;
$result3=mysql_db_query($MYSQL_DB,$sql3,$conn);
$row3=mysql_fetch_row($result3);
if($row3[0]==NULL)
{
echo '0';
}
else
{
echo $row3[0];
}
mysql_free_result($result3);
?></td>
</tr>
<tr>
<td align="center" bgcolor="#CCCCCC"><strong>垫代合计</strong></td>
<?
mysql_data_seek($result,0);
//进行垫贷合计统计
if($_POST['end_station']==NULL)
{
$end_station=1;
}
else
{
$end_station=$_POST['end_station'];
}
while($row10=mysql_fetch_array($result))
{
?>
<td align="center" bgcolor="#FFFFFF">
<?
$sql2='select sum(dian_fee)+sum(dai_fee) from documents where (create_date between \''.$tj_date.'\' and \''.$tj_date2.'\') and start_station='.$row10['ID'].' and end_station='.$end_station;
$result2=mysql_db_query($MYSQL_DB,$sql2,$conn);
$row2=mysql_fetch_row($result2);
if($row2[0]==NULL)
{
echo '0';
}
else
{
echo $row2[0];
}
mysql_free_result($result2);
?> </td>
<?
}
?>
<td align="center" bgcolor="#FFFFFF">
<?
//提付总计
$sql3='select sum(dian_fee)+sum(dai_fee) from documents where (create_date between \''.$tj_date.'\' and \''.$tj_date2.'\') and end_station='.$end_station;
$result3=mysql_db_query($MYSQL_DB,$sql3,$conn);
$row3=mysql_fetch_row($result3);
if($row3[0]==NULL)
{
echo '0';
}
else
{
echo $row3[0];
}
mysql_free_result($result3);
?></td>
</tr>
<tr>
<td align="center" bgcolor="#CCCCCC"><strong>送 货</strong></td>
<?
mysql_data_seek($result,0);
//进行提付统计
if($_POST['end_station']==NULL)
{
$end_station=1;
}
else
{
$end_station=$_POST['end_station'];
}
while($row10=mysql_fetch_array($result))
{
?>
<td align="center" bgcolor="#FFFFFF">
<?
$sql2='select sum(send_fee) from documents where (create_date between \''.$tj_date.'\' and \''.$tj_date2.'\') and start_station='.$row10['ID'].' and end_station='.$end_station;
$result2=mysql_db_query($MYSQL_DB,$sql2,$conn);
$row2=mysql_fetch_row($result2);
if($row2[0]==NULL)
{
echo '0';
}
else
{
echo $row2[0];
}
mysql_free_result($result2);
?> </td>
<?
}
?>
<td align="center" bgcolor="#FFFFFF">
<?
//提付总计
$sql3='select sum(send_fee) from documents where (create_date between \''.$tj_date.'\' and \''.$tj_date2.'\') and end_station='.$end_station;
$result3=mysql_db_query($MYSQL_DB,$sql3,$conn);
$row3=mysql_fetch_row($result3);
if($row3[0]==NULL)
{
echo '0';
}
else
{
echo $row3[0];
}
mysql_free_result($result3);
?></td>
</tr>
<tr>
<td align="center" bgcolor="#CCCCCC"><strong>总 计</strong></td>
<?
mysql_data_seek($result,0);
//进行现金总统计
if($_POST['end_station']==NULL)
{
$end_station=1;
}
else
{
$end_station=$_POST['end_station'];
}
while($row10=mysql_fetch_array($result))
{
?>
<td align="center" bgcolor="#FFFFFF">
<?
$sql2='select sum(trans_fee)-sum(send_fee) from documents where (create_date between \''.$tj_date.'\' and \''.$tj_date2.'\') and start_station='.$row10['ID'].' and end_station='.$end_station;
$result2=mysql_db_query($MYSQL_DB,$sql2,$conn);
$row2=mysql_fetch_row($result2);
if($row2[0]==NULL)
{
echo '0';
}
else
{
echo $row2[0];
}
mysql_free_result($result2);
?> </td>
<?
}
?>
<td align="center" bgcolor="#FFFFFF">
<?
//提付总计
$sql3='select sum(trans_fee)-sum(send_fee) from documents where (create_date between \''.$tj_date.'\' and \''.$tj_date2.'\') and end_station='.$end_station;
$result3=mysql_db_query($MYSQL_DB,$sql3,$conn);
$row3=mysql_fetch_row($result3);
if($row3[0]==NULL)
{
echo '0';
}
else
{
echo $row3[0];
}
mysql_free_result($result3);
?></td>
</tr>
</table>
<form name="form2" method="post" action="print.php" style="text-align:right" target="_blank">
<input name="tj_date" type="hidden" id="tj_date" value="<?=$tj_date?>">
<input name="tj_date2" type="hidden" id="tj_date2" value="<?=$tj_date2?>">
<input name="end_station" type="hidden" id="end_station" value="<?=$_POST['end_station']?>">
<input type="submit" name="Submit2" value="打印输出报表">
</form>
</fieldset>
</body>
</html>
szdhsoft
2011-05-09
打赏
举报
回复
</td>
<?
}
?>
<td align="center" bgcolor="#FFFFFF">
<?
//回单总计
$sql3='select sum(trans_fee) from documents where (create_date between \''.$tj_date.'\' and \''.$tj_date2.'\') and pay_type=\'回单\' and end_station='.$end_station;
$result3=mysql_db_query($MYSQL_DB,$sql3,$conn);
$row3=mysql_fetch_row($result3);
if($row3[0]==NULL)
{
echo '0';
}
else
{
echo $row3[0];
}
mysql_free_result($result3);
?></td>
</tr>
<tr>
<td align="center" bgcolor="#CCCCCC"><strong>现 付</strong></td>
<?
mysql_data_seek($result,0);
//进行收现金统计
if($_POST['end_station']==NULL)
{
$end_station=1;
}
else
{
$end_station=$_POST['end_station'];
}
while($row8=mysql_fetch_array($result))
{
?>
<td align="center" bgcolor="#FFFFFF">
<?
$sql2='select sum(trans_fee) from documents where start_station='.$row8['ID'].' and end_station='.$end_station.' and pay_type=\'现付\' and (create_date between \''.$tj_date.'\' and \''.$tj_date2.'\')';
$result2=mysql_db_query($MYSQL_DB,$sql2,$conn);
$row2=mysql_fetch_row($result2);
if($row2[0]==NULL)
{
echo '0';
}
else
{
echo $row2[0];
}
mysql_free_result($result2);
?> </td>
<?
}
?>
<td align="center" bgcolor="#FFFFFF">
<?
//现金总计
$sql3='select sum(trans_fee) from documents where (create_date between \''.$tj_date.'\' and \''.$tj_date2.'\') and pay_type=\'现付\' and end_station='.$end_station;
$result3=mysql_db_query($MYSQL_DB,$sql3,$conn);
$row3=mysql_fetch_row($result3);
if($row3[0]==NULL)
{
echo '0';
}
else
{
echo $row3[0];
}
mysql_free_result($result3);
?></td>
</tr>
<tr>
<td align="center" bgcolor="#CCCCCC"><strong>合 计</strong></td>
<?
mysql_data_seek($result,0);
//进行收现金与回单合计统计
if($_POST['end_station']==NULL)
{
$end_station=1;
}
else
{
$end_station=$_POST['end_station'];
}
while($row9=mysql_fetch_array($result))
{
?>
<td align="center" bgcolor="#FFFFFF">
<?
$sql2='select sum(trans_fee) from documents where start_station='.$row9['ID'].' and end_station='.$end_station.' and (pay_type=\'现付\' or pay_type=\'回单\') and (create_date between \''.$tj_date.'\' and \''.$tj_date2.'\')';
$result2=mysql_db_query($MYSQL_DB,$sql2,$conn);
$row2=mysql_fetch_row($result2);
if($row2[0]==NULL)
{
echo '0';
}
else
{
echo $row2[0];
}
mysql_free_result($result2);
?> </td>
<?
}
?>
<td align="center" bgcolor="#FFFFFF">
<?
//现金与回单总计
$sql3='select sum(trans_fee) from documents where (create_date between \''.$tj_date.'\' and \''.$tj_date2.'\') and (pay_type=\'现付\' or pay_type=\'回单\') and end_station='.$end_station;
$result3=mysql_db_query($MYSQL_DB,$sql3,$conn);
$row3=mysql_fetch_row($result3);
if($row3[0]==NULL)
{
echo '0';
}
else
{
echo $row3[0];
}
mysql_free_result($result3);
?></td>
</tr>
<tr>
<td align="center" bgcolor="#CCCCCC"><strong>提 付</strong></td>
<?
mysql_data_seek($result,0);
//进行提付统计
if($_POST['end_station']==NULL)
{
$end_station=1;
}
else
{
$end_station=$_POST['end_station'];
}
while($row10=mysql_fetch_array($result))
{
?>
<td align="center" bgcolor="#FFFFFF">
<?
$sql2='select sum(trans_fee) from documents where start_station='.$row10['ID'].' and end_station='.$end_station.' and pay_type=\'提付\' and (create_date between \''.$tj_date.'\' and \''.$tj_date2.'\')';
$result2=mysql_db_query($MYSQL_DB,$sql2,$conn);
$row2=mysql_fetch_row($result2);
if($row2[0]==NULL)
{
echo '0';
}
else
{
echo $row2[0];
}
mysql_free_result($result2);
?> </td>
<?
}
?>
<td align="center" bgcolor="#FFFFFF">
<?
//提付总计
$sql3='select sum(trans_fee) from documents where (create_date between \''.$tj_date.'\' and \''.$tj_date2.'\') and pay_type=\'提付\' and end_station='.$end_station;
$result3=mysql_db_query($MYSQL_DB,$sql3,$conn);
$row3=mysql_fetch_row($result3);
if($row3[0]==NULL)
{
echo '0';
}
else
{
echo $row3[0];
}
mysql_free_result($result3);
?></td>
</tr>
<tr>
<td align="center" bgcolor="#CCCCCC"><strong>垫付款</strong></td>
<?
mysql_data_seek($result,0);
while($row10=mysql_fetch_array($result))
{
?>
<td align="center" bgcolor="#FFFFFF">
<?
$sql2='select sum(dian_fee) from documents where start_station='.$row10['ID'].' and end_station='.$end_station.' and (create_date between \''.$tj_date.'\' and \''.$tj_date2.'\')';
$result2=mysql_db_query($MYSQL_DB,$sql2,$conn);
$row2=mysql_fetch_row($result2);
if($row2[0]==NULL)
{
echo '0';
}
else
{
echo $row2[0];
}
mysql_free_result($result2);
?>
</td>
<?
}
?>
<td align="center" bgcolor="#FFFFFF"><?
//垫付总计
$sql3='select sum(dian_fee) from documents where (create_date between \''.$tj_date.'\' and \''.$tj_date2.'\') and end_station='.$end_station;
$result3=mysql_db_query($MYSQL_DB,$sql3,$conn);
$row3=mysql_fetch_row($result3);
if($row3[0]==NULL)
{
echo '0';
}
else
{
echo $row3[0];
}
mysql_free_result($result3);
?></td>
</tr>
szdhsoft
2011-05-09
打赏
举报
回复
<?
include_once('conn.php');
include_once('../include/calendar.php');
$sql='select ID,station_name from end_station';
$result=mysql_db_query($MYSQL_DB,$sql,$conn);
if($_POST['tj_date']==NULL)
{
$tj_date=date('Y-m-d',time());
}
else
{
$tj_date=$_POST['tj_date'];
}
if($_POST['tj_date2']==NULL)
{
$tj_date2=date('Y-m-d',time());
}
else
{
$tj_date2=$_POST['tj_date2'];
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>..:: 货运运单管理系统 ::..正式版</title>
<link href="../system/images/style.css" rel="stylesheet" type="text/css">
<style type="text/css">
table{background-color:#999999;}
td{height:22px;padding:5px;}
</style>
</head>
<body>
<div id="page-header"><img src="images/font_win.gif" width="16" height="16">当前位置:报表中心>日收货量及线路明细汇总</div>
<center>
<fieldset style="width:99%; padding:5px;">
<legend>统计条件</legend>
<form name="form1" method="post" action="tj.php" style="text-align:left;">
<strong>开始日期:</strong>
<input name="tj_date" type="text" id="tj_date" onClick="fPopCalendar(tj_date,tj_date);return false">
<strong>结束日期:</strong>
<input name="tj_date2" type="text" id="tj_date2" onClick="fPopCalendar(tj_date2,tj_date2);return false">
<strong>线路:</strong>
<select name="end_station" id="end_station">
<option value="0">==选择线路==</option>
<?
while($row=mysql_fetch_array($result))
{
?>
<option value="<?=$row['ID']?>"><?=$row['station_name']?></option>
<?
}
mysql_free_result($result);
?>
</select>
<input type="submit" name="Submit" value="统计">
</form>
</fieldset>
<fieldset style="width:99%; padding:5px;text-align:left;">
<legend>统计结果</legend>
<?
$sql='select ID from start_station order by id asc';
$result=mysql_db_query($MYSQL_DB,$sql,$conn);
?>
<div style="width:90%; text-align:left; height:15px;padding:10px;"><strong>线路:
<?
if($_POST['end_station']==NULL)
{
$sql5='select station_name from end_station where id=1';
}
else
{
$sql5='select station_name from end_station where id='.$_POST['end_station'];
}
$result5=mysql_db_query($MYSQL_DB,$sql5,$conn);
$row5=mysql_fetch_array($result5);
echo $row5['station_name'];
mysql_free_result($result5);
echo " 统计日期:".$tj_date." 到 ".$tj_date2;
?></strong>
</div>
<table width="90%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td bgcolor="#FFFFFF"> </td>
<?
while($row=mysql_fetch_array($result))
{
?>
<td align="center" bgcolor="#CCCCCC"><strong>
<?=$row['station_name']?>
</strong></td>
<?
}
mysql_data_seek($result,0);
?>
<td align="center" bgcolor="#CCCCCC"><strong>总计</strong></td>
</tr>
<tr>
<td align="center" bgcolor="#CCCCCC"><strong>回 单</strong></td>
<?
//进行回单统计
if($_POST['end_station']==NULL)
{
$end_station=1;
}
else
{
$end_station=$_POST['end_station'];
}
while($row1=mysql_fetch_array($result))
{
?>
<td align="center" bgcolor="#FFFFFF">
<?
$sql2='select sum(trans_fee) from documents where start_station='.$row1['ID'].' and end_station='.$end_station.' and pay_type=\'回单\' and (create_date between \''.$tj_date.'\' and \''.$tj_date2.'\')';
$result2=mysql_db_query($MYSQL_DB,$sql2,$conn);
$row2=mysql_fetch_row($result2);
if($row2[0]==NULL)
{
echo '0';
}
else
{
echo $row2[0];
}
mysql_free_result($result2);
?>
kaifadi
2011-05-09
打赏
举报
回复
上千万的数据查询对MYSQL来说也是秒级的,你的15万居然要1分多钟,估计是卡住了吧。
重起MYSQL看看是否问题依旧,能否把完整的SQL语句发来看看呢?
朽Kee木
2011-05-09
打赏
举报
回复
顶着,期待优化的方案....嘿嘿
natici
2011-05-09
打赏
举报
回复
另外,没发现lz的sql语句里面有limit限制查询条数,难道要一次性把15w条数据都读出来?
wasuka
2011-05-08
打赏
举报
回复
优化做到位,15万数据的查询0.1秒不到
szdhsoft
2011-05-08
打赏
举报
回复
关键的问题是客户想一点就要出来,10秒以内的样子。
乌镇程序员
2011-05-08
打赏
举报
回复
15万条记录一点都不算多,果断优化表结构和查询语句吧。
http://dev.mysql.com/doc/refman/5.1/zh/optimization.html
baoxiaohua
2011-05-08
打赏
举报
回复
做这个我还蛮有经验的!
首先需要对数据库进行优化,包括建立索引,字段类型,长度等
其次是需要对SQL语句进行优化,避免用外联表或者多表查询等
第三如果可以的话用存储过程会快很多
其实15万条不算大,怎么会那么慢呢,超过一分钟,就把脚步响应时间调长一些了。
PowerBI系列之Online Service在线版专题
PowerBI系列之Online Service在线版专题1. 在线版界面介绍2. 申请Pro和Premium Per User试用3. PowerBI不同账号的区别4. 发布Desktop报表到在线版5. 创建和管理Workspace工作区:普通和Premium工作区6. 报表相关操作:创建报表、文件选项、下载pbix文件、发送Teams聊天、邮箱订阅、编辑报表、报表使用情况报告、报表Lineage血缘关系、恢复到默认、书签、页面大小、刷新、注释、收藏7. 报表导出:在Excel中分析、导出为PPT或PDF图表
数据
导出与限制:在线版
15
万,DS中3万,汇总和明细在报表设置中更改拷贝PBI图表到其他文件中8.
数据
集相关:创建报表、获取快速见解、RLS安全性管理(Dataset
数据
集定时刷新和Dataflow
数据
流在Gateway专题中讲解)9. 分享报表给组织内部账号和管理权限报表使用者在与我共享中查看别人分享的报表分享报表给组织外部账号-先添加来宾用户10. 将报表发布到公共网络11. 仪表板相关:将图表固定到仪表板、仪表板布局、主题切换和移动布局、添加磁贴、智能问答、管理警报、分享仪表板(同报表)12. 报表通过URL传参访问和过滤
数据
13. 在线版上获取
数据
14. 发布和获取应用
15
. 部署管道Pipeline16. 学习中心、下载中心-了解和帮助17. 管理门户介绍-租户设置
java
查询
几
万条
数据
_java一次性
查询
几十万,几百万
数据
解决办法
java一次性
查询
几十万,几百万
数据
解决办法java
查询
一次性
查询
几十万,几百万
数据
解决办法很早的时候写工具用的一个办法。当时是用来把百万
数据
打包 成rar文件。所以用了个笨办法。 希望高手指导一下,有什么好方法没有啊1、先批量查出所有
数据
,例子中是一
万条
一批。2、在查出
数据
之后把每次的
数据
按一定规则存入本地文件。3、获取
数据
时,通过批次读取,获得大批量
数据
。此方法参见:http://yijian...
tidb 1000
万条
数据
查询
速度体验 tidb
查询
速度测试
tidb 1000
万条
数据
查询
速度体验 tidb
查询
速度测试
记一次500
万条
数据
查询
的优化
1.公司业务系统
数据
平台今早发现有个接口响应很慢,经过逐一排查后,发现问题所在。该接口是做的一个单表
查询
,表的
数据
有500
万条
左右。 下面是表结构 下面是优化前的
查询
SELECT count(IP) as uvCount,visitDate from ( select v.IP,DATE_FORMAT(v.CREATE_DATE,'%Y-%m') as visitDate fro...
mysql测试索引200
万条
数据
mysql测试索引200
万条
数据
基础编程
21,886
社区成员
140,364
社区内容
发帖
与我相关
我的任务
基础编程
从PHP安装配置,PHP入门,PHP基础到PHP应用
复制链接
扫一扫
分享
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章