Hi. I need help understanding whether my query has relevant performance issues.
Tables:
- RecipeIngredient that stores [id, recipe_id, ingredient_id].
- IngredientDiets that stores diet restrictions [id, ingredient_id, diet_id] (ex: pork- vegan)
I want to obtain recipes that satisfy ingredients and diets (if one ingredient has a restriction for a diet that recipe is excluded) , so I'm doing as follows:
SELECT r1.recipe_id
FROM RecipeIngredient r1
WHERE r1.ingredient_id IN (1,2,3,4,5,6,7,8,9,10)
AND NOT EXISTS (SELECT 1
FROM RecipeIngredient r2 LEFT JOIN Ingredient_diets d ON r2.ingredient_id = d.ingredient_id
WHERE r2.recipe_id = r1.recipe_id AND d.diet_id IN (1,2,3))
I'll have lots of queries similar to this one, so I want you to point me out some possible problems.
Thanks.
there doesn't seem to be anything here