Connecting Tech Pros Worldwide Help | Site Map

Patterns for saving objects to the DB.

 
LinkBack Thread Tools Search this Thread
  #1  
Old March 19th, 2008, 01:45 PM
lister
Guest
 
Posts: n/a
Default Patterns for saving objects to the DB.

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, 01:55 PM
ZeldorBlat
Guest
 
Posts: n/a
Default 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, 02:15 PM
Captain Paralytic
Guest
 
Posts: n/a
Default 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.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.