Connecting Tech Pros Worldwide Help | Site Map

Patterns for saving objects to the DB.

  #1  
Old March 19th, 2008, 02:45 PM
lister
Guest
 
Posts: n/a
Hi,

Currently each of the members within my objects have a field in a
table. The objects have a Save() method which writes out all the
members at once in a single SQL statement.

Although this works fine I have been pondering that it's not
particularly efficient to update every field if just one boolean has
changed for example. I have been considering flagging dirty fields
within my object and only writing those out when a Save() is called. I
am, however, wondering whether it's worth the effort to implement
this, and have a few questions:

1) Is MySQL smart enough to realise that certain fields haven't
changed anyway and so to not bother updating any indexes on that
field?

2) Is it really worth worrying about the redundancy for 10-15 field
rows?

3) In researching this a bit, I have found that some people just
serialise the object to a BLOB field. Is this a common method? It
seems a bit nasty to me since it prevents much ability to query the
table, and ties the data to a particular language.

4) How do you guys normally do it?

Many thanks
  #2  
Old March 19th, 2008, 02:55 PM
ZeldorBlat
Guest
 
Posts: n/a

re: Patterns for saving objects to the DB.


On Mar 19, 9:36 am, lister <listerofsme...@hotmail.comwrote:
Quote:
Hi,
>
Currently each of the members within my objects have a field in a
table. The objects have a Save() method which writes out all the
members at once in a single SQL statement.
>
Although this works fine I have been pondering that it's not
particularly efficient to update every field if just one boolean has
changed for example. I have been considering flagging dirty fields
within my object and only writing those out when a Save() is called. I
am, however, wondering whether it's worth the effort to implement
this, and have a few questions:
>
1) Is MySQL smart enough to realise that certain fields haven't
changed anyway and so to not bother updating any indexes on that
field?
>
2) Is it really worth worrying about the redundancy for 10-15 field
rows?
You're prematurely optimizing. Do it the straightforward, easy,
maintainable way first, then optimize if you run into specific
performance problems. At this point you should have a much better
idea of what is causing the problem -- and you may be surprised to
find that it isn't what you thought it was.
Quote:
>
3) In researching this a bit, I have found that some people just
serialise the object to a BLOB field. Is this a common method? It
seems a bit nasty to me since it prevents much ability to query the
table, and ties the data to a particular language.
You seem to already know why this is a bad idea.
Quote:
>
4) How do you guys normally do it?
>
Use the ActiveRecord pattern.


  #3  
Old March 19th, 2008, 03:15 PM
Captain Paralytic
Guest
 
Posts: n/a

re: Patterns for saving objects to the DB.


On 19 Mar, 13:36, lister <listerofsme...@hotmail.comwrote:
Quote:
>
1) Is MySQL smart enough to realise that certain fields haven't
changed anyway and so to not bother updating any indexes on that
field?
Try running an update statement where no data has changed and MySQL
will tell you that no rows were affected.
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Methodology Mark A. Sam answers 3 March 26th, 2006 05:05 PM
author index for Python Cookbook 2? Andrew Dalke answers 10 July 19th, 2005 12:26 AM