Guest User

Untitled

a guest
Jul 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. EXPLAIN SELECT id_member, real_name
  2. FROM forum_members
  3. WHERE id_group = 1 OR FIND_IN_SET(1, additional_groups)
  4. LIMIT 33;
  5.  
  6. *************************** 1. row ***************************
  7. id: 1
  8. select_type: SIMPLE
  9. table: forum_members
  10. type: ALL
  11. possible_keys: ID_GROUP,debug
  12. key: NULL
  13. key_len: NULL
  14. ref: NULL
  15. rows: 1369966
  16. Extra: Using where
  17. 1 row in set (0.00 sec)
  18.  
  19. Better?
  20.  
  21. EXPLAIN
  22. (SELECT id_member, real_name
  23. FROM forum_members
  24. WHERE id_group = 1)
  25. UNION
  26. (SELECT id_member, real_name
  27. FROM forum_members
  28. WHERE FIND_IN_SET(1, additional_groups))
  29. LIMIT 33\G
  30.  
  31. *************************** 1. row ***************************
  32. id: 1
  33. select_type: PRIMARY
  34. table: forum_members
  35. type: ref
  36. possible_keys: ID_GROUP,debug
  37. key: ID_GROUP
  38. key_len: 2
  39. ref: const
  40. rows: 2
  41. Extra:
  42. *************************** 2. row ***************************
  43. id: 2
  44. select_type: UNION
  45. table: forum_members
  46. type: ALL
  47. possible_keys: NULL
  48. key: NULL
  49. key_len: NULL
  50. ref: NULL
  51. rows: 1375021
  52. Extra: Using where
  53. *************************** 3. row ***************************
  54. id: NULL
  55. select_type: UNION RESULT
  56. table: <union1,2>
  57. type: ALL
  58. possible_keys: NULL
  59. key: NULL
  60. key_len: NULL
  61. ref: NULL
  62. rows: NULL
  63. Extra:
  64. 3 rows in set (0.00 sec)
  65.  
  66. Though, I must admit I'm not sure an index on additional_groups would help since it's a function. Better here would probably be to normalize it so you have
  67.  
  68. forum_user_groups
  69. - user_id
  70. - group_id
Add Comment
Please, Sign In to add comment