Forum Moderators: coopster
$arr = mysqli_fetch_all($sth);
$count = count($arr); PHP Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 72 bytes) in ...
SELECT tableA.id, tableB.which, updated, subject, firstname, lastname, size, intro
FROM tableA
LEFT JOIN tableB
ON tableA.id = tableB.id
WHERE (tableB.which = '%s' OR tableB.which = '%s')
AND tableA.id > 12345
ORDER BY tableA.updated DESC TABLE | TYPE | POSSIBLE_KEYS | KEY | KEY_LEN | REF | ROWS | EXTRA
tableA | ALL | PRIMARY | NULL | NULL | NULL | 182746 | Using where; Using filesort
tableB | ref | Unique,which | Unique | 3 | myDB.tableA.id | 1932 | Using where; Using index
I'm confused about the memory size, too
Like, only read rows 0-19, or 60-79
I guess I am misunderstanding the question. But just in case, in an SQL query, you can use the LIMIT to select a range.
$i = 0;
while ($row = mysqli_fetch_row($sth)) {
$arr[] = $row;
$i++;
if ($i == 100) break;
}
$count = mysqli_num_rows($sth); The bottleneck isn't the query itself, phpMyAdmin shows the query completes in 0.0032s.
** I'm confused that the error shows that I'm breaching 67M, though (memory_limit is set to 64M). My query does a single LEFT JOIN; tableA is 41.6MB, and tableB is 11MB. The query looks like:
Also consider if your initial COUNT(*) query is essential on every page load. You could do it once every 10 minutes and write it to file. If you access it often it'll likely be cached in memory most of the time.