Skip to content
This repository
Browse code

Merge pull request #3386 from Montellese/xsp_sql_optims

Optimisations for SQL queries generated for smartplaylists
  • Loading branch information...
commit ac2ac41c88609a7561f100e42369851bd3573fdf 2 parents 95dcfcf + 9dfe507
Sascha Montellese authored October 10, 2013

Showing 1 changed file with 52 additions and 49 deletions. Show diff stats Hide diff stats

  1. 101  xbmc/playlists/SmartPlayList.cpp
101  xbmc/playlists/SmartPlayList.cpp
@@ -812,7 +812,7 @@ void CSmartPlaylistRule::SetParameter(const std::vector<CStdString> &values)
812 812
 
813 813
 CStdString CSmartPlaylistRule::GetVideoResolutionQuery(const CStdString &parameter) const
814 814
 {
815  
-  CStdString retVal(" in (select distinct idFile from streamdetails where iVideoWidth ");
  815
+  CStdString retVal(" IN (SELECT DISTINCT idFile FROM streamdetails WHERE iVideoWidth ");
816 816
   int iRes = (int)strtol(parameter.c_str(), NULL, 10);
817 817
 
818 818
   int min, max;
@@ -824,21 +824,22 @@ CStdString CSmartPlaylistRule::GetVideoResolutionQuery(const CStdString &paramet
824 824
   switch (m_operator)
825 825
   {
826 826
     case OPERATOR_EQUALS:
827  
-      retVal.AppendFormat(">= %i and iVideoWidth <= %i)", min, max);
  827
+      retVal.AppendFormat(">= %i AND iVideoWidth <= %i", min, max);
828 828
       break;
829 829
     case OPERATOR_DOES_NOT_EQUAL:
830  
-      retVal.AppendFormat("< %i or iVideoWidth > %i)", min, max);
  830
+      retVal.AppendFormat("< %i OR iVideoWidth > %i", min, max);
831 831
       break;
832 832
     case OPERATOR_LESS_THAN:
833  
-      retVal.AppendFormat("< %i)", min);
  833
+      retVal.AppendFormat("< %i", min);
834 834
       break;
835 835
     case OPERATOR_GREATER_THAN:
836  
-      retVal.AppendFormat("> %i)", max);
  836
+      retVal.AppendFormat("> %i", max);
837 837
       break;
838 838
     default:
839  
-      retVal += ")";
840 839
       break;
841 840
   }
  841
+
  842
+  retVal += ")";
842 843
   return retVal;
843 844
 }
844 845
 
@@ -921,22 +922,24 @@ CStdString CSmartPlaylistRule::GetWhereClause(const CDatabase &db, const CStdStr
921 922
     if (strType == "movies")
922 923
     {
923 924
       if (m_field == FieldInProgress)
924  
-        return "movieview.idFile " + negate + " IN (select idFile from bookmark where type = 1)";
  925
+        return "movieview.idFile " + negate + " IN (SELECT DISTINCT idFile FROM bookmark WHERE type = 1)";
925 926
       else if (m_field == FieldTrailer)
926 927
         return negate + GetField(m_field, strType) + "!= ''";
927 928
     }
928 929
     else if (strType == "episodes")
929 930
     {
930 931
       if (m_field == FieldInProgress)
931  
-        return "episodeview.idFile " + negate + " IN (select idFile from bookmark where type = 1)";
  932
+        return "episodeview.idFile " + negate + " IN (SELECT DISTINCT idFile FROM bookmark WHERE type = 1)";
932 933
     }
933 934
     else if (strType == "tvshows")
934 935
     {
935 936
       if (m_field == FieldInProgress)
936  
-        return GetField(FieldId, strType) + negate + " IN (select " + GetField(FieldId, strType) + " from tvshowview where "
937  
-               "(watchedcount > 0 AND watchedcount < totalCount) OR "
938  
-               "(watchedcount = 0 AND " + GetField(FieldId, strType) + " IN "
939  
-               "(select episodeview.idShow from episodeview WHERE episodeview.idShow = " + GetField(FieldId, strType) + " AND episodeview.resumeTimeInSeconds > 0)))";
  937
+        return negate + " ("
  938
+            "(tvshowview.watchedcount > 0 AND tvshowview.watchedcount < tvshowview.totalCount) OR "
  939
+            "(tvshowview.watchedcount = 0 AND EXISTS "
  940
+              "(SELECT 1 FROM episodeview WHERE episodeview.idShow = " + GetField(FieldId, strType) + " AND episodeview.resumeTimeInSeconds > 0)"
  941
+            ")"
  942
+          ")";
940 943
     }
941 944
   }
942 945
 
@@ -999,11 +1002,11 @@ CStdString CSmartPlaylistRule::GetWhereClause(const CDatabase &db, const CStdStr
999 1002
       table = "songview";
1000 1003
 
1001 1004
       if (m_field == FieldGenre)
1002  
-        query = GetField(FieldId, strType) + negate + " IN (SELECT idSong FROM song_genre, genre WHERE song_genre.idGenre = genre.idGenre AND genre.strGenre" + parameter + ")";
  1005
+        query = negate + " EXISTS (SELECT 1 FROM song_genre, genre WHERE song_genre.idSong = " + GetField(FieldId, strType) + " AND song_genre.idGenre = genre.idGenre AND genre.strGenre" + parameter + ")";
1003 1006
       else if (m_field == FieldArtist)
1004  
-        query = GetField(FieldId, strType) + negate + " IN (SELECT idSong FROM song_artist, artist WHERE song_artist.idArtist = artist.idArtist AND artist.strArtist" + parameter + ")";
  1007
+        query = negate + " EXISTS (SELECT 1 FROM song_artist, artist WHERE song_artist.idSong = " + GetField(FieldId, strType) + " AND song_artist.idArtist = artist.idArtist AND artist.strArtist" + parameter + ")";
1005 1008
       else if (m_field == FieldAlbumArtist)
1006  
-        query = table + ".idAlbum" + negate + " IN (SELECT idAlbum FROM album_artist, artist WHERE album_artist.idArtist = artist.idArtist AND artist.strArtist" + parameter + ")";
  1009
+        query = negate + " EXISTS (SELECT 1 FROM album_artist, artist WHERE album_artist.idAlbum = " + table + "idAlbum AND album_artist.idArtist = artist.idArtist AND artist.strArtist" + parameter + ")";
1007 1010
       else if (m_field == FieldLastPlayed && (m_operator == OPERATOR_LESS_THAN || m_operator == OPERATOR_BEFORE || m_operator == OPERATOR_NOT_IN_THE_LAST))
1008 1011
         query = GetField(m_field, strType) + " is NULL or " + GetField(m_field, strType) + parameter;
1009 1012
     }
@@ -1012,111 +1015,111 @@ CStdString CSmartPlaylistRule::GetWhereClause(const CDatabase &db, const CStdStr
1012 1015
       table = "albumview";
1013 1016
 
1014 1017
       if (m_field == FieldGenre)
1015  
-        query = GetField(FieldId, strType) + negate + " IN (SELECT song.idAlbum FROM song, song_genre, genre WHERE song.idSong = song_genre.idSong AND song_genre.idGenre = genre.idGenre AND genre.strGenre" + parameter + ")";
  1018
+        query = negate + " EXISTS (SELECT 1 FROM song, song_genre, genre WHERE song.idAlbum = " + GetField(FieldId, strType) + " AND song.idSong = song_genre.idSong AND song_genre.idGenre = genre.idGenre AND genre.strGenre" + parameter + ")";
1016 1019
       else if (m_field == FieldArtist)
1017  
-        query = GetField(FieldId, strType) + negate + " IN (SELECT song.idAlbum FROM song, song_artist, artist WHERE song.idSong = song_artist.idSong AND song_artist.idArtist = artist.idArtist AND artist.strArtist" + parameter + ")";
  1020
+        query = negate + " EXISTS (SELECT 1 FROM song, song_artist, artist WHERE song.idAlbum = " + GetField(FieldId, strType) + " AND song.idSong = song_artist.idSong AND song_artist.idArtist = artist.idArtist AND artist.strArtist" + parameter + ")";
1018 1021
       else if (m_field == FieldAlbumArtist)
1019  
-        query = GetField(FieldId, strType) + negate + " IN (SELECT album_artist.idAlbum FROM album_artist, artist WHERE album_artist.idArtist = artist.idArtist AND artist.strArtist" + parameter + ")";
  1022
+        query = negate + " EXISTS (SELECT 1 FROM album_artist, artist WHERE album_artist.idAlbum = " + GetField(FieldId, strType) + " AND album_artist.idArtist = artist.idArtist AND artist.strArtist" + parameter + ")";
1020 1023
     }
1021 1024
     else if (strType == "artists")
1022 1025
     {
1023 1026
       table = "artistview";
1024 1027
 
1025 1028
       if (m_field == FieldGenre)
1026  
-        query = GetField(FieldId, strType) + negate + " IN (SELECT song_artist.idArtist FROM song_artist, song_genre, genre WHERE song_artist.idSong = song_genre.idSong AND song_genre.idGenre = genre.idGenre AND genre.strGenre" + parameter + ")";
  1029
+        query = negate + " EXISTS (SELECT DISTINCT song_artist.idArtist FROM song_artist, song_genre, genre WHERE song_artist.idArtist = " + GetField(FieldId, strType) + " AND song_artist.idSong = song_genre.idSong AND song_genre.idGenre = genre.idGenre AND genre.strGenre" + parameter + ")";
1027 1030
     }
1028 1031
     else if (strType == "movies")
1029 1032
     {
1030 1033
       table = "movieview";
1031 1034
 
1032 1035
       if (m_field == FieldGenre)
1033  
-        query = GetField(FieldId, strType) + negate + " IN (SELECT idMovie FROM genrelinkmovie JOIN genre ON genre.idGenre=genrelinkmovie.idGenre WHERE genre.strGenre" + parameter + ")";
  1036
+        query = negate + " EXISTS (SELECT 1 FROM genrelinkmovie JOIN genre ON genre.idGenre=genrelinkmovie.idGenre WHERE genrelinkmovie.idMovie = " + GetField(FieldId, strType) + " AND genre.strGenre" + parameter + ")";
1034 1037
       else if (m_field == FieldDirector)
1035  
-        query = GetField(FieldId, strType) + negate + " IN (SELECT idMovie FROM directorlinkmovie JOIN actors ON actors.idActor=directorlinkmovie.idDirector WHERE actors.strActor" + parameter + ")";
  1038
+        query = negate + " EXISTS (SELECT 1 FROM directorlinkmovie JOIN actors ON actors.idActor=directorlinkmovie.idDirector WHERE directorlinkmovie.idMovie = " + GetField(FieldId, strType) + " AND actors.strActor" + parameter + ")";
1036 1039
       else if (m_field == FieldActor)
1037  
-        query = GetField(FieldId, strType) + negate + " IN (SELECT idMovie FROM actorlinkmovie JOIN actors ON actors.idActor=actorlinkmovie.idActor WHERE actors.strActor" + parameter + ")";
  1040
+        query = negate + " EXISTS (SELECT 1 FROM actorlinkmovie JOIN actors ON actors.idActor=actorlinkmovie.idActor WHERE actorlinkmovie.idMovie = " + GetField(FieldId, strType) + " AND actors.strActor" + parameter + ")";
1038 1041
       else if (m_field == FieldWriter)
1039  
-        query = GetField(FieldId, strType) + negate + " IN (SELECT idMovie FROM writerlinkmovie JOIN actors ON actors.idActor=writerlinkmovie.idWriter WHERE actors.strActor" + parameter + ")";
  1042
+        query = negate + " EXISTS (SELECT 1 FROM writerlinkmovie JOIN actors ON actors.idActor=writerlinkmovie.idWriter WHERE writerlinkmovie.idMovie = " + GetField(FieldId, strType) + " AND actors.strActor" + parameter + ")";
1040 1043
       else if (m_field == FieldStudio)
1041  
-        query = GetField(FieldId, strType) + negate + " IN (SELECT idMovie FROM studiolinkmovie JOIN studio ON studio.idStudio=studiolinkmovie.idStudio WHERE studio.strStudio" + parameter + ")";
  1044
+        query = negate + " EXISTS (SELECT 1 FROM studiolinkmovie JOIN studio ON studio.idStudio=studiolinkmovie.idStudio WHERE studiolinkmovie.idMovie = " + GetField(FieldId, strType) + " AND studio.strStudio" + parameter + ")";
1042 1045
       else if (m_field == FieldCountry)
1043  
-        query = GetField(FieldId, strType) + negate + " IN (SELECT idMovie FROM countrylinkmovie JOIN country ON country.idCountry=countrylinkmovie.idCountry WHERE country.strCountry" + parameter + ")";
  1046
+        query = negate + " EXISTS (SELECT 1 FROM countrylinkmovie JOIN country ON country.idCountry=countrylinkmovie.idCountry WHERE countrylinkmovie.idMovie = " + GetField(FieldId, strType) + " AND country.strCountry" + parameter + ")";
1044 1047
       else if ((m_field == FieldLastPlayed || m_field == FieldDateAdded) && (m_operator == OPERATOR_LESS_THAN || m_operator == OPERATOR_BEFORE || m_operator == OPERATOR_NOT_IN_THE_LAST))
1045 1048
         query = GetField(m_field, strType) + " IS NULL OR " + GetField(m_field, strType) + parameter;
1046 1049
       else if (m_field == FieldTag)
1047  
-        query = GetField(FieldId, strType) + negate + " IN (SELECT idMedia FROM taglinks JOIN tag ON tag.idTag = taglinks.idTag WHERE tag.strTag" + parameter + " AND taglinks.media_type = 'movie')";
  1050
+        query = negate + " EXISTS (SELECT 1 FROM taglinks JOIN tag ON tag.idTag = taglinks.idTag WHERE taglinks.idMedia = " + GetField(FieldId, strType) + " AND tag.strTag" + parameter + " AND taglinks.media_type = 'movie')";
1048 1051
     }
1049 1052
     else if (strType == "musicvideos")
1050 1053
     {
1051 1054
       table = "musicvideoview";
1052 1055
 
1053 1056
       if (m_field == FieldGenre)
1054  
-        query = GetField(FieldId, strType) + negate + " IN (SELECT idMVideo FROM genrelinkmusicvideo JOIN genre ON genre.idGenre=genrelinkmusicvideo.idGenre WHERE genre.strGenre" + parameter + ")";
  1057
+        query = negate + " EXISTS (SELECT 1 FROM genrelinkmusicvideo JOIN genre ON genre.idGenre=genrelinkmusicvideo.idGenre WHERE genrelinkmusicvideo.idMVideo = " + GetField(FieldId, strType) + " AND genre.strGenre" + parameter + ")";
1055 1058
       else if (m_field == FieldArtist)
1056  
-        query = GetField(FieldId, strType) + negate + " IN (SELECT idMVideo FROM artistlinkmusicvideo JOIN actors ON actors.idActor=artistlinkmusicvideo.idArtist WHERE actors.strActor" + parameter + ")";
  1059
+        query = negate + " EXISTS (SELECT 1 FROM artistlinkmusicvideo JOIN actors ON actors.idActor=artistlinkmusicvideo.idArtist WHERE artistlinkmusicvideo.idMVideo = " + GetField(FieldId, strType) + " AND actors.strActor" + parameter + ")";
1057 1060
       else if (m_field == FieldStudio)
1058  
-        query = GetField(FieldId, strType) + negate + " IN (SELECT idMVideo FROM studiolinkmusicvideo JOIN studio ON studio.idStudio=studiolinkmusicvideo.idStudio WHERE studio.strStudio" + parameter + ")";
  1061
+        query = negate + " EXISTS (SELECT 1 FROM studiolinkmusicvideo JOIN studio ON studio.idStudio=studiolinkmusicvideo.idStudio WHERE studiolinkmusicvideo.idMVideo = " + GetField(FieldId, strType) + " AND studio.strStudio" + parameter + ")";
1059 1062
       else if (m_field == FieldDirector)
1060  
-        query = GetField(FieldId, strType) + negate + " IN (SELECT idMVideo FROM directorlinkmusicvideo JOIN actors ON actors.idActor=directorlinkmusicvideo.idDirector WHERE actors.strActor" + parameter + ")";
  1063
+        query = negate + " EXISTS (SELECT 1 FROM directorlinkmusicvideo JOIN actors ON actors.idActor=directorlinkmusicvideo.idDirector WHERE directorlinkmusicvideo.idMVideo = " + GetField(FieldId, strType) + " AND actors.strActor" + parameter + ")";
1061 1064
       else if ((m_field == FieldLastPlayed || m_field == FieldDateAdded) && (m_operator == OPERATOR_LESS_THAN || m_operator == OPERATOR_BEFORE || m_operator == OPERATOR_NOT_IN_THE_LAST))
1062 1065
         query = GetField(m_field, strType) + " IS NULL OR " + GetField(m_field, strType) + parameter;
1063 1066
       else if (m_field == FieldTag)
1064  
-        query = GetField(FieldId, strType) + negate + " IN (SELECT idMedia FROM taglinks JOIN tag ON tag.idTag = taglinks.idTag WHERE tag.strTag" + parameter + " AND taglinks.media_type = 'musicvideo')";
  1067
+        query = negate + " EXISTS (SELECT 1 FROM taglinks JOIN tag ON tag.idTag = taglinks.idTag WHERE taglinks.idMedia = " + GetField(FieldId, strType) + " AND tag.strTag" + parameter + " AND taglinks.media_type = 'musicvideo')";
1065 1068
     }
1066 1069
     else if (strType == "tvshows")
1067 1070
     {
1068 1071
       table = "tvshowview";
1069 1072
 
1070 1073
       if (m_field == FieldGenre)
1071  
-        query = GetField(FieldId, strType) + negate + " IN (SELECT idShow FROM genrelinktvshow JOIN genre ON genre.idGenre=genrelinktvshow.idGenre WHERE genre.strGenre" + parameter + ")";
  1074
+        query = negate + " EXISTS (SELECT 1 FROM genrelinktvshow JOIN genre ON genre.idGenre=genrelinktvshow.idGenre WHERE genrelinktvshow.idShow = " + GetField(FieldId, strType) + " AND genre.strGenre" + parameter + ")";
1072 1075
       else if (m_field == FieldDirector)
1073  
-        query = GetField(FieldId, strType) + negate + " IN (SELECT idShow FROM directorlinktvshow JOIN actors ON actors.idActor=directorlinktvshow.idDirector WHERE actors.strActor" + parameter + ")";
  1076
+        query = negate + " EXISTS (SELECT 1 FROM directorlinktvshow JOIN actors ON actors.idActor=directorlinktvshow.idDirector WHERE directorlinktvshow.idShow = " + GetField(FieldId, strType) + " AND actors.strActor" + parameter + ")";
1074 1077
       else if (m_field == FieldActor)
1075  
-        query = GetField(FieldId, strType) + negate + " IN (SELECT idShow FROM actorlinktvshow JOIN actors ON actors.idActor=actorlinktvshow.idActor WHERE actors.strActor" + parameter + ")";
  1078
+        query = negate + " EXISTS (SELECT 1 FROM actorlinktvshow JOIN actors ON actors.idActor=actorlinktvshow.idActor WHERE actorlinktvshow.idShow = " + GetField(FieldId, strType) + " AND actors.strActor" + parameter + ")";
1076 1079
       else if (m_field == FieldStudio)
1077  
-        query = GetField(FieldId, strType) + negate + " IN (SELECT idShow FROM tvshowview WHERE " + GetField(m_field, strType) + parameter + ")";
  1080
+        query = negate + " (" + GetField(m_field, strType) + parameter + ")";
1078 1081
       else if (m_field == FieldMPAA)
1079  
-        query = GetField(FieldId, strType) + negate + " IN (SELECT idShow FROM tvshowview WHERE " + GetField(m_field, strType) + parameter + ")";
  1082
+        query = negate + " (" + GetField(m_field, strType) + parameter + ")";
1080 1083
       else if ((m_field == FieldLastPlayed || m_field == FieldDateAdded) && (m_operator == OPERATOR_LESS_THAN || m_operator == OPERATOR_BEFORE || m_operator == OPERATOR_NOT_IN_THE_LAST))
1081 1084
         query = GetField(m_field, strType) + " IS NULL OR " + GetField(m_field, strType) + parameter;
1082 1085
       else if (m_field == FieldPlaycount)
1083 1086
         query = "CASE WHEN COALESCE(" + GetField(FieldNumberOfEpisodes, strType) + " - " + GetField(FieldNumberOfWatchedEpisodes, strType) + ", 0) > 0 THEN 0 ELSE 1 END " + parameter;
1084 1087
       else if (m_field == FieldTag)
1085  
-        query = GetField(FieldId, strType) + negate + " IN (SELECT idMedia FROM taglinks JOIN tag ON tag.idTag = taglinks.idTag WHERE tag.strTag" + parameter + " AND taglinks.media_type = 'tvshow')";
  1088
+        query = negate + " EXISTS (SELECT 1 FROM taglinks JOIN tag ON tag.idTag = taglinks.idTag WHERE taglinks.idMedia = " + GetField(FieldId, strType) + " AND tag.strTag" + parameter + " AND taglinks.media_type = 'tvshow')";
1086 1089
     }
1087 1090
     else if (strType == "episodes")
1088 1091
     {
1089 1092
       table = "episodeview";
1090 1093
 
1091 1094
       if (m_field == FieldGenre)
1092  
-        query = table + ".idShow" + negate + " IN (SELECT idShow FROM genrelinktvshow JOIN genre ON genre.idGenre=genrelinktvshow.idGenre WHERE genre.strGenre" + parameter + ")";
  1095
+        query = negate + " EXISTS (SELECT 1 FROM genrelinktvshow JOIN genre ON genre.idGenre=genrelinktvshow.idGenre WHERE genrelinktvshow.idShow = " + table + ".idShow AND genre.strGenre" + parameter + ")";
1093 1096
       else if (m_field == FieldDirector)
1094  
-        query = GetField(FieldId, strType) + negate + " IN (SELECT idEpisode FROM directorlinkepisode JOIN actors ON actors.idActor=directorlinkepisode.idDirector WHERE actors.strActor" + parameter + ")";
  1097
+        query = negate + " EXISTS (SELECT 1 FROM directorlinkepisode JOIN actors ON actors.idActor=directorlinkepisode.idDirector WHERE directorlinkepisode.idEpisode = " + GetField(FieldId, strType) + " AND actors.strActor" + parameter + ")";
1095 1098
       else if (m_field == FieldActor)
1096  
-        query = GetField(FieldId, strType) + negate + " IN (SELECT idEpisode FROM actorlinkepisode JOIN actors ON actors.idActor=actorlinkepisode.idActor WHERE actors.strActor" + parameter + ")";
  1099
+        query = negate + " EXISTS (SELECT 1 FROM actorlinkepisode JOIN actors ON actors.idActor=actorlinkepisode.idActor WHERE actorlinkepisode.idEpisode = " + GetField(FieldId, strType) + " AND actors.strActor" + parameter + ")";
1097 1100
       else if (m_field == FieldWriter)
1098  
-        query = GetField(FieldId, strType) + negate + " IN (SELECT idEpisode FROM writerlinkepisode JOIN actors ON actors.idActor=writerlinkepisode.idWriter WHERE actors.strActor" + parameter + ")";
  1101
+        query = negate + " EXISTS (SELECT 1 FROM writerlinkepisode JOIN actors ON actors.idActor=writerlinkepisode.idWriter WHERE writerlinkepisode.idEpisode = " + GetField(FieldId, strType) + " AND actors.strActor" + parameter + ")";
1099 1102
       else if ((m_field == FieldLastPlayed || m_field == FieldDateAdded) && (m_operator == OPERATOR_LESS_THAN || m_operator == OPERATOR_BEFORE || m_operator == OPERATOR_NOT_IN_THE_LAST))
1100 1103
         query = GetField(m_field, strType) + " IS NULL OR " + GetField(m_field, strType) + parameter;
1101 1104
       else if (m_field == FieldStudio)
1102  
-        query = GetField(FieldId, strType) + negate + " IN (SELECT idEpisode FROM episodeview WHERE strStudio" + parameter + ")";
  1105
+        query = negate + " (" + GetField(FieldId, strType) + parameter + ")";
1103 1106
       else if (m_field == FieldMPAA)
1104  
-        query = GetField(FieldId, strType) + negate + " IN (SELECT idEpisode FROM episodeview WHERE mpaa" + parameter + ")";
  1107
+        query = negate + " (" + GetField(FieldId, strType) +  parameter + ")";
1105 1108
     }
1106 1109
     if (m_field == FieldVideoResolution)
1107 1110
       query = table + ".idFile" + negate + GetVideoResolutionQuery(*it);
1108 1111
     else if (m_field == FieldAudioChannels)
1109  
-      query = table + ".idFile" + negate + " IN (SELECT DISTINCT idFile FROM streamdetails WHERE iAudioChannels " + parameter + ")";
  1112
+      query = negate + " EXISTS (SELECT 1 FROM streamdetails WHERE streamdetails.idFile = " + table + ".idFile AND iAudioChannels " + parameter + ")";
1110 1113
     else if (m_field == FieldVideoCodec)
1111  
-      query = table + ".idFile" + negate + " IN (SELECT DISTINCT idFile FROM streamdetails WHERE strVideoCodec " + parameter + ")";
  1114
+      query = negate + " EXISTS (SELECT 1 FROM streamdetails WHERE streamdetails.idFile = " + table + ".idFile AND strVideoCodec " + parameter + ")";
1112 1115
     else if (m_field == FieldAudioCodec)
1113  
-      query = table + ".idFile" + negate + " IN (SELECT DISTINCT idFile FROM streamdetails WHERE strAudioCodec " + parameter + ")";
  1116
+      query = negate + " EXISTS (SELECT 1 FROM streamdetails WHERE streamdetails.idFile = " + table + ".idFile AND strAudioCodec " + parameter + ")";
1114 1117
     else if (m_field == FieldAudioLanguage)
1115  
-      query = table + ".idFile" + negate + " IN (SELECT DISTINCT idFile FROM streamdetails WHERE strAudioLanguage " + parameter + ")";
  1118
+      query = negate + " EXISTS (SELECT 1 FROM streamdetails WHERE streamdetails.idFile = " + table + ".idFile AND strAudioLanguage " + parameter + ")";
1116 1119
     else if (m_field == FieldSubtitleLanguage)
1117  
-      query = table + ".idFile" + negate + " IN (SELECT DISTINCT idFile FROM streamdetails WHERE strSubtitleLanguage " + parameter + ")";
  1120
+      query = negate + " EXISTS (SELECT 1 FROM streamdetails WHERE streamdetails.idFile = " + table + ".idFile AND strSubtitleLanguage " + parameter + ")";
1118 1121
     else if (m_field == FieldVideoAspectRatio)
1119  
-      query = table + ".idFile" + negate + " IN (SELECT DISTINCT idFile FROM streamdetails WHERE fVideoAspect " + parameter + ")";
  1122
+      query = negate + " EXISTS (SELECT 1 FROM streamdetails WHERE streamdetails.idFile = " + table + ".idFile AND fVideoAspect " + parameter + ")";
1120 1123
     if (m_field == FieldPlaycount && strType != "songs" && strType != "albums" && strType != "tvshows")
1121 1124
     { // playcount IS stored as NULL OR number IN video db
1122 1125
       if ((m_operator == OPERATOR_EQUALS && it->Equals("0")) ||

0 notes on commit ac2ac41

Please sign in to comment.
Something went wrong with that request. Please try again.