amy burgess amy burgess - 1 month ago 26
MySQL Question

Codeigniter batch update performance

Does

$this->db->update_batch();
update with 1 table connection or does it update each row separately incurring overhead of opening connections?

I'm wondering if this is faster than using foreach and
$this->db->update();

Answer

As in Codeigniter documentation $this->db->update_batch(); generate a single query and establish only one connection. So it would be faster than query within foreach loop.

After profiling I can see following results (only 0.0700 sec taken to update 4 rows)

UPDATE batch

on other hand I have updated same no. of rows with loop and it takes much time (0.665 sec which is almost 1 sec)

foreach loop