New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jarvis restore AudioLibrary.GetSongs speed in SQLlite #9108
Conversation
std::string strSQL = "SELECT %s FROM songview "; | ||
if (artistData) | ||
std::string strSQL = "SELECT songview.* FROM songview "; | ||
if (artistData) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Good job.. WIth this query we have the right query plan in sqlite.. I can't test it right now in mysql but it shouldn't change things. |
MySQL testing: I built Jarvis with/without this PR for x86 and as far as I can tell it's working as expected - with this PR it's a few seconds quicker than without (when querying MySQL and Kodi seem to be returning the correct results for various If you produce a version of this PR for master I can test on RPi2 hardware, should this be necessary. With this PR the following query is being executed for
Without this PR the query is:
In MySQL Workbench, the timings for either query is essentially the same:
On this basis, elimination of the repeated 👍 Not related to this PR but I'll include it anyway as something else to think about (and I've got the test data!)... the majority of the remaining time during the end-to-end test is now taken by the repeated artwork queries:
ie. for
The end-to-end test which produced the above queries took 15.071 seconds to transfer all data, ~15 seconds of which is spent querying artwork (this is testing on a fast x86 box so time spent crunching the data is now minimal).
The same end-to-end test but without the |
The speed impact of left join on views elsewhere in Jarvis is much smaller, so at this stage (release Sunday) I would say best left as it is. For Krypton I will look at changes across the music database, it has a greater impact. I didn't spot any left joins on views in video, but will check again. |
Anyway to have the tests builds ? :) I have no faith in rebuilding all deps and everything for Jarvis :( |
kicked a win32 build. http://jenkins.kodi.tv/job/WIN-32/7811/ |
Already built for all platforms http://jenkins.kodi.tv/job/WIN-32/7809/ @MartijnKaijser @Tolriq, like I said I would in the first post. |
@MilhouseVH this problem with one-to-many relationships has been know for a few years. Specifically for artwork I once tried to optimize it by storing the different artwork for a single item in JSON in an extra column in the item's table (e.g. |
bb61d14
to
23d1a77
Compare
@DaveTBlake Ok so have tested this one. All works OK and it's even faster with this patch than in 15.2 so all good. (from Yatse 22s instead of 26s for the 22k songs in 750 chunks, way better than the 60s) Next time as Montellese do, do not hesitate to ping me for tests and feedback ;) Glad to have found this before release. |
Thanks all for the testing, it seems we are good to go :) [Edit: Famous last words - no we weren't]
Yes indeed. The optimiser bug was a surprise, but that is what optimisers sometimes do. I should know that after all these years of DB work! I will incorporate changes to Krypton in due course. |
else | ||
{ | ||
strSQL = PrepareSQL(strSQL, !filter.fields.empty() && filter.fields.compare("*") != 0 ? filter.fields.c_str() : "songview.*, songartistview.* "); | ||
{ // Get data from song and song_artist tables to fully populate songs with artists |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
23d1a77
to
b5b6c3d
Compare
I have tested this as well and found an issue. It does not return songs without artist in id3 tags. |
Good catch @Millencolin, got so focused on speed I missed testing the original point of the left join!! Of course in splitting the songartistview into consituant tables they both have to be left join or the songs without artists stil get missed. |
…t makes left join on views very slow
b5b6c3d
to
e957065
Compare
Have fixed query so that it does return songs that don't have an artist (the point of adding the left join in the first place!). It doesn't seem to impact timings too much, the optimiser is still using the right plan, but it is necessary anyway. @Tolriq could you test this with your 902 songs without artists please an ensure we get them. A build will be on the mirrors for you in due course. |
Here's a win32 test build http://mirrors.kodi.tv/test-builds/win32/KodiSetup-20160212-01b104a-HEAD.exe |
Will test again but not available before a few hours :( |
Ok so tested, all 22079 songs are correctly returned with correct data. 23s from Yatse, but since 902 more songs timing is unchanged and still better than 15.2. |
Thanks @Tolriq that is a satisfying result. I'm going to hit merge then as it is what we want in 16.0 |
Jarvis restore AudioLibrary.GetSongs speed in SQLlite work around Left Join query optimiser bug
AudioLibrary.GetSongs
is at least 3 times slower in current build compared to RC2 on SQLite (but not MySQL). This regression is caused by a bug in the way the SQLite query optimiser deals with left joins between views. A suboptimal query plan is applied, this issue is discussed at length in #9081. The left join was introduced in #8993 to ensure that songs without artists were returned.As a work around songartistview is replaced with the explicit song_artist and artist tables. The alternative fix for applying limits to number of songs that works in MySQL is applied modifying that patched in #9034. In addition only those artist fields exposed by the API are queried, and the unncecessary loading of replaygain from cuesheet is removed, as replaygain is not exposed by the API, this also improves the speed.
Also the half-attempt at querying specific fields is removed, as it was not supported by the way CFileItem is filled and did not work. Must have been unused.
@MilhouseVH could you check this in MySQL please, I don't want to introduce more issues!
@Tolriq, @phate89 and @razzeee hope this makes sense from our discussion. More can be done in Krypton, but want to fix Jarvis as quickly and simply as possible.
@Montellese do changes to the underlying query require an API version change?
Thorough testing appreciated, will set a test build going for that and upload to mirrors.