[odb-users] Question about query caching

Stroud, Sean T ststrou at sandia.gov
Mon Oct 1 17:25:21 EDT 2012


Hi,

I am new to ODB and have a question about query caching.  I created the following data classes:

Sensor_Product
Product_Header
Ephemeris

The Sensor_Product has the following data members:
-       Product_Header *m_header_ptr;
-       Ephemeris *m_ephemeris_ptr;
-       int m_id;  // the primary key

Now say I issue a query on the Sensor_Product class, like this:

      // Issue the query
      transaction t(db->begin);
      query<Sensor_Product> sp_query( query<Sensor_Product>::data_value > 10 );
      result<Sensor_Product> sp_result( db->query(sp_query) );

      // Cache the results
      sp_result.cache();

      // Iterate over the results
      for ( result<Sensor_Product>::iterator iter(sp_result.begin(); iter != sp_result.end(); ++iter ) {
          const Sensor_Product &sp = *iter;
          cout << sp.m_id << endl;
      }

What I am seeing is that the "Issue the query" section above does a SELECT with two LEFT JOINs to get the Sensor_Product, Product_Header and Ephemeris classes.  That makes sense.  But then it looks like the "Iterate over the results" section causes more SELECT statements to be issued.  In particular, each time the "*iter" expression is executed in the for loop, ODB is issuing two queries: one to select the Product_Header and one to select the Ephemeris.   This surprised me since I thought I was caching the results with the "sp_result.cache()" statement.  These extra select statements appear to slow things down considerably, so I'd like to understand why they are necessary and (more importantly) if there is a way I can eliminate them.  Can someone educate me?

Thanks.

Sean




More information about the odb-users mailing list