Skip to content
Permalink
Browse files

make path and files indices non-unique. fixes issues with mysql and v…

…ery long paths (that are thus non-unique on the prefixed indices).
  • Loading branch information
Jonathan Marshall committed Dec 1, 2012
1 parent c427b2b commit eabf43282e3bb3132dea7c5275d614e65038d640
Showing with 10 additions and 3 deletions.
  1. +10 −3 xbmc/video/VideoDatabase.cpp
@@ -162,11 +162,11 @@ bool CVideoDatabase::CreateTables()

CLog::Log(LOGINFO, "create path table");
m_pDS->exec("CREATE TABLE path ( idPath integer primary key, strPath text, strContent text, strScraper text, strHash text, scanRecursive integer, useFolderNames bool, strSettings text, noUpdate bool, exclude bool, dateAdded text)");
m_pDS->exec("CREATE UNIQUE INDEX ix_path ON path ( strPath(255) )");
m_pDS->exec("CREATE INDEX ix_path ON path ( strPath(255) )");

CLog::Log(LOGINFO, "create files table");
m_pDS->exec("CREATE TABLE files ( idFile integer primary key, idPath integer, strFilename text, playCount integer, lastPlayed text, dateAdded text)");
m_pDS->exec("CREATE UNIQUE INDEX ix_files ON files ( idPath, strFilename(255) )");
m_pDS->exec("CREATE INDEX ix_files ON files ( idPath, strFilename(255) )");

CLog::Log(LOGINFO, "create tvshow table");
columns = "CREATE TABLE tvshow ( idShow integer primary key";
@@ -4296,14 +4296,21 @@ bool CVideoDatabase::UpdateOldVersion(int iVersion)
m_pDS->exec(PrepareSQL("update %s set c%02d=%d where id%s=%d", (i->first=="mvideo")?"musicvideo":i->first.c_str(), i->second, j->second, i->first.c_str(), j->first));
}
}
if (iVersion < 75)
{ // make indices on path, file non-unique (mysql has a prefix index, and prefixes aren't necessarily unique)
m_pDS->dropIndex("path", "ix_path");
m_pDS->dropIndex("files", "ix_files");
m_pDS->exec("CREATE INDEX ix_path ON path ( strPath(255) )");
m_pDS->exec("CREATE INDEX ix_files ON files ( idPath, strFilename(255) )");
}
// always recreate the view after any table change
CreateViews();
return true;
}

int CVideoDatabase::GetMinVersion() const
{
return 74;
return 75;
}

bool CVideoDatabase::LookupByFolders(const CStdString &path, bool shows)

2 comments on commit eabf432

@Montellese

This comment has been minimized.

Copy link
Member

@Montellese Montellese replied Dec 1, 2012

That doesn't look like a nice solution. Obviously it will work but maybe there's a proper solution for this?

@jmarshallnz

This comment has been minimized.

Copy link
Member

@jmarshallnz jmarshallnz replied Dec 1, 2012

There is no nice solution. mysql indices on text fields must be limited in length, and as we cannot have such a limit, the only solution is to have the index non-unique. It doesn't actually hurt anywhere for mysql - as the index is a prefix index it requires a row lookup anyway once the row numbers are found using the index. It may potentially hurt for sqlite, though I doubt it as the index there will be unique (it may just not know that fact).

Please sign in to comment.