[odb-users] Segfault after adding relations

Boris Kolpackov boris at codesynthesis.com
Fri Sep 30 06:37:56 EDT 2011


Hi Michal,

kontakt at msnoch.pl <kontakt at msnoch.pl> writes:

> Db which I use is having table whith ~500.000 records of bus arrivals which
> are storing as boost::shared_ptr, relation to Line and Stop; Stop - Arrival
> is bidirectional so, stop is storing QVector of weak_ptr to arrivals. The
> problem is, when I try to find stop via street name. If Stop doesn't have
> pointer vector it works really fast, but when it is - it takes minutes.  Do
> you know what can be wrong?

It depends what takes so long, the query() call or the iteration over the
returned result.

If it is the query(), then the problem is most likely in the database.
That is, when object relationships are complex, the SELECT statement
that is used in the query() call can JOIN quite a few tables.

If it is the iteration, then it is most definitely the relationships
that take so long to load. If each object returned by a query contains
a vector of pointers to other objects, then loading them can take some
time. Using a session (as you do) will help if there are many shared
objects but the better solution to this problem will be to switch to
lazy pointers, especially if there are "many"-sided relationships, as
in your case. See Section 6.3, "Lazy Pointers" in the ODB manual for
more information.

> I saw one another weird thing:
>
>         for(int i=0; i<start.size(); i++)
>         {
>             cout << "X,";
>         }
>         cout << endl;
>
>         for(result::iterator i(start.begin()); i!= start.end(); ++i)
>         {
>
>             cout << "Found " << i->name().toStdString() << " -> "
>                  << i->street().toStdString() << endl;
>
>         }
>
> First loop runs instantly, but second, which uses iterator - waits few  
> seconds. Even if only one record is selected.

This indicates that the problem is most likely the relationship loading.
Try to switch to lazy pointers and see if it helps.

Boris



More information about the odb-users mailing list