Good point about database defaults.
Stepping back for a second, what I'm really wondering is why new/save
is so much slower than insert/find. Here's a trivial benchmark:
http://gist.github.com/412084
The results are somewhat surprising:
$ ./create_vs_insert
user system total
real
plain insert 1.640000 0.250000 1.890000
( 2.508927)
find by id 1.630000 0.260000 1.890000
( 2.880001)
create 9.420000 1.080000 10.500000
( 13.431826)
plain insert with find 3.420000 0.520000 3.940000
( 5.634394)
So it looks like Sequel is spending alot of time somewhere in new/save/
create vs insert/find. There are no validations or callbacks or
anything on these models which could explain the difference. Any
ideas?
Thanks,
Nate
On May 23, 6:38 pm, Jeremy Evans <[email protected]> wrote:
> On May 23, 5:08 pm, Nate Wiger <[email protected]> wrote:
>
> > Sure, insert will put it into the DB, but that will bypass all the
> > validations/etc.
>
> > Shouldn't it be possible for Sequel to have a reference to the item
> > without making a DB roundtrip?
>
> In certain cases, yes. It does the query to get the values of all of
> the columns, so that it works correctly with database defaults. Let's
> say column a has a default value of 5. Without doing the refresh, if
> you did:
>
> Model.create.a
>
> You would get nil instead of 5.
>
> Note that on PostgreSQL (and I think on Firebird too), Sequel doesn't
> need to send a query to refresh, since it uses INSERT RETURNING, so
> that the column values are returned when the insert is done.
>
> You can certainly modify Sequel not to do the refresh. It currently
> requires modifying a fairly large method (_save), but it could be
> easily refactored that to make it easier to override.
>
> Jeremy
>
> --
> You received this message because you are subscribed to the Google Groups
> "sequel-talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group
> athttp://groups.google.com/group/sequel-talk?hl=en.
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.