Part of the EllisLab Network
   
 
first_row, last_row
Posted: 26 August 2008 11:08 AM   [ Ignore ]  
Summer Student
Total Posts:  2
Joined  08-26-2008

See code below…

function query_events_older_than_timeperiod($value,$period)
   
{
    $this
->load->database('snortdb',TRUE);
    
$sql = "SELECT cid,sid,timestamp FROM event WHERE timestamp < NOW() - INTERVAL " . $value . " " . $period ." ORDER BY timestamp ASC";
    
$query = $this->db->query($sql);

    
$first_ev = $query->first_row('array');
    
$last_ev = $query->last_row('array');

    
$results = array('query' => $query,
                     
'fe' => $first_ev['timestamp']);

    return
$results;
   
}

Everytime this function is executed I get the following error:

Fatal error: Allowed memory size of 18874368 bytes exhausted (tried to allocate 39 bytes) in /var/www/html/idscontrol/system/database/drivers/mysql/mysql_result.php on line 153

I have increased the memory allowed to scripts to 18M, but I do not think I should have to keep increasing it, that is not a solution.

If I remove the first_row() and last_row() calls, I get no errors. This query is returning ~45K rows.

Can anyone think of why asking for the first and last rows would cause this?

Profile
 
 
Posted: 27 August 2008 12:01 PM   [ Ignore ]   [ # 1 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1163
Joined  08-06-2006

welcome to CI funkshun!

I don’t have an answer per se, but you might get faster response by changing your approach.

Make two queries: both with LIMIT 1, one with ORDER BY ASC and one DESC.

just a thought… might not work with your requirements.

cheers.

 Signature 

imap_pop get email | site_migrate port sites | OOCalendar | PhotoBox2 gallery | CI/EE 2 word_limiter, yep, wrote it

Profile
 
 
Posted: 27 August 2008 12:05 PM   [ Ignore ]   [ # 2 ]  
Summer Student
Total Posts:  2
Joined  08-26-2008

I hadn’t thought of that, and it would work, but I do think I should need to do that since these functions are suppose to accomplish it. I may do that in the meantime as a workaround. Thx.

Profile
 
 
Posted: 27 August 2008 12:30 PM   [ Ignore ]   [ # 3 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1163
Joined  08-06-2006

i’d call it optimization rather than workaround… maybe the “bytes exhausted” error is trying to tell you something wink

EDIT: I just looked at the CI $query->first_row() method and it currently sports an (overlooked?) resource-greedy while loop through the ENTIRE RESULT ARRAY just to get the first result as an array. so, the optimization i suggested actually avoids this CI performance bottleneck. this should be posted in the bug report section of the forum…

funkshun, would you like to do the honors?

 Signature 

imap_pop get email | site_migrate port sites | OOCalendar | PhotoBox2 gallery | CI/EE 2 word_limiter, yep, wrote it

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 819, on March 11, 2010 11:15 AM
Total Registered Members: 120461 Total Logged-in Users: 38
Total Topics: 126538 Total Anonymous Users: 2
Total Replies: 665365 Total Guests: 308
Total Posts: 791903    
Members ( View Memberlist )
Newest Members:  kmotion1jelevinlizandermagnosismx2428JordanMartzShaun HardynelsonpowellLimenijetzzy