Parts explosion with repeated subtrees

From: --CELKO-- <71062.1056_at_compuserve.com>
Date: 13 Dec 2002 16:01:46 -0800
Message-ID: <c0d87ec0.0212131601.71ea8ad0_at_posting.google.com>



Another tree oriented problem.

Imagine that we have a forest of trees called "Menu" which stores the menu items for a restaurant. The first level under the root is the dishes served. Each dish is then decomposed into its ingredients; the ingredient can be either simple (salt, water, milk, flour, etc) or it can have a recipe of its own (Béarnaise sauce, Hollandaise sauce, etc.)

Let me build a tree of each dish or recipe down to its most basic simple ingredients:

CREATE TABLE Menu
(dish_name VARCHAR (25) NOT NULL,
 food_item VARCHAR (25) NOT NULL,
  item_type CHAR (6) NOT NULL DEFAULT ‘simple'

        CHECK (item_type IN (‘dish', ‘recipe', ‘simple')),  PRIMARY KEY (dish_name, food_item),
<< constraints >>);

INSERT INTO Menu
VALUES (‘Eggs Benedict', ‘English Muffin', ‘simple'),

(‘Eggs Benedict', ‘Canadian Bacon', ‘simple'),
(‘Eggs Benedict', ‘Egg', ‘simple'),
(‘Eggs Benedict', ‘Béarnaise sauce', ‘recipe');

INSERT INTO Menu
VALUES (‘Béarnaise sauce', ‘Dill', ‘simple'),

(‘Béarnaise sauce', ‘Hollandaise sauce', ‘recipe');

INSERT INTO Menu
VALUES (‘Hollandaise sauce', ‘Egg‘, ‘simple'),

(‘Hollandaise sauce', ‘Lemon Juice‘, ‘simple'),
(‘Hollandaise sauce', ‘Butter‘, ‘simple');

If I put the Menu into a nested set model, I would want to build a full tree for each menu item. However, things like ‘Béarnaise sauce' and ‘Hollandaise sauce' are going to appear all over the place.

I can recursively expand each ingredient which has a recipe of its own until I have a result set of only simple ingredients.

But is there another model or better query which would allow us to find all the simple ingredients of a given dish? Received on Sat Dec 14 2002 - 01:01:46 CET

Original text of this message