IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 19582


Ignore:
Timestamp:
Sep 16, 2008, 10:09:43 AM (18 years ago)
Author:
Paul Price
Message:

Optimising difftool -inputskyfile: this was driving the load on the mysql server way high. The problem is that there were two sub-selects that are UNION-ed, and then the search criteria were applied. The new version applies the search criteria to each sub-select separately, resulting in about a 20-fold reduction in execution time. Main patch by Josh, with a small fix by me.

Location:
trunk/ippTools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/share/difftool_inputskyfile.sql

    r19092 r19582  
    3535        AND camRun.state = 'full'
    3636        AND chipRun.state = 'full'
     37        -- where hook %s
    3738    UNION
    3839    SELECT
     
    7172        AND camRun.state = 'full'
    7273        AND chipRun.state = 'full'
     74        -- where hook %s
    7375    ) as Foo
  • trunk/ippTools/src/difftool.c

    r19525 r19582  
    318318    }
    319319
     320    psString whereClause = NULL;
    320321    if (psListLength(where->list)) {
    321         psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    322         psStringAppend(&query, " WHERE %s", whereClause);
    323         psFree(whereClause);
    324     }
     322        whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     323        psStringPrepend(&whereClause, "\n AND ");
     324    }
     325    psFree(where);
    325326
    326327    // Add condition to get only templates or only inputs
    327328    {
    328         psString whereClause = NULL;
     329        psString templateClause = NULL;
    329330        if (template) {
    330             psStringAppend(&whereClause, " %s", " template != 0");
     331            psStringAppend(&templateClause, " %s", " template != 0");
    331332        } else if (input) {
    332             psStringAppend(&whereClause, " %s", " template = 0");
    333         }
    334         if (whereClause) {
    335             psStringAppend(&query, " %s %s", psListLength(where->list) ? "AND" : "WHERE", whereClause);
    336         }
    337         psFree(whereClause);
    338     }
    339 
    340     psFree(where);
     333            psStringAppend(&templateClause, " %s", " template = 0");
     334        }
     335        if (templateClause) {
     336            psStringAppend(&whereClause, "\n AND %s", templateClause);
     337        }
     338        psFree(templateClause);
     339    }
     340
    341341
    342342    // treat limit == 0 as "no limit"
     
    347347    }
    348348
    349     if (!p_psDBRunQuery(config->dbh, query)) {
    350         psError(PS_ERR_UNKNOWN, false, "database error");
     349    if (!p_psDBRunQuery(config->dbh, query, whereClause, whereClause)) {
     350        psError(PS_ERR_UNKNOWN, false, "database error");
     351        psFree(whereClause);
    351352        psFree(query);
    352353        return false;
    353354    }
     355    psFree(whereClause);
    354356    psFree(query);
    355357
Note: See TracChangeset for help on using the changeset viewer.