Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. ALTER TABLE products
  2. ADD FOREIGN KEY (category_id) REFERENCES categories(id);
  3.  
  4. ALTER TABLE product_descriptions
  5. ADD FOREIGN KEY (product_id) REFERENCES products(id);
  6.  
  7. CREATE INDEX ct_lang
  8. ON category_descriptions(category_id, lang);
  9.  
  10. EXPLAIN SELECT
  11. p.*, pd.*, cd.*
  12. FROM products p
  13. JOIN product_descriptions pd
  14. ON p.id = pd.product_id
  15. AND pd.lang = 'eng'
  16. JOIN category_descriptions cd FORCE INDEX (ct_lang)
  17. ON p.category_id = cd.category_id
  18. AND cd.lang = 'eng';
  19.  
  20. --> total = 3 * 1 rows
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement