[odb-users] Segfault after adding relations

kontakt at msnoch.pl kontakt at msnoch.pl
Thu Sep 29 16:44:50 EDT 2011


 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.

 On Thu, 29 Sep 2011 21:49:00 +0200, kontakt at msnoch.pl wrote:
> Hi
>
> Well, i figured out that i had cycles in my relations - that caused
> an error. Now eveyrthing works fine but i'm wondering how can I
> speedup my app. 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?
>
> Michał
>
> PS. I'm using PostgreSQL
>
>
> [code]
>         session s;
>         transaction t(db->begin());
>
>         result start(db->query<Stop>("name ilike 'Opera'"));
>
>         for(result::iterator i(start.begin()); i!= start.end(); ++i)
>         {
>
>             cout << "Found " << i->name().toStdString() <<
> i->street().toStdString() << endl;
>
>         }
>
>         t.commit();
>         cout << "Route Done (" << start.size() << ")" << endl;
> [/code]
>
> On Thu, 29 Sep 2011 10:54:17 +0200, Boris Kolpackov wrote:
>> Hi Michal,
>>
>> kontakt at msnoch.pl <kontakt at msnoch.pl> writes:
>>
>>>         transaction t(db->begin());
>>>
>>>         result start(db->query<Stop>(query::name == p_from ||
>>> query::street == p_from));
>>>
>>>         for(result::iterator i(start.begin()); i!= start.end(); 
>>> ++i)
>>>         {
>>>
>>>             cout << "Found " << i->test().toStdString() << endl;
>>>
>>>         }
>>>
>>>         t.commit();
>>>         cout << "Route Done (" << start.size() << ")" << endl;
>>
>> The only problem that I see is the use of the result object after
>> the transaction has been committed (last line). Quoting the manual,
>> Section 4.4, second paragraph:
>>
>> "The result instance is only usable within the transaction it was
>>  created in. Trying to manipulate the result after the transaction
>>  has terminated leads to undefined behavior."
>>
>> If after fixing this you still get the segfault, I will also need
>> either the code fragment that persists the Stop/Line objects in the
>> database or your database dump (if it is big, please send it off-
>> list).
>>
>> Boris



More information about the odb-users mailing list