Author: rhuijben
Date: Wed May 23 01:31:09 2012
New Revision: 1341715
URL: http://svn.apache.org/viewvc?rev=1341715&view=rev
Log:
Split the root node in the target list processing from its children and/or
descendants to avoid a table scan.
Two cheap queries are together much faster than a table scan.
* subversion/libsvn_wc/wc-queries.sql
(STMT_INSERT_TARGET): Reformat.
(STMT_INSERT_TARGET_DEPTH_FILES): Only select files from children.
(STMT_INSERT_TARGET_DEPTH_IMMEDIATES): Only select children.
(STMT_INSERT_TARGET_DEPTH_INFINITY): Only select descendants
(to work the other 7).
(STMT_INSERT_TARGET_WITH_CHANGELIST): Reformat.
(STMT_INSERT_TARGET_WITH_CHANGELIST_DEPTH_FILES):
Only select files from children.
(STMT_INSERT_TARGET_WITH_CHANGELIST_DEPTH_IMMEDIATES): Only select children.
(STMT_INSERT_TARGET_WITH_CHANGELIST_DEPTH_INFINITY): Only select descendants.
* subversion/libsvn_wc/wc_db.c
(populate_targets_tree): Separate the root from the rest query to improve
performance on large working copies by using the index.
* subversion/tests/libsvn_wc/wc-queries-test.c
(slow_statements): Remove 6 more previously slow queries.
Modified:
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/wc-queries.sql
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/wc-queries.sql?rev=1341715&r1=1341714&r2=1341715&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/wc-queries.sql (original)
+++ subversion/trunk/subversion/libsvn_wc/wc-queries.sql Wed May 23 01:31:09
2012
@@ -479,51 +479,59 @@ DROP TABLE IF EXISTS targets_list
-- STMT_INSERT_TARGET
INSERT INTO targets_list(wc_id, local_relpath, parent_relpath, kind)
SELECT wc_id, local_relpath, parent_relpath, kind
-FROM nodes_current WHERE wc_id = ?1 AND local_relpath = ?2
+FROM nodes_current
+WHERE wc_id = ?1
+ AND local_relpath = ?2
-- STMT_INSERT_TARGET_DEPTH_FILES
INSERT INTO targets_list(wc_id, local_relpath, parent_relpath, kind)
SELECT wc_id, local_relpath, parent_relpath, kind
FROM nodes_current
-WHERE wc_id = ?1 AND ((parent_relpath = ?2 AND kind = 'file')
- OR local_relpath = ?2)
+WHERE wc_id = ?1
+ AND parent_relpath = ?2
+ AND kind = 'file'
-- STMT_INSERT_TARGET_DEPTH_IMMEDIATES
INSERT INTO targets_list(wc_id, local_relpath, parent_relpath, kind)
SELECT wc_id, local_relpath, parent_relpath, kind
FROM nodes_current
-WHERE wc_id = ?1 AND (parent_relpath = ?2 OR local_relpath = ?2)
+WHERE wc_id = ?1
+ AND parent_relpath = ?2
-- STMT_INSERT_TARGET_DEPTH_INFINITY
INSERT INTO targets_list(wc_id, local_relpath, parent_relpath, kind)
SELECT wc_id, local_relpath, parent_relpath, kind
FROM nodes_current
WHERE wc_id = ?1
- AND (local_relpath = ?2
- OR IS_STRICT_DESCENDANT_OF(local_relpath, ?2))
+ AND IS_STRICT_DESCENDANT_OF(local_relpath, ?2)
-- STMT_INSERT_TARGET_WITH_CHANGELIST
INSERT INTO targets_list(wc_id, local_relpath, parent_relpath, kind)
SELECT N.wc_id, N.local_relpath, N.parent_relpath, N.kind
FROM actual_node AS A JOIN nodes_current AS N
ON A.wc_id = N.wc_id AND A.local_relpath = N.local_relpath
- WHERE N.wc_id = ?1 AND A.changelist = ?3 AND N.local_relpath = ?2
+ WHERE N.wc_id = ?1
+ AND N.local_relpath = ?2
+ AND A.changelist = ?3
-- STMT_INSERT_TARGET_WITH_CHANGELIST_DEPTH_FILES
INSERT INTO targets_list(wc_id, local_relpath, parent_relpath, kind)
SELECT N.wc_id, N.local_relpath, N.parent_relpath, N.kind
FROM actual_node AS A JOIN nodes_current AS N
ON A.wc_id = N.wc_id AND A.local_relpath = N.local_relpath
- WHERE N.wc_id = ?1 AND A.changelist = ?3
- AND ((N.parent_relpath = ?2 AND kind = 'file') OR N.local_relpath = ?2)
+ WHERE N.wc_id = ?1
+ AND N.parent_relpath = ?2
+ AND kind = 'file'
+ AND A.changelist = ?3
-- STMT_INSERT_TARGET_WITH_CHANGELIST_DEPTH_IMMEDIATES
INSERT INTO targets_list(wc_id, local_relpath, parent_relpath, kind)
SELECT N.wc_id, N.local_relpath, N.parent_relpath, N.kind
FROM actual_node AS A JOIN nodes_current AS N
ON A.wc_id = N.wc_id AND A.local_relpath = N.local_relpath
- WHERE N.wc_id = ?1 AND A.changelist = ?3
- AND (N.parent_relpath = ?2 OR N.local_relpath = ?2)
+ WHERE N.wc_id = ?1
+ AND N.parent_relpath = ?2
+ AND A.changelist = ?3
-- STMT_INSERT_TARGET_WITH_CHANGELIST_DEPTH_INFINITY
INSERT INTO targets_list(wc_id, local_relpath, parent_relpath, kind)
@@ -531,9 +539,8 @@ SELECT N.wc_id, N.local_relpath, N.paren
FROM actual_node AS A JOIN nodes_current AS N
ON A.wc_id = N.wc_id AND A.local_relpath = N.local_relpath
WHERE N.wc_id = ?1
- AND (N.local_relpath = ?2
- OR IS_STRICT_DESCENDANT_OF(N.local_relpath, ?2))
- AND A.changelist = ?3
+ AND IS_STRICT_DESCENDANT_OF(N.local_relpath, ?2)
+ AND A.changelist = ?3
-- STMT_SELECT_TARGETS
SELECT local_relpath, parent_relpath from targets_list
Modified: subversion/trunk/subversion/libsvn_wc/wc_db.c
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/wc_db.c?rev=1341715&r1=1341714&r2=1341715&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/wc_db.c (original)
+++ subversion/trunk/subversion/libsvn_wc/wc_db.c Wed May 23 01:31:09 2012
@@ -4947,17 +4947,29 @@ populate_targets_tree(svn_wc__db_wcroot_
const char *changelist = APR_ARRAY_IDX(changelist_filter, i,
const char *);
- SVN_ERR(svn_sqlite__get_statement(&stmt, wcroot->sdb, stmt_idx));
+ SVN_ERR(svn_sqlite__get_statement(&stmt, wcroot->sdb,
+ STMT_INSERT_TARGET_WITH_CHANGELIST));
SVN_ERR(svn_sqlite__bindf(stmt, "iss", wcroot->wc_id,
local_relpath, changelist));
SVN_ERR(svn_sqlite__update(&sub_affected, stmt));
+ /* If the root is matched by the changelist, we don't have to match
+ the children. As that tells us the root is a file */
+ if (!sub_affected && depth > svn_depth_empty)
+ {
+ SVN_ERR(svn_sqlite__get_statement(&stmt, wcroot->sdb, stmt_idx));
+ SVN_ERR(svn_sqlite__bindf(stmt, "iss", wcroot->wc_id,
+ local_relpath, changelist));
+ SVN_ERR(svn_sqlite__update(&sub_affected, stmt));
+ }
+
affected_rows += sub_affected;
}
}
else /* No changelist filtering */
{
int stmt_idx;
+ int sub_affected;
switch (depth)
{
@@ -4983,9 +4995,19 @@ populate_targets_tree(svn_wc__db_wcroot_
break;
}
- SVN_ERR(svn_sqlite__get_statement(&stmt, wcroot->sdb, stmt_idx));
+ SVN_ERR(svn_sqlite__get_statement(&stmt, wcroot->sdb,
+ STMT_INSERT_TARGET));
SVN_ERR(svn_sqlite__bindf(stmt, "is", wcroot->wc_id, local_relpath));
- SVN_ERR(svn_sqlite__update(&affected_rows, stmt));
+ SVN_ERR(svn_sqlite__update(&sub_affected, stmt));
+ affected_rows += sub_affected;
+
+ if (depth > svn_depth_empty)
+ {
+ SVN_ERR(svn_sqlite__get_statement(&stmt, wcroot->sdb, stmt_idx));
+ SVN_ERR(svn_sqlite__bindf(stmt, "is", wcroot->wc_id, local_relpath));
+ SVN_ERR(svn_sqlite__update(&sub_affected, stmt));
+ affected_rows += sub_affected;
+ }
}
/* Does the target exist? */
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=1341715&r1=1341714&r2=1341715&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_wc/wc-queries-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_wc/wc-queries-test.c Wed May 23
01:31:09 2012
@@ -92,12 +92,6 @@ static const int slow_statements[] =
STMT_SELECT_CHANGELIST_LIST,
/* Need review: */
- STMT_INSERT_TARGET_DEPTH_FILES,
- STMT_INSERT_TARGET_DEPTH_IMMEDIATES,
- STMT_INSERT_TARGET_DEPTH_INFINITY,
- STMT_INSERT_TARGET_WITH_CHANGELIST_DEPTH_FILES,
- STMT_INSERT_TARGET_WITH_CHANGELIST_DEPTH_IMMEDIATES,
- STMT_INSERT_TARGET_WITH_CHANGELIST_DEPTH_INFINITY,
STMT_SELECT_COMMITTABLE_EXTERNALS_BELOW,
STMT_SELECT_EXTERNALS_DEFINED,
STMT_SELECT_EXTERNAL_PROPERTIES,