|There's more than one way to do things|
Efficiently Walking Large Data Structures Stored Across Multiple Tablesby jerrygarciuh (Curate)
|on Feb 28, 2004 at 14:55 UTC||Need Help??|
jerrygarciuh has asked for the
wisdom of the Perl Monks concerning the following question:
Our curriculum model has a very clean structure with all objects having a single parent object type and a single child object type. If speed were not a concern walking this structure is quite easy using CDBI. However, it involves quite a few record lookups, eg pull the pages for this section of this chapter and see if $page_number + 1 exists.
Since speed is a concern I am looking for alternatives for looking up a page id without having to potentially look up sections and chapters. My initial impulse is to alter the wizarding process for creating the curriculum so that it maintains a map of the whole structure of each curriculum as a var in a single record. I am imagining a hash that nests at each level the id for the current objects and an array of it's children. Each child also has it's id and the array of it's children. In this manner one could look up Curriculum 1, Chapter 3, Section 2, Page 5 or see if it has a page 6 and finding none go on to Section 3 or Chapter 4 etc. without multiple lookups in the db.
My question to you is what solutions have my betters applied to similar problems? If my solution has any merit please advise me of any gotchas you see.
"The man who grasps principles can successfully select his own methods.
The man who tries methods, ignoring principles, is sure to have trouble.
~ Ralph Waldo Emerson