CodeIgniter - How to SELECT all rows in a big table without memory leake

对着背影说爱祢 提交于 2021-01-28 06:15:55

问题


It's kinda hard to undertsand my need in the title.

CodeIgniter is performing a SELECT query in a table of 800,000+ rows in one shot.

It takes a lot of memory, but in one specific server, I get a "Out of memory" fatal error.

For performance purposes, I would like to seperate the select into 2 selects, and more specifically, the 50% first rows, and then the 50% left.

I reuse this set of data to perform an INSERT afterwise.

How to do that without losing/forgetting any single row ?


回答1:


Beside the fact that operations like that are highly connected to performance issues, you can use unbuffered_row.

Basically, if you have a job with that large data - you should use unbuffered_row provided and integrated in the built in query builder.

its very well documented here in the result rows section.

for example:

$query = $this->db->select('*')->from('your_table')->get();

while($row = $query->unbuffered_row())
{
    //do your job
}

This will avoid your memory problem.



来源:https://stackoverflow.com/questions/59665243/codeigniter-how-to-select-all-rows-in-a-big-table-without-memory-leake

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!