Commit 21462918 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Add various missing indices

See https://www.sqlite.org/foreignkeys.html#fk_indexes
Having an index on any column that is a foreign key is advisable (if not
strongly recommended)
parent e32bbef6
......@@ -360,9 +360,12 @@ bool Album::createTable(DBConnection dbConnection )
"title,"
"artist"
")";
static const std::string indexReq = "CREATE INDEX IF NOT EXISTS album_artist_id_idx ON " +
policy::AlbumTable::Name + "(artist_id)";
return sqlite::Tools::executeRequest( dbConnection, req ) &&
sqlite::Tools::executeRequest( dbConnection, reqRel ) &&
sqlite::Tools::executeRequest( dbConnection, vtableReq );
sqlite::Tools::executeRequest( dbConnection, vtableReq ) &&
sqlite::Tools::executeRequest( dbConnection, indexReq );
}
bool Album::createTriggers(DBConnection dbConnection)
......
......@@ -119,9 +119,12 @@ bool AlbumTrack::createTable( DBConnection dbConnection )
" BEGIN"
" UPDATE " + policy::AlbumTrackTable::Name + " SET is_present = new.is_present WHERE media_id = new.id_media;"
" END";
static const std::string indexReq = "CREATE INDEX IF NOT EXISTS album_media_artist_genre_album_idx ON " +
policy::AlbumTrackTable::Name + "(media_id, artist_id, genre_id, album_id)";
return sqlite::Tools::executeRequest( dbConnection, req ) &&
sqlite::Tools::executeRequest( dbConnection, triggerReq );
sqlite::Tools::executeRequest( dbConnection, triggerReq ) &&
sqlite::Tools::executeRequest( dbConnection, indexReq );
}
std::shared_ptr<AlbumTrack> AlbumTrack::create( MediaLibraryPtr ml, int64_t albumId,
......
......@@ -113,7 +113,10 @@ bool AudioTrack::createTable( DBConnection dbConnection )
"FOREIGN KEY ( media_id ) REFERENCES " + policy::MediaTable::Name
+ "( id_media ) ON DELETE CASCADE"
")";
return sqlite::Tools::executeRequest( dbConnection, req );
static const std::string indexReq = "CREATE INDEX IF NOT EXISTS audio_track_media_idx ON " +
policy::AudioTrackTable::Name + "(media_id)";
return sqlite::Tools::executeRequest( dbConnection, req ) &&
sqlite::Tools::executeRequest( dbConnection, indexReq );
}
std::shared_ptr<AudioTrack> AudioTrack::create( MediaLibraryPtr ml, const std::string& codec,
......
......@@ -129,7 +129,10 @@ bool Movie::createTable( DBConnection dbConnection )
"FOREIGN KEY(media_id) REFERENCES " + policy::MediaTable::Name
+ "(id_media) ON DELETE CASCADE"
")";
return sqlite::Tools::executeRequest( dbConnection, req );
static const std::string indexReq = "CREATE INDEX IF NOT EXISTS movie_media_idx ON " +
policy::MovieTable::Name + "(media_id)";
return sqlite::Tools::executeRequest( dbConnection, req ) &&
sqlite::Tools::executeRequest( dbConnection, indexReq );
}
std::shared_ptr<Movie> Movie::create(MediaLibraryPtr ml, int64_t mediaId, const std::string& title )
......
......@@ -170,7 +170,10 @@ bool ShowEpisode::createTable( DBConnection dbConnection )
"FOREIGN KEY(show_id) REFERENCES " + policy::ShowTable::Name
+ "(id_show) ON DELETE CASCADE"
")";
return sqlite::Tools::executeRequest( dbConnection, req );
const std::string indexReq = "CREATE INDEX IF NOT EXISTS show_episode_media_show_idx ON " +
policy::ShowEpisodeTable::Name + "(media_id, show_id)";
return sqlite::Tools::executeRequest( dbConnection, req ) &&
sqlite::Tools::executeRequest( dbConnection, indexReq );
}
std::shared_ptr<ShowEpisode> ShowEpisode::create( MediaLibraryPtr ml, int64_t mediaId, const std::string& title, unsigned int episodeNumber, int64_t showId )
......
......@@ -121,7 +121,10 @@ bool VideoTrack::createTable( DBConnection dbConnection )
"FOREIGN KEY ( media_id ) REFERENCES " + policy::MediaTable::Name +
"(id_media) ON DELETE CASCADE"
")";
return sqlite::Tools::executeRequest( dbConnection, req );
static const std::string indexReq = "CREATE INDEX IF NOT EXISTS video_track_media_idx ON " +
policy::VideoTrackTable::Name + "(media_id)";
return sqlite::Tools::executeRequest( dbConnection, req ) &&
sqlite::Tools::executeRequest( dbConnection, indexReq );
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment