Hey everyone, I am currently building a highly efficient website on culinary recipes (let's just put it that way).
Each recipe has 10 or less ingredients.
So given an ingredient, how can I find 1) All the recipes that the subject is present, and 2) All the other ingredients that are present in each of the recipes in 1) QUICKLY.
My initial planning is this: (and I will explain why: note that the syntax is not specific to a language so that it's easier for everyone to understand, Note that I am doing this first on MySQL, then if possible, I might want to move on to something faster with less functionality like tokyodb, which I am a big fan of).
Create TABLE mapping:
# This table holds all the names of everything, hopefully storing int
# will cause less IO
id int(32)
name char(32)
index/key (name)
Create table recipes:
# Note that ing1 - ing10 are not nulls, zero will be used for empty
name char(32)
ing1 int(32)
ing2 int(32)
ing3 int(32)
ing4 int(32)
ing5 int(32)
ing6 int(32)
ing7 int(32)
ing8 int(32)
ing9 int(32)
ing10 int(32)
index/key on name
create table relationship:
# This table holds the relationship between ingredients and recipe
ing int(32)
recipe int(32)
key/index on ing
What do you guys think? Can someone think of a better implementation?