Advertisement
Guest User

banshee performance regression

a guest
Nov 3rd, 2014
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. Datum: Thu, 23 Oct 2014 18:42:17 -0400
  2. Von: Richard Hipp <drh sqlite.org>
  3. An: General Discussion of SQLite Database <sqlite-users@sqlite.org>
  4. Betreff: Re: [sqlite] Performance regression in Banshee with sqlite
  5. 3.8.7 on Arch Linux
  6.  
  7.  
  8. On Thu, Oct 23, 2014 at 4:03 PM, Tomislav Ljubej <sporbie@gmail.com>
  9. wrote:
  10.  
  11. > I've searched Banshee's source code and it seems 'CoreCache' is a TEMP
  12. > table according to some comments in the code but I have no clue where
  13. > it's actually defined, there is no 'CREATE TABLE' statement in the
  14. > code for that particular table (I've searched even with TEMP or
  15. > TEMPORARY keywords, nothing). Then I've googled around and found this
  16. > definition:
  17. >
  18. > CREATE TABLE CoreCache (
  19. > OrderID INTEGER PRIMARY KEY,
  20. > ModelID INTEGER,
  21. > ItemID INTEGER);
  22. >
  23.  
  24. Thanks. That was sufficient for me to reproduce the problem. The
  25. problem is caused by this check-in:
  26.  
  27. http://www.sqlite.org/src/info/0bdf1a086b
  28.  
  29. And that check-in was necessary to ensure correct behavior in certain
  30. obscure circumstances. So I cannot easily back it out. But I can work
  31. to try to find a different optimization that makes your query run
  32. faster.
  33.  
  34. In the meantime, may I suggest rewriting your query. The query you
  35. have is this:
  36.  
  37. INSERT INTO CoreCache (ModelID, ItemID)
  38. SELECT 9, CoreTracks.TrackID
  39. FROM (SELECT MIN(CoreTracks.TrackID) AS TrackID, CoreTracks.Year
  40. FROM CoreTracks GROUP BY CoreTracks.Year) AS CoreTracks
  41. WHERE CoreTracks.Year IN
  42. (SELECT CoreTracks.Year FROM CoreTracks, CoreCache
  43. WHERE CoreCache.ModelID = 71
  44. AND CoreCache.ItemID = CoreTracks.TrackID )
  45. ORDER BY Year;
  46.  
  47. I suggest rewriting it as follows:
  48.  
  49. INSERT INTO CoreCache (ModelID, ItemID)
  50. SELECT 9, MIN(TrackID)
  51. FROM CoreTracks
  52. GROUP BY Year
  53. HAVING Year IN
  54. (SELECT CoreTracks.Year FROM CoreTracks, CoreCache
  55. WHERE CoreCache.ModelID = 71
  56. AND CoreCache.ItemID = CoreTracks.TrackID )
  57. ORDER BY Year;
  58.  
  59. Or perhaps this:
  60.  
  61. INSERT INTO CoreCache (ModelID, ItemID)
  62. SELECT 9, MIN(TrackID)
  63. FROM CoreTracks
  64. WHERE Year IN
  65. (SELECT CoreTracks.Year FROM CoreTracks, CoreCache
  66. WHERE CoreCache.ModelID = 71
  67. AND CoreCache.ItemID = CoreTracks.TrackID )
  68. GROUP BY Year
  69. ORDER BY Year;
  70.  
  71. In 3.8.6, SQLite was making the above transformation automatically. But
  72. there are corner cases where this transformation is not valid and so it
  73. was disabled for 3.8.7, which is apparently what is causing your
  74. slowdown.
  75.  
  76. No promises, but I will try to make this transformation occur
  77. automatically again for SQLite 3.8.8, at least in your case where it
  78. does appear to be valid.
  79.  
  80. --
  81. D. Richard Hipp
  82. drh@sqlite.org
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement