在我的mysql数据库中,行中有100多万行。使用Join查询,我获取了数据库,但是检索数据需要花费更多的时间,使用php中的foreach循环显示数据也需要时间。它显示错误,如程序没有响应。
SQl查询被执行,它需要更多的时间。在编码点火器中显示数据并使用jquery分页,也需要更多的时间来显示。
我现在很快就开始使用Codeigniter分页了。但它显示了SQL中的错误。请找到这个
表格
Table name - catch_estimation
estiamteid int(11) PRI
centerid int(11)
centername varchar(100)
month int(2)
year int(5)
totalcatch int(11)
totalefforts int(11)
totalafh int(11)
noofgears int(11)
created_date datetime
modified_date datetime表名gearwise_estimation
id int(11) NO PRI
estimationid int(11)
centername varchar(50)
gearname varchar(20)
gear_totalefforts int(11)
gear_totalafh int(11)
gear_totalcatch int(11)
$this->db->select('start.*');
$this->db->from('gearwise_estimation');
$this->db->join('catch_estimation', 'gearwise_estimation.estimationid = catch_estimation.estiamteid and year = '.$year);
foreach($month as $mon):
$this->db->like('catch_estimation.month',trim($mon));
endforeach;
foreach($gear as $gr):
$this->db->like('gearwise_estimation.gearname',trim($gr));
endforeach;
foreach($centername as $zo):
$this->db->like('catch_estimation.centerid',trim($zo));
endforeach;
$this->db->order_by("catch_estimation.month", "asc");
$this->db->order_by("catch_estimation.centername", "asc");但它显示了错误
SELECT `start`.* FROM `gearwise_estimation` JOIN `catch_estimation` ON `gearwise_estimation`.`estimationid` = `catch_estimation`.`estiamteid` and `year` = 2018 WHERE catch_estimation.month LIKE '%8%' ESCAPE '!' AND catch_estimation.month LIKE '%9%' ESCAPE '!' AND gearwise_estimation.gearname LIKE '%OBGN%' ESCAPE '!' AND catch_estimation.centerid LIKE '%2%' ESCAPE '!' ORDER BY `catch_estimation`.`month` ASC, `catch_estimation`.`centername` ASC发布于 2019-02-12 01:24:13
如果表中有10个lakhs+行,那么使用DOM级别分页是不可行的。目前,您的分页是从数据库中获取所有10百万行,然后在DOM级别上进行隐藏/显示以形成分页。
您应该在mysql中应用limit子句,然后只获取每页需要的记录。
See this供您参考。
一旦您只显示您需要的数据,那么您就可以通过添加索引来优化更多的数据,使用Explain获取查询执行细节。
发布于 2019-02-13 05:08:34
你至少有INDEX(year)吗?以及每个表中估计值的索引(或主键)?
是否需要所有列(SELECT *)?如果有TEXT或BLOB的话,这会特别昂贵。
您是否试图获取100万行(100万行)?网络可能会窒息。
PHP有一个内存限制,可能会被一次抛出的这么多数据窒息。
如果您首先获取所有的行,分页是相当昂贵的。
如果使用LIMIT和OFFSET,分页也很昂贵。
如果你“记得你停下来的地方”的话,分页是有效的。见http://mysql.rjweb.org/doc.php/pagination。
https://stackoverflow.com/questions/54641504
复制相似问题