Ticket #3113: mythtv-CleanupRecordedTables-recordedmarkup_and_recordedseek-20070221.patch

File mythtv-CleanupRecordedTables-recordedmarkup_and_recordedseek-20070221.patch, 2.8 KB (added by sphery <mtdean@…>, 17 years ago)

Drop the temp table when done since we're using connection pooling; otherwise we end up with a bunch of little temprecordedcleanup tables. Replaces mythtv-CleanupRecordedTables?-recordedmarkup_and_recordedseek.patch .

  • programs/mythbackend/housekeeper.cpp

     
    362362        "recordedprogram",
    363363        "recordedrating",
    364364        "recordedcredits",
     365        "recordedmarkup",
     366        "recordedseek",
    365367        "" }; // This blank entry must exist, do not remove.
    366368    QString table = tables[tableIndex];
    367    
     369
     370    // Because recordedseek can have millions of rows, we don't want to JOIN it
     371    // with recorded.  Instead, pull out DISTINCT chanid and starttime into a
     372    // temporary table (resulting in tens, hundreds, or--at most--a few
     373    // thousand rows) for the JOIN
     374    QString querystr;
     375    querystr = "CREATE TEMPORARY TABLE IF NOT EXISTS temprecordedcleanup ("
     376               "chanid int(10) unsigned NOT NULL default '0',"
     377               "starttime datetime NOT NULL default '0000-00-00 00:00:00' );";
     378
     379    if (!query.exec(querystr))
     380    {
     381        MythContext::DBError("Housekeeper Creating Temporary Table", query);
     382        return;
     383    }
     384
    368385    while (table != "")
    369386    {
     387        query.prepare(QString("TRUNCATE TABLE temprecordedcleanup;"));
     388        if (!query.exec() || !query.isActive())
     389        {
     390            MythContext::DBError("Housekeeper Truncating Temporary Table",
     391                                 query);
     392            return;
     393        }
     394
     395        query.prepare(QString("INSERT INTO temprecordedcleanup "
     396                              "( chanid, starttime ) "
     397                              "SELECT DISTINCT chanid, starttime "
     398                              "FROM %1;")
     399                              .arg(table));
     400
     401        if (!query.exec() || !query.isActive())
     402        {
     403            MythContext::DBError("HouseKeeper Cleaning Recorded Tables", query);
     404            return;
     405        }
     406
    370407        query.prepare(QString("SELECT DISTINCT p.chanid, p.starttime "
    371                               "FROM %1 p LEFT JOIN recorded r "
     408                              "FROM temprecordedcleanup p "
     409                              "LEFT JOIN recorded r "
    372410                              "ON p.chanid = r.chanid "
    373411                              "AND p.starttime = r.progstart "
    374                               "WHERE r.chanid IS NULL;")
    375                               .arg(table));
     412                              "WHERE r.chanid IS NULL;"));
    376413        if (!query.exec() || !query.isActive())
    377414        {
    378415            MythContext::DBError("HouseKeeper Cleaning Recorded Tables", query);
     
    393430        tableIndex++;
    394431        table = tables[tableIndex];
    395432    }
     433
     434    if (!query.exec("DROP TABLE temprecordedcleanup;"))
     435        MythContext::DBError("Housekeeper Dropping Temporary Table", query);
     436
    396437}
    397438
    398439void HouseKeeper::CleanupProgramListings(void)