You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by rh...@apache.org on 2013/11/05 13:09:39 UTC

svn commit: r1538962 - in /subversion/trunk/subversion: libsvn_wc/upgrade.c libsvn_wc/wc-queries.sql libsvn_wc/wc_db.c tests/libsvn_wc/wc-queries-test.c

Author: rhuijben
Date: Tue Nov  5 12:09:38 2013
New Revision: 1538962

URL: http://svn.apache.org/r1538962
Log:
Add a working copy query test to automatically find queries with an idential
query plan as not having duplicates reduces maintenance and helps avoiding
query planner costs.

* subversion/libsvn_wc/upgrade.c
  (migrate_single_tree_conflict_data): Use existing instead of specialized
    queries.

* subversion/libsvn_wc/wc-queries.sql
  (STMT_DELETE_MOVED_BACK): Remove duplicate.
  (STMT_UPDATE_ACTUAL_CONFLICT_DATA,
   STMT_INSERT_ACTUAL_CONFLICT_DATA): Remove duplicates.

* subversion/libsvn_wc/wc_db.c
  (handle_move_back): Update query user.

* subversion/tests/libsvn_wc/wc-queries-test.c
  (includes): Add svn_hash.h.
  (test_query_duplicates): New function.
  (test_funcs): Add test_query_duplicates.

Modified:
    subversion/trunk/subversion/libsvn_wc/upgrade.c
    subversion/trunk/subversion/libsvn_wc/wc-queries.sql
    subversion/trunk/subversion/libsvn_wc/wc_db.c
    subversion/trunk/subversion/tests/libsvn_wc/wc-queries-test.c

