Changeset 128276 for trunk/base


Ignore:
Timestamp:
Nov 17, 2014, 11:31:21 PM (5 years ago)
Author:
cal@…
Message:

base: cregistry/entry.c: Fix queries using wrong indices with SQLite NGQP

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/base/src/cregistry/entry.c

    r128113 r128276  
    186186    char* query;
    187187    if (strlen(epoch) > 0) {
    188         query = "SELECT id FROM registry.ports WHERE name=? AND version=? "
    189         "AND revision=? AND variants=? AND epoch=?";
    190     } else {
    191         query = "SELECT id FROM registry.ports WHERE name=? AND version=? "
    192         "AND revision=? AND variants=? AND epoch!=?";
     188        query = "SELECT id FROM registry.ports "
     189#if SQLITE_VERSION_NUMBER >= 3006004
     190                "INDEXED BY port_name "
     191#endif
     192                "WHERE name=? AND version=? AND revision=? AND variants=? AND epoch=?";
     193    } else {
     194        query = "SELECT id FROM registry.ports "
     195#if SQLITE_VERSION_NUMBER >= 3006004
     196                "INDEXED BY port_name "
     197#endif
     198                "WHERE name=? AND version=? AND revision=? AND variants=? AND epoch!=?";
    193199    }
    194200    if ((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
     
    495501        format = "%s WHERE state='installed'";
    496502    } else {
    497         format = "%s WHERE state='installed' AND name='%q'";
     503        format = "%s "
     504#if SQLITE_VERSION_NUMBER >= 3006004
     505                "INDEXED BY port_name "
     506#endif
     507                "WHERE state='installed' AND name='%q'";
    498508    }
    499509    query = sqlite3_mprintf(format, select, name);
     
    827837    int result = 1;
    828838    sqlite3_stmt* stmt = NULL;
    829     char* query = "DELETE FROM registry.files WHERE path=? AND id=?";
     839    char* query = "DELETE FROM registry.files "
     840#if SQLITE_VERSION_NUMBER >= 3006004
     841                  "INDEXED BY file_path "
     842#endif
     843                  "WHERE path=? AND id=?";
    830844    if ((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
    831845            && (sqlite3_bind_int64(stmt, 2, entry->id) == SQLITE_OK)) {
     
    10311045#if SQLITE_VERSION_NUMBER >= 3006004
    10321046        /* if the version of SQLite supports it force the usage of the index on
    1033          * path, rather than the one on id (which has a lot less discriminative
    1034          * power) and leads to very slow queries. This is needed for the new
     1047         * path, rather than the one on id which has a lot less discriminative
     1048         * power and leads to very slow queries. This is needed for the new
    10351049         * query planner introduced in 3.8.0 which would not use the correct
    10361050         * index automatically. */
     
    11381152#if SQLITE_VERSION_NUMBER >= 3006004
    11391153        /* if the version of SQLite supports it force the usage of the index on
    1140          * path, rather than the one on id (which has a lot less discriminative
    1141          * power) and leads to very slow queries. This is needed for the new
     1154         * path, rather than the one on id which has a lot less discriminative
     1155         * power and leads to very slow queries. This is needed for the new
    11421156         * query planner introduced in 3.8.0 which would not use the correct
    11431157         * index automatically. */
Note: See TracChangeset for help on using the changeset viewer.