[128421] branches/release_2_3

jmr at macports.org jmr at macports.org
Thu Nov 20 16:32:48 PST 2014


Revision: 128421
          https://trac.macports.org/changeset/128421
Author:   jmr at macports.org
Date:     2014-11-20 16:32:48 -0800 (Thu, 20 Nov 2014)
Log Message:
-----------
merge r128113, r128274, r128276 from trunk:
 force use of a specific high-quality index to fix slowness with SQLite's new query planner first shipped with Yosemite, closes #45645

Revision Links:
--------------
    https://trac.macports.org/changeset/128113
    https://trac.macports.org/changeset/128274
    https://trac.macports.org/changeset/128276

Modified Paths:
--------------
    branches/release_2_3/base/src/cregistry/entry.c
    branches/release_2_3/base/src/cregistry/file.c

Property Changed:
----------------
    branches/release_2_3/
    branches/release_2_3/base/


Property changes on: branches/release_2_3
___________________________________________________________________
Modified: svn:mergeinfo
   - /trunk:118056,118085,118161,118640,118735,119034,119204,119297,120127,120132,120142,120345,120637,121311,121364,121451,123652,125578,125621,125859,126866,126868,126900
   + /trunk:118056,118085,118161,118640,118735,119034,119204,119297,120127,120132,120142,120345,120637,121311,121364,121451,123652,125578,125621,125859,126866,126868,126900,128113,128274,128276


Property changes on: branches/release_2_3/base
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/gsoc08-privileges/base:37343-46937
/branches/gsoc09-logging/base:51231-60371
/branches/gsoc11-rev-upgrade/base:78828-88375
/branches/gsoc11-statistics/base:79520,79666
/branches/gsoc13-tests:106692-111324
/branches/universal-sanity/base:51872-52323
/branches/variant-descs-14482/base:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/trunk/base:118038-118039,118056,118085,118161,118559,118562-118569,118598-118599,118602-118603,118606-118607,118640,118735,119034,119169,119171,119175,119204,119297,119987,119992,120036,120038,120059-120060,120064,120067-120069,120074,120076,120127,120132,120142,120345,120382,120637,121311,121364,121451,121485,123652,124145-124146,124150,124216,125578,125621,125859,126475,126866,126868,126895,126900
/users/perry/base-bugs_and_notes:45682-46060
/users/perry/base-select:44044-44692
   + /branches/gsoc08-privileges/base:37343-46937
/branches/gsoc09-logging/base:51231-60371
/branches/gsoc11-rev-upgrade/base:78828-88375
/branches/gsoc11-statistics/base:79520,79666
/branches/gsoc13-tests:106692-111324
/branches/universal-sanity/base:51872-52323
/branches/variant-descs-14482/base:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/trunk/base:118038-118039,118056,118085,118161,118559,118562-118569,118598-118599,118602-118603,118606-118607,118640,118735,119034,119169,119171,119175,119204,119297,119987,119992,120036,120038,120059-120060,120064,120067-120069,120074,120076,120127,120132,120142,120345,120382,120637,121311,121364,121451,121485,123652,124145-124146,124150,124216,125578,125621,125859,126475,126866,126868,126895,126900,128113,128274,128276
/users/perry/base-bugs_and_notes:45682-46060
/users/perry/base-select:44044-44692

