Community

How to perform a very big sql query without exhausting sql memory

I have a very large database table that I need to query.

I am using a

$query = db_select('search_send', 's')
->fields('s')
->condition('s.userID', $user->uid,'=');

$result = $query->execute();
   
while($record = $result->fetchAssoc()) {

     $sentTime = strtotime($record['created']);
     $sentdate = date('Y-m-d h:s:i', $record['created']);
      $rows[] = array(
      'data' => array(

But I am getting an error that max_packet_allow for sql is reached. I am on a shared host, so I can not change this variable.

Is there any way around this? Thanks!

Comments

A suggestion

Hello,
I would consider replacing the single request with multiple requests. I would also verify that I need all the fields or just some fields (from the database).

Why not first do a count query. Then calculate a series of smaller requests using something like db_query_range() (or your own criteria. like one month at time ).

For example if you "search users" is associate with 100 posts. Instead of selecting all 100, do 10 at a time.

Good Luck :)

Thinking is the best way to travel.

nobody click here