Skip to content

Commit

Permalink
added: index to the basePath columns for faster retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Marshall committed Mar 8, 2011
1 parent 606fcbc commit cdb8fc1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions xbmc/video/VideoDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,12 @@ bool CVideoDatabase::CreateTables()
m_pDS->exec("CREATE TABLE setlinkmovie ( idSet integer, idMovie integer)\n");
m_pDS->exec("CREATE UNIQUE INDEX ix_setlinkmovie_1 ON setlinkmovie ( idSet, idMovie)\n");
m_pDS->exec("CREATE UNIQUE INDEX ix_setlinkmovie_2 ON setlinkmovie ( idMovie, idSet)\n");

// create basepath indices
m_pDS->exec("CREATE index ixMovieBasePath on movie(c22)");
m_pDS->exec("CREATE index ixMusicVideoBasePath on musicvideo(c13)");
m_pDS->exec("CREATE index ixEpisodeBasePath on episode(c18)");
m_pDS->exec("CREATE index ixTVShowBasePath on tvshow(c16)");
}
catch (...)
{
Expand Down Expand Up @@ -3465,6 +3471,13 @@ bool CVideoDatabase::UpdateOldVersion(int iVersion)
UpdateBasePath("episode", "idEpisode", VIDEODB_ID_EPISODE_BASEPATH);
UpdateBasePath("tvshow", "idShow", VIDEODB_ID_TV_BASEPATH, true);
}
if (iVersion < 46)
{ // add indices for dir entry lookups
m_pDS->exec("CREATE index ixMovieBasePath on movie(c22)");
m_pDS->exec("CREATE index ixMusicVideoBasePath on musicvideo(c13)");
m_pDS->exec("CREATE index ixEpisodeBasePath on episode(c18)");
m_pDS->exec("CREATE index ixTVShowBasePath on tvshow(c16)");
}
}
catch (...)
{
Expand Down
2 changes: 1 addition & 1 deletion xbmc/video/VideoDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ class CVideoDatabase : public CDatabase
*/
void UpdateBasePath(const char *table, const char *id, int column, bool shows = false);

virtual int GetMinVersion() const { return 45; };
virtual int GetMinVersion() const { return 46; };
const char *GetBaseDBName() const { return "MyVideos"; };

void ConstructPath(CStdString& strDest, const CStdString& strPath, const CStdString& strFileName);
Expand Down

9 comments on commit cdb8fc1

@Saviq
Copy link

@Saviq Saviq commented on cdb8fc1 Mar 11, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails with:

14:11:58 T:139768379459488 M:726536192  NOTICE: Attempting to update the database xbmc_video from version 44 to 46
14:12:07 T:139768379459488 M:725307392   ERROR: SQL: Undefined MySQL error: Code (1170)
    Query: CREATE index ixMovieBasePath on movie(c22)
14:12:07 T:139768379459488 M:725307392   ERROR: Error attempting to update the database version!

Since MySQL can't index TEXT/BLOBs without index length provided.

@jmarshallnz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup - I'm waiting on someone to test the obvious fix:

CREATE index ixMovieBasePath on movie(c22(255))

@opdenkamp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

works fine on mysql. not on sqlite though :)

dush@crichton:~/github/xbmc$ echo "CREATE index ixMovieBasePath on movie(c22 (255));" | sqlite3 ~/.xbmc/userdata/Database/MyVideos46.db
Error: near line 1: near "(": syntax error

@opdenkamp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could by the version of sqlite that I got installed

22:38:43 T:3024549696 M:2947600384 NOTICE: Attempting to update the database MyVideos46.db from version 44 to 46
22:38:43 T:3024549696 M:2947600384 ERROR: SQL: SQL error or missing database
Query: CREATE INDEX ixMovieBasePath ON movie ( c22(255) )
22:38:43 T:3024549696 M:2947600384 ERROR: Error attempting to update the database version!

@firnsy
Copy link
Contributor

@firnsy firnsy commented on cdb8fc1 Mar 11, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the exec() command will strip out the constrained index for sqlite databases within XBMC, so testing it at the command line will fail.

@firnsy
Copy link
Contributor

@firnsy firnsy commented on cdb8fc1 Mar 11, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change the queries to "CREATE UNIQUE INDEX" and it the filter will pick it up. "CREATE UNIQUE INDEX" is supported by both sqlite and mysql.

@opdenkamp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not unique though. if you make it unique, it'll fail when you add something with a large (>255 chars) length path.

@firnsy
Copy link
Contributor

@firnsy firnsy commented on cdb8fc1 Mar 11, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah very true, who has paths that long anyways ;)

the solution then is to add "CREATE INDEX" as a valid trigger for the filter in xbmc/dbwrappers/sqlitedataset.cpp

change line 484:
if ( qry.find("CREATE UNIQUE INDEX") != string::npos )

to something like (or similar to)

if ( (qry.find("CREATE UNIQUE INDEX") != string::npos) || (qry.find("CREATE INDEX") != string::npos) )

@opdenkamp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushed the fix in 999e8d0 and 8438004

Please sign in to comment.