Prefetch Paths

Posts   
 
    
Answer
User
Posts: 363
Joined: 28-Jun-2004
# Posted on: 22-Oct-2005 00:58:05   

im reading over the new docs, since its been a while since i last used llblgen, like 7 months, and i ahve questions regarding prefech paths.

Say i have order entity that has a 1 to 1 relation with a customer entity and and 1 to 1 relation with a packager entity.

So to recap i have order.customer and order.packager both of which are 1 to 1 relation.

If i use a prefetch path, will the order data, customer data, and packager data be fetched in a single query? or will it use 3 querys? I would think it could do it in one...but im not sure.

BTW...im UBEr impressed with all the new cool stuff smile Its like Christmas in Oct stuck_out_tongue_winking_eye

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 22-Oct-2005 02:26:00   

It's done in three queries. The first query fills the order entity and then the other two will perform using the fields in the relation between the order and the customer and the order and the packager. Have you checked out how Predicates are handled in 2005.1 with c#. Pretty cool stuff for people that have been using the software for a while. simple_smile

Answer
User
Posts: 363
Joined: 28-Jun-2004
# Posted on: 22-Oct-2005 05:09:13   

Yeah i read almost the entire manaul over the last couple days. The new way of using the operators is a lot easier to "see" teh query, i like it a lot.

The reason i ask about the prefectch path is that isnt it possible that all that data could be pulled in one query using a two joins?

Now i figured i could create a typed list with all the columns of each entity. And that would be filled using one query with joins. However since i will be pulling only ONE entity at a time, it seems like a lot of over kill creating a datatable for one record. smile

pilotboba
User
Posts: 434
Joined: 05-Aug-2005
# Posted on: 22-Oct-2005 21:08:07   

Answer wrote:

The reason i ask about the prefectch path is that isnt it possible that all that data could be pulled in one query using a two joins?

It is possible, but inefficient. Since you are pulling duplicate data for the parent record.

Say you have a customer table with 100 fields, and an order table and you want to pre-fetch all the customers orders.

So, if you do this:

FROM customer JOIN order ON ...

Then you will get a record for each order with 100 extra fields of data from the customer table joined to it. This doesn't seem to mesh with the "get the least amount of data possible" when fetching data from the server.

The most efficient is to use one query for each entity in a single batch. I "assume" that is what Frans is doing.

BOb

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 22-Oct-2005 23:33:24   

pilotboba wrote:

Answer wrote:

The reason i ask about the prefectch path is that isnt it possible that all that data could be pulled in one query using a two joins?

It is possible, but inefficient. Since you are pulling duplicate data for the parent record.

Say you have a customer table with 100 fields, and an order table and you want to pre-fetch all the customers orders.

So, if you do this:

FROM customer JOIN order ON ...

Then you will get a record for each order with 100 extra fields of data from the customer table joined to it. This doesn't seem to mesh with the "get the least amount of data possible" when fetching data from the server.

The most efficient is to use one query for each entity in a single batch. I "assume" that is what Frans is doing.

Correct, one query per graph node. I've done various experiements with all kinds of setups how to pull data for prefetch paths and which one would be more efficient, and subqueries were the most efficient. With Marcus' optimization code, this is optimized a lot in 1.0.2005.1 simple_smile

Objectspaces used joins as well with a union with nulls for parent fields. It could work but you would have a problem with multi-path graphs.

Frans Bouma | Lead developer LLBLGen Pro
Answer
User
Posts: 363
Joined: 28-Jun-2004
# Posted on: 23-Oct-2005 02:09:17   

Say you have a customer table with 100 fields, and an order table and you want to pre-fetch all the customers orders.

Yes in this case it is more efficent to pull it in more then query. But im talking about the specific scenario where you are pulling only 1 record from each table. In this case you would not be pulling duplicate data.

So you have order.customer and order.packager. now there will be only one corresponding customer record int eh customer table and only one packager in the packager table for each order.

So if i pull a SINGLE order, i could also pull the customer and packager using ajoin without any duplicate data. The way it is right now is that 3 queries are used.

Just so im up to speed, the 3 prefetch path queries are equivalent to calling adapter.fetch() 3 times, assuming i keep the connection object open.