Re: best stategry: check before create
[prev]
[thread]
[next]
[Date index for 2005/03/18]
On Mar 17, 2005, at 11:10 PM, Ofer Nave wrote:
> 1) It will hit the database for every title. I could avoid this by
> building a quick hash of all titles already in my DB and checking
> myself in perl, then calling 'create' for the new ones, but that's
> less CDBI-ish.
Then you are trading more small lookups for a big data transfer and
memory usage. If you are concerned about it you should make a test to
see if it's even faster. How many titles do you need to compare
before it's faster?
> 2) It uses the same data structure to both 'find' and 'create' -
> meaning you can't say "just match on title, but if you don't find the
> title, then create it with that title as well as this body and this
> other misc data". Since it returns the object, I could then set the
> non-matchable fields afterwards, and then call 'update', but that's
> two DB hits instead of one. Not a big deal, but I am wondering if
> there's a more elegant CDBI solution that I don't know of.
Do a search on the title and then either update or create as
appropriate.
If the data load is truly high it should be a little faster to do a
"insert ... on duplicate key update ..." statement if your MySQL is new
enough to support that.
- ask
--
http://www.askbjoernhansen.com/
|
|
Re: best stategry: check before create
=?ISO-8859-1?Q?Ask_Bj=F8rn_Hansen?= 07:22 on 18 Mar 2005
|