Monday, February 23, 2009

Things to consider when using Zend_Db_Table_Row

Before you start using Zend_Db_Table_Row, there's a few things you need to be aware of. By default, I would say Zend_Db_Table_Row isn't very performant. Everytime you use it to insert or update a row, the row will then be fetched automatically from the dabatase to update it's content. Why? Because it's possible some external process (like a trigger) or default values did assign values to some fields after your insert and your update. It will ensure that you keep on working on valid, up to date data if you keep on using the Zend_Db_Table_Row after an operation.

Imagine you're on a site where you're using a Zend_Db_Table_Row to insert IP addresses in some ip_address table. If you get hundreds of visits per minute, you'll not only have hundreds of insert statements, but hundreds of select statements too.

From my point of view, there are two solutions. You could simply *not* use Zend_Db_Table_Row to insert or update data in tables under heavy loads (you could use Zend_Db_Table directly) or you could subclass Zend_Db_Table_Row with some extra property that will allow the class *not* to update itself after an insert or update. This is what I did at work, and I pretty much always choose not to update the row because 99.99% of the time, once the insert or update is done, I don't need the row instance anymore.

No comments:

Post a Comment