On Wed, 31 Aug 2011 16:20:24 +0200, Fulvio Senore <mail...@fsoft.it>
wrote:
> I didn't know anything about the N+1 query trap, but Google was my
friend.
> Yes, that is my problem, but I don't know how to find a better solution.
> 
> My program shows 3 user selectable views. For each view a tree control 
> at the left shows a structure of "folders" and "subfolders" where images

> are organized.
> 
> When I open a catalog I load the first 2 levels of items in the tree 
> controls, so that users can see all the first level items and they can 
> see if an item has sub-items so it can be expanded.
> Further items loading in the tree controls happens when the user expands

> an existing item.
> 
> Of course if the user has a lot of items in the tree controls this leads

> to an explosion of queries. This has never been a problem before, but I 
> realize that a better solution would be welcome.
> 
> At the moment I enumerate all the first level items with a query, then I

> execute a query for each item to find its sub-items.
> Items are stored in a single table, with a parent-child relationship 
> created using a FATHER_ID field.
> I probably need a better solution, but probably this question would be 
> better suited for the Firebird Support list.

Not 100% sure, but it sounds like a recursive Common Table Expression
might be your friend here. See for example
http://mycodingexperience.blogspot.com/2011/04/common-table-expression-cte-and-tree.html

(in Firebird you will need to use WITH RECURSIVE for this)

Mark

------------------------------------------------------------------------------
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better 
price-free! And you'll get a free "Love Thy Logs" t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev
Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel

Reply via email to