Guest User

Untitled

a guest
Dec 18th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. $sql = "SELECT SQL_NO_CACHE p1.* FROM comment p1 INNER JOIN
  2. (SELECT max(seen) last_seen, max(id) MaxId,
  3. user_id, topic_id, picture_id, news_id, date
  4. FROM comment WHERE user_id='$me' and deleted=0
  5. GROUP BY topic_id) p2
  6. ON p1.topic_id = p2.topic_id
  7. WHERE p1.date > p2.last_seen and p1.id > p2.MaxId and deleted=0
  8. GROUP BY p1.topic_id ORDER BY p1.date DESC"
  9.  
  10. $sql = "SELECT SQL_NO_CACHE p1.* FROM comment p1 INNER JOIN
  11. (SELECT max(seen) last_seen, max(id) MaxId,
  12. user_id, topic_id, picture_id, news_id, date
  13. FROM comment WHERE user_id='$me' and deleted=0
  14. GROUP BY topic_id, picture_id, news_id) p2
  15. ON p1.topic_id = p2.topic_id and p1.picture_id= p2.picture_id
  16. and p1.news_id= p2.news_id
  17. WHERE p1.date > p2.last_seen and p1.id > p2.MaxId and deleted=0
  18. GROUP BY p1.topic_id, p1.picture_id, p1.news_id ORDER BY p1.date DESC"
  19.  
  20. CREATE TABLE `comment` (
  21. `id` int(11) NOT NULL,
  22. `user_id` int(11) NOT NULL,
  23. `topic_id` int(11) NOT NULL,
  24. `picture_id` int(11) NOT NULL,
  25. `news_id` int(11) NOT NULL,
  26. `text` text COLLATE utf8_hungarian_ci NOT NULL,
  27. `date` datetime NOT NULL,
  28. `reply_id` int(11) NOT NULL,
  29. `comment_vote` int(11) NOT NULL,
  30. `comment_hit` int(11) NOT NULL,
  31. `moderated` int(11) NOT NULL,
  32. `seen` datetime NOT NULL,
  33. `deleted` tinyint(4) NOT NULL,
  34. `ip` text COLLATE utf8_hungarian_ci NOT NULL
  35. ) ENGINE=InnoDB DEFAULT CHARSET=utf8
  36. COLLATE=utf8_hungarian_ci;
  37.  
  38. 1(id) PRIMARY(select_type) <derived2>(table) ALL(type) NULL(possible keys) NULL(key) NULL(key_len) NULL(ref) 105(rows) Using temporary; Using filesort(extra)
  39. 1(id) PRIMARY(select_type) p1(table) ref(type) PRIMARY,topic_id,deleted,date,picture_id,news_id(possible keys) topic_id(key) 4(key_len) p2.deck_id(ref) 5(rows) Using where(extra)
  40. 2(id) DERIVED(select_type) p2(table) index_merge(type) deleted,user_id(possible_keys) user_id(key) 4,1(key_len) NULL(ref) 169(rows) Using intersect(user_id,deleted); Using where; Using filesort(extra)
Add Comment
Please, Sign In to add comment