0

Given the following:

$userMapper = new UserMapper($db);
$user = $userMapper->find(381);
$user->name = 'Derp' //was Durr
$userMapper->save($user);

Is it worth building logic into the UserMapper to detect that only name has changed, so as to build a slimmer UPDATE query? Or is it simpler just to update the whole record for the user from all of the fields in the user object?

I assume MySQL update performance between a single field, and fifty fields, is rather negligible?

AgmLauncher
  • 7,070
  • 8
  • 41
  • 67
  • You'll have to answer this yourself. Of course it's simpler to send the entire row along with the update but at what cost? How many fields and of what type are in your table? At some point tracking changes could be more expensive than sending everything. – Mike B Oct 31 '13 at 12:53

1 Answers1

0

All of this depends on a number of things. For example: The size of the data that is being processed. The amount of times that these updates will occur. There are a lot of things to take into account. In my opinion, your current example is fine unless it proves to be a performance issue.

Wayne Whitty
  • 19,513
  • 7
  • 44
  • 66