DrewPierce

cached function calls

Nov 1st, 2016
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.98 KB | None | 0 0
  1. create table xyz
  2. (   id int not null,
  3.     title varchar(1000) not null
  4. );
  5. -- truncate xyz;
  6. insert xyz (id,title) select qid,title from questions_mysql limit 5000;
  7.  
  8. select sum(length(title)) from xyz;
  9. -- 1st time: 265416 in 0.032 sec
  10. -- 2nd time: 265416 in 0.015 sec
  11. -- 3nd time: 265416 in 0.000 sec
  12. -- 4th time: 265416 in 0.016 sec
  13.  
  14. So far inconclusive due to title being cached potentially, not length(title) necess being cached
  15.  
  16. truncate xyz;
  17. insert xyz (id,title) select qid,title from questions_mysql limit 5000;
  18.  
  19. select count(*)
  20. from
  21. (   select distinct(soundex(title))
  22. from xyz
  23. )xDerived;
  24. -- 1st time: 4996 rows in 0.281 sec
  25. -- 2nd time: 4996 rows in 0.281 sec
  26. -- 3rd time: 4996 rows in 0.265 sec
  27. -- 3rd time: 4996 rows in 0.266 sec
  28.  
  29. Granted xDerived on 5.6 is manifested in a temp table but if soundex is cached then temp is generated quicker
  30.  
  31.  
  32. select sum(length(title)) from xyz;
  33. -- 1st time: 265416 in 0.016 sec
  34.  
  35. Note in above line, that is new data due to truncate.
Advertisement
Add Comment
Please, Sign In to add comment