Fossil

Changes On Branch start-of-branch-cte
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch start-of-branch-cte Excluding Merge-Ins

This is equivalent to a diff from ad744440 to 5e34c998

2022-03-08
13:08
Faster implementation of start_of_branch() using a CTE. ... (check-in: 8736de8b user: drh tags: trunk)
12:04
Fix the case eType==1 (find the first check-in of the branch). ... (Closed-Leaf check-in: 5e34c998 user: danield tags: start-of-branch-cte)
2022-03-07
19:01
Update to the latest SQLite 3.39.0 alpha with its performance enhancements and bug fixes. ... (check-in: 14da62ee user: drh tags: trunk)
2022-03-04
17:56
Add braces around an if-block. ... (check-in: 9cd92711 user: danield tags: start-of-branch-cte)
2022-03-03
23:19
Use a CTE instead of querying the database in a loop when finding the start of a branch. This can bring significant speedup on some machines. ... (check-in: c7749bb0 user: danield tags: start-of-branch-cte)
2022-03-02
02:00
Update the built-in SQLite to the latest trunk version that includes various performance enhancements. The purpose here is to test the recent SQLite enhancements in a real-world application. ... (check-in: ad744440 user: drh tags: trunk)
2022-03-01
21:02
Ensure that db_open()'s db-is-an-appendvfs-binary check uses canonicalized filenames to avoid the problem reported in forum post 16880a28aad1a868. ... (check-in: ab7ad234 user: stephan tags: trunk)

Changes to src/name.c.

155
156
157
158
159
160
161


162
163
164






165
166



167
168
169
170
171
172
173
174
175
176
177

178
179
180
181
182
183
184
*/
int start_of_branch(int rid, int eType){
  Stmt q;
  int rc;
  int ans = rid;
  char *zBr = branch_of_rid(rid);
  db_prepare(&q,


    "SELECT pid, EXISTS(SELECT 1 FROM tagxref"
                       " WHERE tagid=%d AND tagtype>0"
                       "   AND value=%Q AND rid=plink.pid)"






    "  FROM plink"
    " WHERE cid=:cid AND isprim",



    TAG_BRANCH, zBr
  );
  fossil_free(zBr);
  do{
    db_reset(&q);
    db_bind_int(&q, ":cid", ans);
    rc = db_step(&q);
    if( rc!=SQLITE_ROW ) break;
    if( eType==1 && db_column_int(&q,1)==0 ) break;
    ans = db_column_int(&q, 0);
  }while( db_column_int(&q, 1)==1 && ans>0 );

  db_finalize(&q);
  if( eType==2 && ans>0 ){
    zBr = branch_of_rid(ans);
    ans = compute_youngest_ancestor_in_branch(rid, zBr);
    fossil_free(zBr);
  }
  return ans;







>
>
|
|
|
>
>
>
>
>
>
|
|
>
>
>
|


<
<
<
|
|
<

<
>







155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180



181
182

183

184
185
186
187
188
189
190
191
*/
int start_of_branch(int rid, int eType){
  Stmt q;
  int rc;
  int ans = rid;
  char *zBr = branch_of_rid(rid);
  db_prepare(&q,
    "WITH RECURSIVE"
    "  par(pid, ex, cnt) as ("
    "    SELECT pid, EXISTS(SELECT 1 FROM tagxref"
    "                        WHERE tagid=%d AND tagtype>0"
    "                          AND value=%Q AND rid=plink.pid), 1"
    "    FROM plink WHERE cid=%d AND isprim"
    "    UNION ALL "
    "    SELECT plink.pid, EXISTS(SELECT 1 FROM tagxref "
    "                              WHERE tagid=%d AND tagtype>0" 
    "                                AND value=%Q AND rid=plink.pid),"
    "           1+par.cnt"
    "      FROM plink, par"
    "     WHERE cid=par.pid AND isprim AND par.ex "
    "     LIMIT 100000 "
    "  )"
    " SELECT pid FROM par WHERE ex>=%d ORDER BY cnt DESC LIMIT 1",
    TAG_BRANCH, zBr, ans, TAG_BRANCH, zBr, eType%2
  );
  fossil_free(zBr);



  rc = db_step(&q);
  if( rc==SQLITE_ROW ){ 

    ans = db_column_int(&q, 0);

  }
  db_finalize(&q);
  if( eType==2 && ans>0 ){
    zBr = branch_of_rid(ans);
    ans = compute_youngest_ancestor_in_branch(rid, zBr);
    fossil_free(zBr);
  }
  return ans;