[odb-users] lazy pointers not working and update performance issue

Boris Kolpackov boris at codesynthesis.com
Fri Feb 26 09:28:46 EST 2016


Hi Luisa,

Luisa Giacomini <luisagiacomini.eu at gmail.com> writes:

> 1. The first problem is how to load the shared_ptr of an object, to be used
> as a foreign key into another object, without actually loading the object.
> I found on the manual the topic "lazy pointers" and it looks as if it
> exactly what I am looking for but it does not work.
> 
> I tried this
> std::string str = "TERMINAL1";
> lazy_shared_ptr<Terminal> er (db,str);  //TERMINAL1 exists always
> SvTerminal svt; //SvTerminal has a field named mrid that is a
> shared_ptr vs Terminal
> svt.mrid(er.get_eager());
> persist(svt);
> and yes, the shared_prt is null. What I am doing wrong?

You need to make svt.mrid lazy_shared_ptr<> as well. You cannot convert
a lazy pointer into a (non-NULL) eager one without loading the object.


> 2. I have found that the update instruction is quite slow; actually I
> have a table of 7000 elements, I load them, I modify a few fields and
> then call update one by one.
> The overall execution time is about 3sec, 1sec just for the updates.
> Is it possible to speed up the process, at least the update one with
> some kind of batch operation?

SQLite doesn't support bulk operations (unlike, say, SQL Server and
Oracle). A few things you can try, however:

1. Split the update into several smaller transaction, say 100 objects
at a time. Chances are it takes so long because SQLite has to maintain
a fairly large log.

2. Consider using object sections (Chapter 9, "Sections") to update
only the few members that you have modified.

Boris



More information about the odb-users mailing list