Fossil SCM

Avoid large SQL inserts when computing the path between two check-ins for use by reverse annotation.

drh 2017-10-02 16:25 trunk
Commit 5eba557c22ff8e6de5fb95988e004ce77e9b0e886a8a52d0a65fed571f9c97b3
1 file changed +7 -7
+7 -7
--- src/path.c
+++ src/path.c
@@ -203,30 +203,30 @@
203203
void path_shortest_stored_in_ancestor_table(
204204
int origid, /* RID for check-in at start of the path */
205205
int cid /* RID for check-in at the end of the path */
206206
){
207207
PathNode *pPath;
208
- Blob sql;
209208
int gen = 0;
210
- char *zSep = "VALUES";
209
+ Stmt ins;
211210
pPath = path_shortest(cid, origid, 1, 0);
212211
db_multi_exec(
213212
"CREATE TEMP TABLE IF NOT EXISTS ancestor("
214213
" rid INT UNIQUE,"
215214
" generation INTEGER PRIMARY KEY"
216215
");"
217216
"DELETE FROM ancestor;"
218217
);
219
- blob_init(&sql, "INSERT INTO ancestor(rid, generation)", -1);
218
+ db_prepare(&ins, "INSERT INTO ancestor(rid, generation) VALUES(:rid,:gen)");
220219
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);
223224
pPath = pPath->u.pTo;
224225
}
226
+ db_finalize(&ins);
225227
path_reset();
226
- db_multi_exec("%s", blob_sql_text(&sql));
227
- blob_reset(&sql);
228228
}
229229
230230
/*
231231
** COMMAND: test-shortest-path
232232
**
233233
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button