Fossil SCM
Avoid large SQL inserts when computing the path between two check-ins for use by reverse annotation.
Commit
5eba557c22ff8e6de5fb95988e004ce77e9b0e886a8a52d0a65fed571f9c97b3
Parent
e9845e590456d23…
1 file changed
+7
-7
+7
-7
| --- src/path.c | ||
| +++ src/path.c | ||
| @@ -203,30 +203,30 @@ | ||
| 203 | 203 | void path_shortest_stored_in_ancestor_table( |
| 204 | 204 | int origid, /* RID for check-in at start of the path */ |
| 205 | 205 | int cid /* RID for check-in at the end of the path */ |
| 206 | 206 | ){ |
| 207 | 207 | PathNode *pPath; |
| 208 | - Blob sql; | |
| 209 | 208 | int gen = 0; |
| 210 | - char *zSep = "VALUES"; | |
| 209 | + Stmt ins; | |
| 211 | 210 | pPath = path_shortest(cid, origid, 1, 0); |
| 212 | 211 | db_multi_exec( |
| 213 | 212 | "CREATE TEMP TABLE IF NOT EXISTS ancestor(" |
| 214 | 213 | " rid INT UNIQUE," |
| 215 | 214 | " generation INTEGER PRIMARY KEY" |
| 216 | 215 | ");" |
| 217 | 216 | "DELETE FROM ancestor;" |
| 218 | 217 | ); |
| 219 | - blob_init(&sql, "INSERT INTO ancestor(rid, generation)", -1); | |
| 218 | + db_prepare(&ins, "INSERT INTO ancestor(rid, generation) VALUES(:rid,:gen)"); | |
| 220 | 219 | while( pPath ){ |
| 221 | - blob_append_sql(&sql, "%s(%d,%d)", zSep/*safe-for-%s*/, pPath->rid,++gen); | |
| 222 | - zSep = ","; | |
| 220 | + db_bind_int(&ins, ":rid", pPath->rid); | |
| 221 | + db_bind_int(&ins, ":gen", ++gen); | |
| 222 | + db_step(&ins); | |
| 223 | + db_reset(&ins); | |
| 223 | 224 | pPath = pPath->u.pTo; |
| 224 | 225 | } |
| 226 | + db_finalize(&ins); | |
| 225 | 227 | path_reset(); |
| 226 | - db_multi_exec("%s", blob_sql_text(&sql)); | |
| 227 | - blob_reset(&sql); | |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /* |
| 231 | 231 | ** COMMAND: test-shortest-path |
| 232 | 232 | ** |
| 233 | 233 |
| --- src/path.c | |
| +++ src/path.c | |
| @@ -203,30 +203,30 @@ | |
| 203 | void path_shortest_stored_in_ancestor_table( |
| 204 | int origid, /* RID for check-in at start of the path */ |
| 205 | int cid /* RID for check-in at the end of the path */ |
| 206 | ){ |
| 207 | PathNode *pPath; |
| 208 | Blob sql; |
| 209 | int gen = 0; |
| 210 | char *zSep = "VALUES"; |
| 211 | pPath = path_shortest(cid, origid, 1, 0); |
| 212 | db_multi_exec( |
| 213 | "CREATE TEMP TABLE IF NOT EXISTS ancestor(" |
| 214 | " rid INT UNIQUE," |
| 215 | " generation INTEGER PRIMARY KEY" |
| 216 | ");" |
| 217 | "DELETE FROM ancestor;" |
| 218 | ); |
| 219 | blob_init(&sql, "INSERT INTO ancestor(rid, generation)", -1); |
| 220 | while( pPath ){ |
| 221 | blob_append_sql(&sql, "%s(%d,%d)", zSep/*safe-for-%s*/, pPath->rid,++gen); |
| 222 | zSep = ","; |
| 223 | pPath = pPath->u.pTo; |
| 224 | } |
| 225 | path_reset(); |
| 226 | db_multi_exec("%s", blob_sql_text(&sql)); |
| 227 | blob_reset(&sql); |
| 228 | } |
| 229 | |
| 230 | /* |
| 231 | ** COMMAND: test-shortest-path |
| 232 | ** |
| 233 |
| --- src/path.c | |
| +++ src/path.c | |
| @@ -203,30 +203,30 @@ | |
| 203 | void path_shortest_stored_in_ancestor_table( |
| 204 | int origid, /* RID for check-in at start of the path */ |
| 205 | int cid /* RID for check-in at the end of the path */ |
| 206 | ){ |
| 207 | PathNode *pPath; |
| 208 | int gen = 0; |
| 209 | Stmt ins; |
| 210 | pPath = path_shortest(cid, origid, 1, 0); |
| 211 | db_multi_exec( |
| 212 | "CREATE TEMP TABLE IF NOT EXISTS ancestor(" |
| 213 | " rid INT UNIQUE," |
| 214 | " generation INTEGER PRIMARY KEY" |
| 215 | ");" |
| 216 | "DELETE FROM ancestor;" |
| 217 | ); |
| 218 | db_prepare(&ins, "INSERT INTO ancestor(rid, generation) VALUES(:rid,:gen)"); |
| 219 | while( pPath ){ |
| 220 | db_bind_int(&ins, ":rid", pPath->rid); |
| 221 | db_bind_int(&ins, ":gen", ++gen); |
| 222 | db_step(&ins); |
| 223 | db_reset(&ins); |
| 224 | pPath = pPath->u.pTo; |
| 225 | } |
| 226 | db_finalize(&ins); |
| 227 | path_reset(); |
| 228 | } |
| 229 | |
| 230 | /* |
| 231 | ** COMMAND: test-shortest-path |
| 232 | ** |
| 233 |