Guest User

Untitled

a guest
Dec 11th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. Benchmark.bm do|b|
  2. b.report("exclusion join ") do
  3. a = ""
  4. 10_000.times do
  5. Element.find_by_sql(
  6. <<-SQL
  7. select e.* from elements e
  8. left outer join elements leafs
  9. on e.id = leafs.parent_id
  10. where leafs.parent_id is null
  11. SQL
  12. )
  13. end
  14. end
  15.  
  16. b.report("sub query ") do
  17. a = ""
  18. 10_000.times do
  19. Element.find_by_sql(
  20. <<-SQL
  21. SELECT * FROM elements
  22. WHERE id NOT IN (
  23. SELECT parent_id FROM elements
  24. WHERE parent_id IS NOT NULL
  25. )
  26. SQL
  27. )
  28. end
  29. end
  30. end
  31.  
  32. # results:
  33. # user system total real
  34. # exclusion join 2.440000 0.200000 2.640000 ( 4.545996)
  35. # sub query 1.900000 0.180000 2.080000 ( 3.591858)
Add Comment
Please, Sign In to add comment