Hacker News new | ask | show | jobs
by rkv 3342 days ago
Can you give me an example where an array would be more beneficial than having another table with {id, name}? I personally have never found a use for them.
2 comments

simplicity, for one - write a quick query to retrieve all recipes that contain all of any number of ingredients.

  SELECT * FROM recipes r
   INNER JOIN ingredients i ON (r.id = i.recipe_id)
   WHERE i.ingredient IN ('mushrooms', 'sour cream')
load up some data and run explain analyze on both schemas/queries.
I could think of denormalization; e.g. you have an entitiy that can have 0..n tags and you want to speed up the retrieval, I could think of arrays being a faster way.
Quite a bit faster, actually, depending on the dataset.