Skip to content

Commit 8b0daaf

Browse files
committed
Fix inefficiency in marking first/last showings without programids.
For users without programids (where listings provider doesn't specify a programid and doesn't specify both season and episode number), mythfilldatabase marks first/last showings by comparing title, subtitle, and description to find unique episodes. If the listings provider provides extremely long descriptions (>>255 characters), this results in mysqld creating on-disk temp tables, and can create extremely long run times for this specific query (with one user reporting times on the order of 30min using an AMD Athlon II 5050e with 2GB RAM). This change limits the query to use only the first 1024 characters of description for the SELECT and the GROUP BY. This is equivalent to what we were doing before ccb759a changed the description from TEXT to VARCHAR, since MySQL automatically uses max_sort_length (defaults to 1024) for sorting text and blob fields (including GROUP BY). Even in the event of 2 shows that differ only after the first 1024 characters of the description, but that air at the same time, the logic is sound. In the event 2 shows with different start times that differ only after the first 1024 characters of the description exist in the listings, one won't be properly marked as first/last showing, but I'd hope that listings providers would provide some indication of differences before the end of the novel (but, again, this is the same behavior we would have seen before the change to use VARCHAR for description). Thanks to Jan Schneider for noticing the issue and performing a bunch of test queries to help me find a way to work around it.
1 parent 1b75fdb commit 8b0daaf

File tree

1 file changed

+10
-8
lines changed
  • mythtv/programs/mythfilldatabase

1 file changed

+10
-8
lines changed

mythtv/programs/mythfilldatabase/main.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -595,9 +595,10 @@ int main(int argc, char *argv[])
595595
}
596596
}
597597
int found = query.size();
598-
query.prepare("SELECT MIN(starttime),title,subtitle,description "
598+
query.prepare("SELECT MIN(starttime),title,subtitle,"
599+
" LEFT(description, 1024) AS partdesc "
599600
"FROM program WHERE programid = '' "
600-
"GROUP BY title,subtitle,description;");
601+
"GROUP BY title,subtitle,partdesc;");
601602
if (query.exec())
602603
{
603604
while(query.next())
@@ -606,11 +607,11 @@ int main(int argc, char *argv[])
606607
"WHERE starttime = :STARTTIME "
607608
" AND title = :TITLE "
608609
" AND subtitle = :SUBTITLE "
609-
" AND description = :DESCRIPTION");
610+
" AND LEFT(description, 1024) = :PARTDESC");
610611
updt.bindValue(":STARTTIME", query.value(0).toDateTime());
611612
updt.bindValue(":TITLE", query.value(1).toString());
612613
updt.bindValue(":SUBTITLE", query.value(2).toString());
613-
updt.bindValue(":DESCRIPTION", query.value(3).toString());
614+
updt.bindValue(":PARTDESC", query.value(3).toString());
614615
if (!updt.exec())
615616
MythDB::DBError("Marking first showings", updt);
616617
}
@@ -635,9 +636,10 @@ int main(int argc, char *argv[])
635636
}
636637
}
637638
found = query.size();
638-
query.prepare("SELECT MAX(starttime),title,subtitle,description "
639+
query.prepare("SELECT MAX(starttime),title,subtitle,"
640+
" LEFT(description, 1024) AS partdesc "
639641
"FROM program WHERE programid = '' "
640-
"GROUP BY title,subtitle,description;");
642+
"GROUP BY title,subtitle,partdesc;");
641643
if (query.exec())
642644
{
643645
while(query.next())
@@ -646,11 +648,11 @@ int main(int argc, char *argv[])
646648
"WHERE starttime = :STARTTIME "
647649
" AND title = :TITLE "
648650
" AND subtitle = :SUBTITLE "
649-
" AND description = :DESCRIPTION");
651+
" AND LEFT(description, 1024) = :PARTDESC");
650652
updt.bindValue(":STARTTIME", query.value(0).toDateTime());
651653
updt.bindValue(":TITLE", query.value(1).toString());
652654
updt.bindValue(":SUBTITLE", query.value(2).toString());
653-
updt.bindValue(":DESCRIPTION", query.value(3).toString());
655+
updt.bindValue(":PARTDESC", query.value(3).toString());
654656
if (!updt.exec())
655657
MythDB::DBError("Marking last showings", updt);
656658
}

0 commit comments

Comments
 (0)