问题
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