Modified: subversion/trunk/subversion/libsvn_wc/upgrade.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/upgrade.c?rev=1538962&r1=1538961&r2=1538962&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/upgrade.c (original)
+++ subversion/trunk/subversion/libsvn_wc/upgrade.c Tue Nov  5 12:09:38 2013
@@ -755,13 +755,13 @@ migrate_single_tree_conflict_data(svn_sq
         {
           /* There is an existing ACTUAL row, so just update it. */
           SVN_ERR(svn_sqlite__get_statement(&stmt, sdb,
-                                            STMT_UPDATE_ACTUAL_CONFLICT_DATA));
+                                            STMT_UPDATE_ACTUAL_CONFLICT));
         }
       else
         {
           /* We need to insert an ACTUAL row with the tree conflict data. */
           SVN_ERR(svn_sqlite__get_statement(&stmt, sdb,
-                                            STMT_INSERT_ACTUAL_CONFLICT_DATA));
+                                            STMT_INSERT_ACTUAL_CONFLICT));
         }
 
       SVN_ERR(svn_sqlite__bindf(stmt, "iss", wc_id, conflict_relpath,

Modified: subversion/trunk/subversion/libsvn_wc/wc-queries.sql
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/wc-queries.sql?rev=1538962&r1=1538961&r2=1538962&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/wc-queries.sql (original)
+++ subversion/trunk/subversion/libsvn_wc/wc-queries.sql Tue Nov  5 12:09:38 2013
@@ -468,13 +468,6 @@ WHERE u.wc_id = ?1
   AND IS_STRICT_DESCENDANT_OF(u.local_relpath, ?2)
   AND u.op_depth = ?4
 
--- STMT_DELETE_MOVED_BACK
-DELETE FROM nodes
-WHERE wc_id = ?1
-  AND (local_relpath = ?2
-       OR IS_STRICT_DESCENDANT_OF(local_relpath, ?2))
-  AND op_depth = ?3
-
 -- STMT_DELETE_LOCK
 DELETE FROM lock
 WHERE repos_id = ?1 AND repos_relpath = ?2
@@ -1214,14 +1207,6 @@ VALUES (?1, ?2, ?3, ?4, ?5, ?6)
 
 /* these are used in upgrade.c  */
 
--- STMT_UPDATE_ACTUAL_CONFLICT_DATA
-UPDATE actual_node SET conflict_data = ?3
-WHERE wc_id = ?1 AND local_relpath = ?2
-
--- STMT_INSERT_ACTUAL_CONFLICT_DATA
-INSERT INTO actual_node (wc_id, local_relpath, conflict_data, parent_relpath)
-VALUES (?1, ?2, ?3, ?4)
-
 -- STMT_SELECT_ALL_FILES
 SELECT local_relpath FROM nodes_current
 WHERE wc_id = ?1 AND parent_relpath = ?2 AND kind = MAP_FILE

Modified: subversion/trunk/subversion/libsvn_wc/wc_db.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/wc_db.c?rev=1538962&r1=1538961&r2=1538962&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/wc_db.c (original)
+++ subversion/trunk/subversion/libsvn_wc/wc_db.c Tue Nov  5 12:09:38 2013
@@ -4893,7 +4893,7 @@ handle_move_back(svn_boolean_t *moved_ba
              generally these values should be the same anyway as it was
              a no-op move. */
       SVN_ERR(svn_sqlite__get_statement(&stmt, wcroot->sdb,
-                                        STMT_DELETE_MOVED_BACK));
+                                        STMT_DELETE_WORKING_OP_DEPTH));
 
       SVN_ERR(svn_sqlite__bindf(stmt, "isd", wcroot->wc_id,
                                              local_relpath,

Modified: subversion/trunk/subversion/tests/libsvn_wc/wc-queries-test.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_wc/wc-queries-test.c?rev=1538962&r1=1538961&r2=1538962&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_wc/wc-queries-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_wc/wc-queries-test.c Tue Nov  5 12:09:38 2013
@@ -22,6 +22,7 @@
  */
 
 #include "svn_pools.h"
+#include "svn_hash.h"
 #include "svn_ctype.h"
 #include "private/svn_dep_compat.h"
 
@@ -713,6 +714,105 @@ test_query_expectations(apr_pool_t *scra
   return warnings;
 }
 
+static svn_error_t *
+test_query_duplicates(apr_pool_t *scratch_pool)
+{
+  sqlite3 *sdb;
+  int i;
+  apr_pool_t *iterpool = svn_pool_create(scratch_pool);
+  svn_error_t *warnings = NULL;
+  svn_boolean_t supports_query_info;
+  apr_hash_t *sha_to_query = apr_hash_make(scratch_pool);
+
+  SVN_ERR(create_memory_db(&sdb, scratch_pool));
+
+  SVN_ERR(supported_explain_query_plan(&supports_query_info, sdb,
+      scratch_pool));
+  if (!supports_query_info)
+    {
+      SQLITE_ERR(sqlite3_close(sdb));
+      return svn_error_create(SVN_ERR_TEST_SKIPPED, NULL,
+          "Sqlite doesn't support EXPLAIN QUERY PLAN");
+    }
+
+  for (i = 0; i < STMT_SCHEMA_FIRST; i++)
+    {
+      sqlite3_stmt *stmt;
+      const char *tail;
+      int r;
+      svn_stringbuf_t *result;
+      svn_checksum_t *checksum;
+
+      if (is_schema_statement(i))
+        continue;
+
+      /* Prepare statement to find if it is a single statement. */
+      r = sqlite3_prepare_v2(sdb, wc_queries[i], -1, &stmt, &tail);
+
+      if (r != SQLITE_OK)
+        continue; /* Parse failure is already reported by 'test_parable' */
+
+      SQLITE_ERR(sqlite3_finalize(stmt));
+      if (tail[0] != '\0')
+        continue; /* Multi-queries are currently not testable */
+
+      svn_pool_clear(iterpool);
+
+      r = sqlite3_prepare_v2(sdb,
+                             apr_pstrcat(iterpool,
+                             "EXPLAIN ",
+                             wc_queries[i],
+                             NULL),
+                             -1, &stmt, &tail);
+
+      if (r != SQLITE_OK)
+          continue; /* EXPLAIN not enabled or doesn't support this query */
+
+      result = svn_stringbuf_create_empty(iterpool);
+
+      while (SQLITE_ROW == (r = sqlite3_step(stmt)))
+        {
+          int col;
+
+          for (col = 0; col < sqlite3_column_count(stmt); col++)
+            {
+              const char *txt = (const char*)sqlite3_column_text(stmt, col);
+              if (txt)
+                  svn_stringbuf_appendcstr(result, txt);
+
+              svn_stringbuf_appendcstr(result, "|");
+            }
+
+          svn_stringbuf_appendcstr(result, "\n");
+        }
+
+      SQLITE_ERR(sqlite3_reset(stmt));
+      SQLITE_ERR(sqlite3_finalize(stmt));
+
+      SVN_ERR(svn_checksum(&checksum, svn_checksum_sha1,
+                           result->data, result->len,
+                           iterpool));
+
+      {
+        const char *hex = svn_checksum_to_cstring(checksum, scratch_pool);
+        const char *other;
+
+        other = svn_hash_gets(sha_to_query, hex);
+        if (other)
+          {
+            warnings = svn_error_createf(SVN_ERR_TEST_FAILED, warnings,
+                              "Query %s has an identical execution plan as %s",
+                              wc_query_info[i][0], other);
+          }
+        else
+          svn_hash_sets(sha_to_query, hex, wc_query_info[i][0]);
+      }
+    }
+  SQLITE_ERR(sqlite3_close(sdb)); /* Close the DB if ok; otherwise leaked */
+
+  return warnings;
+}
+
 struct svn_test_descriptor_t test_funcs[] =
   {
     SVN_TEST_NULL,
@@ -722,5 +822,7 @@ struct svn_test_descriptor_t test_funcs[
                    "queries are parsable"),
     SVN_TEST_PASS2(test_query_expectations,
                    "test query expectations"),
+    SVN_TEST_PASS2(test_query_duplicates,
+                   "test query duplicates"),
     SVN_TEST_NULL
   };