Advertisement
stronk7

Untitled

Aug 30th, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. report the total number of files:
  2. SELECT COUNT(*) FROM mdl_files
  3.  
  4. report how many files the user has:
  5. SELECT userid as REALUSERID, count(*) as numfiles
  6. FROM mdl_files
  7. WHERE userid != ''
  8. GROUP BY userid
  9. ORDER BY numfiles desc
  10. LIMIT 1
  11.  
  12. timing (and explain plan) of (note you need to replace REALUSERID):
  13. SELECT files1.contextid, files1.itemid, files1.filearea,
  14. files1.component, files1.filepath, files1.filename, files1.pathnamehash
  15. FROM mdl_files files1
  16. JOIN (
  17. SELECT contenthash, filename, MAX(id) AS id
  18. FROM mdl_files
  19. WHERE userid = REALUSERID
  20. AND filename != '.'
  21. AND ((filearea = 'draft' AND itemid = 0) OR filearea != 'draft')
  22. AND referencefileid IS NULL
  23. GROUP BY contenthash, filename
  24. ) files2 ON files1.id = files2.id
  25. ORDER BY files1.timemodified DESC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement