[Dbix-class] Update first X rows

Peter Rabbitson rabbit+dbic at rabbit.us
Thu Jul 16 13:31:23 GMT 2009


On Thu, Jul 16, 2009 at 01:53:39PM +0200, Yves Räber wrote:
> Thanks for your explanation. But things are still not clear for me.
> 
> If I create a resulset with a "rows" argument and then
> 
> 1/ Get all  the rows with a ->all method : It generate a "SELECT ... LIMIT rowcount" that's perfect
> 2/ Update the rows with a ->update( { whatever => 1 }) : It generates a "UPDATE ..." but ignores the limit
> 
> The slow and foolpoof method would be to update the rows one by one and stop after X elements, but it's not what it is doing. 
> 

Sigh. It really helps if you read what people point you to (I am referring
to the function I mentioned in previous mails). Once gain - the *default*
way to do $rs->update will _never_ add a limit to the query, as limit
is simply not portable (see SQL::Abstract::Limit). The "slow and foolproof
method" we use is to:

1) start a transaction
2) *SELECT* (not update) all rows that we would want to update
3) iterate over the result and update rows one by one
4) wrap up transaction

Guess which one of the points contains the actual limit, and read the
damned trace.

To summarize - everything works correctly, this is not a bug, it is just
inefficient. I already outlined what needs to be done to make it happen,
and it will happen when someone gets the time to do it.



More information about the DBIx-Class mailing list