Commit fd3f08ec authored by Samuel Gyger's avatar Samuel Gyger Committed by Andres G. Aragoneses

Database: fix performance for the new SQLite's query planner (bgo#740879)

Starting with sqlite version 3.8.6, a new query planner is used.
To get back the performance on filling the CoreCache Table,
this commit provides hints to sqlite (using the UNLIKELY statement).
But the UNLIKELY statement is only supported in version 3.8.1 and
above, so in order not to raise the version of the dependency on
sqlite, we can use this new clause conditionally.
parent a0c4490d
......@@ -46,7 +46,7 @@ namespace Banshee.Collection.Database
ReloadFragmentFormat = @"
FROM CoreArtists WHERE CoreArtists.ArtistID IN
(SELECT CoreAlbums.ArtistID FROM CoreAlbums, CoreTracks, CoreCache{0}
WHERE CoreCache.ModelID = {1} AND
WHERE {4}(CoreCache.ModelID = {1}) AND
CoreTracks.AlbumID = CoreAlbums.AlbumID AND
EXISTS (SELECT 1 FROM CoreArtists WHERE ArtistID = CoreAlbums.ArtistID) AND
CoreCache.ItemID = {2} {3})
......
......@@ -58,7 +58,7 @@ namespace Banshee.Collection.Database
ReloadFragmentFormat = @"
FROM CoreAlbums WHERE CoreAlbums.AlbumID IN
(SELECT CoreTracks.AlbumID FROM CoreTracks, CoreCache{0}
WHERE CoreCache.ModelID = {1} AND
WHERE {4}(CoreCache.ModelID = {1}) AND
CoreCache.ItemId = {2} {3})
ORDER BY CoreAlbums.TitleSortKey, CoreAlbums.ArtistNameSortKey";
}
......
......@@ -49,7 +49,7 @@ namespace Banshee.Collection.Database
ReloadFragmentFormat = @"
FROM CoreArtists WHERE CoreArtists.ArtistID IN
(SELECT CoreTracks.ArtistID FROM CoreTracks, CoreCache{0}
WHERE CoreCache.ModelID = {1} AND
WHERE {4}(CoreCache.ModelID = {1}) AND
CoreCache.ItemID = {2} {3})
ORDER BY NameSortKey";
}
......
......@@ -57,10 +57,10 @@ namespace Banshee.Collection.Database
}
protected readonly U select_all_item;
private HyenaSqliteConnection connection;
private BansheeDbConnection connection;
public DatabaseFilterListModel (string name, string label, Banshee.Sources.DatabaseSource source,
DatabaseTrackListModel trackModel, HyenaSqliteConnection connection, SqliteModelProvider<T> provider, U selectAllItem, string uuid)
DatabaseTrackListModel trackModel, BansheeDbConnection connection, SqliteModelProvider<T> provider, U selectAllItem, string uuid)
: base (trackModel)
{
this.source = source;
......@@ -124,7 +124,8 @@ namespace Banshee.Collection.Database
"{0}.{1} AND CoreTracks.TrackID = {0}.{2}",
FilteredModel.JoinTable, FilteredModel.JoinPrimaryKey, FilteredModel.JoinColumn)
: "CoreTracks.TrackID",
filtered ? GetFilterFragment () : ""
filtered ? GetFilterFragment () : "",
connection.LikelihoodSupport ? "UNLIKELY" : ""
);
}
......
......@@ -37,6 +37,7 @@ using Hyena.Data.Sqlite;
using Mono.Unix;
using Banshee.ServiceStack;
using Banshee.Database;
namespace Banshee.Collection.Database
{
......@@ -51,7 +52,7 @@ namespace Banshee.Collection.Database
private string select_all_fmt;
public DatabaseQueryFilterModel (Banshee.Sources.DatabaseSource source, DatabaseTrackListModel trackModel,
HyenaSqliteConnection connection, string select_all_fmt, string uuid, QueryField field, string filter_column)
BansheeDbConnection connection, string select_all_fmt, string uuid, QueryField field, string filter_column)
: base (field.Name, field.Label, source, trackModel, connection, QueryFilterInfo<T>.CreateProvider (filter_column, field), new QueryFilterInfo<T> (), String.Format ("{0}-{1}", uuid, field.Name))
{
this.field = field;
......@@ -59,7 +60,7 @@ namespace Banshee.Collection.Database
ReloadFragmentFormat = @"
FROM CoreTracks, CoreCache{0}
WHERE CoreCache.ModelID = {1} AND CoreCache.ItemID = {2} {3}
WHERE {4}(CoreCache.ModelID = {1}) AND CoreCache.ItemID = {2} {3}
ORDER BY Value";
QueryFields = new QueryFieldSet (query_filter_field);
......
......@@ -47,7 +47,7 @@ namespace Banshee.Collection.Database
FROM (SELECT MIN(CoreTracks.TrackID) AS TrackID, CoreTracks.Year FROM CoreTracks GROUP BY CoreTracks.Year) AS CoreTracks
WHERE CoreTracks.Year IN
(SELECT CoreTracks.Year FROM CoreTracks, CoreCache{0}
WHERE CoreCache.ModelID = {1} AND
WHERE {4}(CoreCache.ModelID = {1}) AND
CoreCache.ItemID = {2} {3})
ORDER BY Year";
}
......
......@@ -52,6 +52,16 @@ namespace Banshee.Database
get { return configuration; }
}
private bool? likelihood_support = null;
public bool LikelihoodSupport {
get {
if (!likelihood_support.HasValue) {
likelihood_support = Query<bool> ("SELECT sqlite_version () >= '3.8.1'");
}
return likelihood_support.Value;
}
}
public BansheeDbConnection () : this (DatabaseFile)
{
validate_schema = ApplicationContext.CommandLine.Contains ("validate-db-schema");
......
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