Modified: branches/release_2_3/base/src/cregistry/entry.c
===================================================================
--- branches/release_2_3/base/src/cregistry/entry.c	2014-11-20 22:57:21 UTC (rev 128420)
+++ branches/release_2_3/base/src/cregistry/entry.c	2014-11-21 00:32:48 UTC (rev 128421)
@@ -185,11 +185,17 @@
     int lower_bound = 0;
     char* query;
     if (strlen(epoch) > 0) {
-        query = "SELECT id FROM registry.ports WHERE name=? AND version=? "
-        "AND revision=? AND variants=? AND epoch=?";
+        query = "SELECT id FROM registry.ports "
+#if SQLITE_VERSION_NUMBER >= 3006004
+                "INDEXED BY port_name "
+#endif
+                "WHERE name=? AND version=? AND revision=? AND variants=? AND epoch=?";
     } else {
-        query = "SELECT id FROM registry.ports WHERE name=? AND version=? "
-        "AND revision=? AND variants=? AND epoch!=?";
+        query = "SELECT id FROM registry.ports "
+#if SQLITE_VERSION_NUMBER >= 3006004
+                "INDEXED BY port_name "
+#endif
+                "WHERE name=? AND version=? AND revision=? AND variants=? AND epoch!=?";
     }
     if ((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
             && (sqlite3_bind_text(stmt, 1, name, -1, SQLITE_STATIC)
@@ -494,7 +500,11 @@
     if (name == NULL) {
         format = "%s WHERE state='installed'";
     } else {
-        format = "%s WHERE state='installed' AND name='%q'";
+        format = "%s "
+#if SQLITE_VERSION_NUMBER >= 3006004
+                "INDEXED BY port_name "
+#endif
+                "WHERE state='installed' AND name='%q'";
     }
     query = sqlite3_mprintf(format, select, name);
     result = reg_all_entries(reg, query, -1, entries, errPtr);
@@ -826,7 +836,11 @@
     reg_registry* reg = entry->reg;
     int result = 1;
     sqlite3_stmt* stmt = NULL;
-    char* query = "DELETE FROM registry.files WHERE path=? AND id=?";
+    char* query = "DELETE FROM registry.files "
+#if SQLITE_VERSION_NUMBER >= 3006004
+                  "INDEXED BY file_path "
+#endif
+                  "WHERE path=? AND id=?";
     if ((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
             && (sqlite3_bind_int64(stmt, 2, entry->id) == SQLITE_OK)) {
         int i;
@@ -1027,8 +1041,16 @@
     sqlite3_stmt* update = NULL;
     char* select_query = "SELECT id FROM registry.files WHERE actual_path=? "
         "AND active";
-    char* update_query = "UPDATE registry.files SET actual_path=?, active=1 "
-        "WHERE path=? AND id=?";
+    char* update_query = "UPDATE registry.files "
+#if SQLITE_VERSION_NUMBER >= 3006004
+        /* if the version of SQLite supports it force the usage of the index on
+         * path, rather than the one on id which has a lot less discriminative
+         * power and leads to very slow queries. This is needed for the new
+         * query planner introduced in 3.8.0 which would not use the correct
+         * index automatically. */
+        "INDEXED BY file_path "
+#endif
+        "SET actual_path=?, active=1 WHERE path=? AND id=?";
 
     /* if as_files wasn't specified, activate as the original files */
     if (as_files == NULL) {
@@ -1126,7 +1148,16 @@
     int result = 1;
     int i;
     sqlite3_stmt* stmt = NULL;
-    char* query = "UPDATE registry.files SET active=0 WHERE actual_path=? AND id=?";
+    char* query = "UPDATE registry.files "
+#if SQLITE_VERSION_NUMBER >= 3006004
+        /* if the version of SQLite supports it force the usage of the index on
+         * path, rather than the one on id which has a lot less discriminative
+         * power and leads to very slow queries. This is needed for the new
+         * query planner introduced in 3.8.0 which would not use the correct
+         * index automatically. */
+        "INDEXED BY file_actual "
+#endif
+        "SET active=0 WHERE actual_path=? AND id=?";
     if ((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
             && (sqlite3_bind_int64(stmt, 2, entry->id) == SQLITE_OK)) {
         for (i=0; i<file_count && result; i++) {

Modified: branches/release_2_3/base/src/cregistry/file.c
===================================================================
--- branches/release_2_3/base/src/cregistry/file.c	2014-11-20 22:57:21 UTC (rev 128420)
+++ branches/release_2_3/base/src/cregistry/file.c	2014-11-21 00:32:48 UTC (rev 128421)
@@ -105,7 +105,16 @@
         reg_error* errPtr) {
     sqlite3_stmt* stmt = NULL;
     reg_file* file = NULL;
-    char* query = "SELECT id, path FROM registry.files WHERE id=? AND path=?";
+    char* query = "SELECT id, path FROM registry.files "
+#if SQLITE_VERSION_NUMBER >= 3006004
+        /* if the version of SQLite supports it force the usage of the index on
+         * path, rather than the one on id which has a lot less discriminative
+         * power and leads to very slow queries. This is needed for the new
+         * query planner introduced in 3.8.0 which would not use the correct
+         * index automatically. */
+        "INDEXED BY file_path "
+#endif
+        "WHERE id=? AND path=?";
     int lower_bound = 0;
 
     if ((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
@@ -235,8 +244,17 @@
     sqlite3_stmt* stmt = NULL;
     char* query;
     const char *text;
-    query = sqlite3_mprintf("SELECT %q FROM registry.files WHERE id=%lld "
-            "AND path='%q'", key, file->key.id, file->key.path);
+    query = sqlite3_mprintf(
+            "SELECT %q FROM registry.files "
+#if SQLITE_VERSION_NUMBER >= 3006004
+            /* if the version of SQLite supports it force the usage of the index
+             * on path, rather than the one on id which has a lot less
+             * discriminative power and leads to very slow queries. This is
+             * needed for the new query planner introduced in 3.8.0 which would
+             * not use the correct index automatically. */
+            "INDEXED BY file_path "
+#endif
+            "WHERE id=%lld AND path='%q'", key, file->key.id, file->key.path);
     if (sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK) {
         int r;
         do {
@@ -290,8 +308,17 @@
     int result = 0;
     sqlite3_stmt* stmt = NULL;
     char* query;
-    query = sqlite3_mprintf("UPDATE registry.files SET %q = '%q' WHERE id=%lld "
-            "AND path='%q'", key, value, file->key.id, file->key.path);
+    query = sqlite3_mprintf(
+            "UPDATE registry.files "
+#if SQLITE_VERSION_NUMBER >= 3006004
+            /* if the version of SQLite supports it force the usage of the index
+             * on path, rather than the one on id which has a lot less
+             * discriminative power and leads to very slow queries. This is
+             * needed for the new query planner introduced in 3.8.0 which would
+             * not use the correct index automatically. */
+            "INDEXED BY file_path "
+#endif
+            "SET %q = '%q' WHERE id=%lld AND path='%q'", key, value, file->key.id, file->key.path);
     if (sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK) {
         int r;
         do {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/macports-changes/attachments/20141120/be44470a/attachment.html>


More information about the macports-changes mailing list