Changeset 23946


Ignore:
Timestamp:
Feb 11, 2012, 7:55:25 AM (13 years ago)
Author:
Even Rouault
Message:

SQLite: speed-up opening of a result layer that has an ORDER BY

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gdal/ogr/ogrsf_frmts/sqlite/ogrsqlitedatasource.cpp

    r23945 r23946  
    12251225    sqlite3_stmt *hSQLStmt = NULL;
    12261226
    1227     rc = sqlite3_prepare( GetDB(), pszSQLCommand, strlen(pszSQLCommand),
     1227    CPLString osSQLCommand = pszSQLCommand;
     1228
     1229    /* This will speed-up layer creation */
     1230    /* ORDER BY are costly to evaluate and are not necessary to establish */
     1231    /* the layer definition. */
     1232    if( osSQLCommand.ifind("SELECT ") == 0 &&
     1233        osSQLCommand.ifind(" UNION ") == std::string::npos &&
     1234        osSQLCommand.ifind(" INTERSECT ") == std::string::npos &&
     1235        osSQLCommand.ifind(" EXCEPT ") == std::string::npos )
     1236    {
     1237        size_t nOrderByPos = osSQLCommand.ifind(" ORDER BY ");
     1238        if( nOrderByPos != std::string::npos )
     1239            osSQLCommand.resize(nOrderByPos);
     1240    }
     1241
     1242    rc = sqlite3_prepare( GetDB(), osSQLCommand.c_str(), osSQLCommand.size(),
    12281243                          &hSQLStmt, NULL );
    12291244
Note: See TracChangeset for help on using the changeset viewer.