/ Check-in [a2c443c0]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Minor changes to the input grammar resulting in a faster and slightly smaller parser.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a2c443c0ee9a0e0b2d10298b8a74ff00a1a66e3f96f4093348f0fef977587204
User & Date: drh 2018-04-09 20:36:09
Context
2018-04-10
00:53
Update the top-level README.md file to point to the whynotgit.html document. Put it on the correct branch, this time. check-in: a52e3cdd user: drh tags: trunk
2018-04-09
20:36
Minor changes to the input grammar resulting in a faster and slightly smaller parser. check-in: a2c443c0 user: drh tags: trunk
15:57
Enhance the query planner so that it detects when the xBestIndex method of a virtual table gives out-of-sequence argvIndex values and reports an error. Secondary fix for ticket [2b8aed9f7c9e6]. check-in: 9506ec14 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/parse.y.

   460    460         ){
   461    461           sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
   462    462         }
   463    463       }
   464    464     }
   465    465   }
   466    466   
   467         -select(A) ::= with(W) selectnowith(X). {
          467  +select(A) ::= WITH wqlist(W) selectnowith(X). {
          468  +  Select *p = X;
          469  +  if( p ){
          470  +    p->pWith = W;
          471  +    parserDoubleLinkSelect(pParse, p);
          472  +  }else{
          473  +    sqlite3WithDelete(pParse->db, W);
          474  +  }
          475  +  A = p;
          476  +}
          477  +select(A) ::= WITH RECURSIVE wqlist(W) selectnowith(X). {
   468    478     Select *p = X;
   469    479     if( p ){
   470    480       p->pWith = W;
   471    481       parserDoubleLinkSelect(pParse, p);
   472    482     }else{
   473    483       sqlite3WithDelete(pParse->db, W);
   474    484     }
   475         -  A = p; /*A-overwrites-W*/
          485  +  A = p;
          486  +}
          487  +select(A) ::= selectnowith(X). {
          488  +  Select *p = X;
          489  +  if( p ){
          490  +    parserDoubleLinkSelect(pParse, p);
          491  +  }
          492  +  A = p; /*A-overwrites-X*/
   476    493   }
   477    494   
   478    495   selectnowith(A) ::= oneselect(A).
   479    496   %ifndef SQLITE_OMIT_COMPOUND_SELECT
   480    497   selectnowith(A) ::= selectnowith(A) multiselect_op(Y) oneselect(Z).  {
   481    498     Select *pRhs = Z;
   482    499     Select *pLhs = A;
................................................................................
   662    679   
   663    680   %type dbnm {Token}
   664    681   dbnm(A) ::= .          {A.z=0; A.n=0;}
   665    682   dbnm(A) ::= DOT nm(X). {A = X;}
   666    683   
   667    684   %type fullname {SrcList*}
   668    685   %destructor fullname {sqlite3SrcListDelete(pParse->db, $$);}
   669         -fullname(A) ::= nm(X) dbnm(Y).  
          686  +fullname(A) ::= nm(X).  
          687  +   {A = sqlite3SrcListAppend(pParse->db,0,&X,0); /*A-overwrites-X*/}
          688  +fullname(A) ::= nm(X) DOT nm(Y).  
   670    689      {A = sqlite3SrcListAppend(pParse->db,0,&X,&Y); /*A-overwrites-X*/}
   671    690   
   672    691   %type joinop {int}
   673    692   joinop(X) ::= COMMA|JOIN.              { X = JT_INNER; }
   674    693   joinop(X) ::= JOIN_KW(A) JOIN.
   675    694                     {X = sqlite3JoinType(pParse,&A,0,0);  /*X-overwrites-A*/}
   676    695   joinop(X) ::= JOIN_KW(A) nm(B) JOIN.
................................................................................
   758    777                            {A = sqlite3PExpr(pParse,TK_LIMIT,X,Y);}
   759    778   limit_opt(A) ::= LIMIT expr(X) COMMA expr(Y). 
   760    779                            {A = sqlite3PExpr(pParse,TK_LIMIT,Y,X);}
   761    780   
   762    781   /////////////////////////// The DELETE statement /////////////////////////////
   763    782   //
   764    783   %ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
   765         -cmd ::= with(C) DELETE FROM fullname(X) indexed_opt(I) where_opt(W) 
          784  +cmd ::= with DELETE FROM fullname(X) indexed_opt(I) where_opt(W) 
   766    785           orderby_opt(O) limit_opt(L). {
   767         -  sqlite3WithPush(pParse, C, 1);
   768    786     sqlite3SrcListIndexedBy(pParse, X, &I);
   769    787     sqlite3DeleteFrom(pParse,X,W,O,L);
   770    788   }
   771    789   %endif
   772    790   %ifndef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
   773         -cmd ::= with(C) DELETE FROM fullname(X) indexed_opt(I) where_opt(W). {
   774         -  sqlite3WithPush(pParse, C, 1);
          791  +cmd ::= with DELETE FROM fullname(X) indexed_opt(I) where_opt(W). {
   775    792     sqlite3SrcListIndexedBy(pParse, X, &I);
   776    793     sqlite3DeleteFrom(pParse,X,W,0,0);
   777    794   }
   778    795   %endif
   779    796   
   780    797   %type where_opt {Expr*}
   781    798   %destructor where_opt {sqlite3ExprDelete(pParse->db, $$);}
................................................................................
   782    799   
   783    800   where_opt(A) ::= .                    {A = 0;}
   784    801   where_opt(A) ::= WHERE expr(X).       {A = X;}
   785    802   
   786    803   ////////////////////////// The UPDATE command ////////////////////////////////
   787    804   //
   788    805   %ifdef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
   789         -cmd ::= with(C) UPDATE orconf(R) fullname(X) indexed_opt(I) SET setlist(Y)
          806  +cmd ::= with UPDATE orconf(R) fullname(X) indexed_opt(I) SET setlist(Y)
   790    807           where_opt(W) orderby_opt(O) limit_opt(L).  {
   791         -  sqlite3WithPush(pParse, C, 1);
   792    808     sqlite3SrcListIndexedBy(pParse, X, &I);
   793    809     sqlite3ExprListCheckLength(pParse,Y,"set list"); 
   794    810     sqlite3Update(pParse,X,Y,W,R,O,L);
   795    811   }
   796    812   %endif
   797    813   %ifndef SQLITE_ENABLE_UPDATE_DELETE_LIMIT
   798         -cmd ::= with(C) UPDATE orconf(R) fullname(X) indexed_opt(I) SET setlist(Y)
          814  +cmd ::= with UPDATE orconf(R) fullname(X) indexed_opt(I) SET setlist(Y)
   799    815           where_opt(W).  {
   800         -  sqlite3WithPush(pParse, C, 1);
   801    816     sqlite3SrcListIndexedBy(pParse, X, &I);
   802    817     sqlite3ExprListCheckLength(pParse,Y,"set list"); 
   803    818     sqlite3Update(pParse,X,Y,W,R,0,0);
   804    819   }
   805    820   %endif
   806    821   
   807    822   %type setlist {ExprList*}
................................................................................
   820    835   }
   821    836   setlist(A) ::= LP idlist(X) RP EQ expr(Y). {
   822    837     A = sqlite3ExprListAppendVector(pParse, 0, X, Y);
   823    838   }
   824    839   
   825    840   ////////////////////////// The INSERT command /////////////////////////////////
   826    841   //
   827         -cmd ::= with(W) insert_cmd(R) INTO fullname(X) idlist_opt(F) select(S). {
   828         -  sqlite3WithPush(pParse, W, 1);
          842  +cmd ::= with insert_cmd(R) INTO fullname(X) idlist_opt(F) select(S). {
   829    843     sqlite3Insert(pParse, X, S, F, R);
   830    844   }
   831         -cmd ::= with(W) insert_cmd(R) INTO fullname(X) idlist_opt(F) DEFAULT VALUES.
          845  +cmd ::= with insert_cmd(R) INTO fullname(X) idlist_opt(F) DEFAULT VALUES.
   832    846   {
   833         -  sqlite3WithPush(pParse, W, 1);
   834    847     sqlite3Insert(pParse, X, 0, F, R);
   835    848   }
   836    849   
   837    850   %type insert_cmd {int}
   838    851   insert_cmd(A) ::= INSERT orconf(R).   {A = R;}
   839    852   insert_cmd(A) ::= REPLACE.            {A = OE_Replace;}
   840    853   
................................................................................
  1484   1497   anylist ::= .
  1485   1498   anylist ::= anylist LP anylist RP.
  1486   1499   anylist ::= anylist ANY.
  1487   1500   %endif  SQLITE_OMIT_VIRTUALTABLE
  1488   1501   
  1489   1502   
  1490   1503   //////////////////////// COMMON TABLE EXPRESSIONS ////////////////////////////
  1491         -%type with {With*}
  1492   1504   %type wqlist {With*}
  1493         -%destructor with {sqlite3WithDelete(pParse->db, $$);}
  1494   1505   %destructor wqlist {sqlite3WithDelete(pParse->db, $$);}
  1495   1506   
  1496         -with(A) ::= . {A = 0;}
         1507  +with ::= .
  1497   1508   %ifndef SQLITE_OMIT_CTE
  1498         -with(A) ::= WITH wqlist(W).              { A = W; }
  1499         -with(A) ::= WITH RECURSIVE wqlist(W).    { A = W; }
         1509  +with ::= WITH wqlist(W).              { sqlite3WithPush(pParse, W, 1); }
         1510  +with ::= WITH RECURSIVE wqlist(W).    { sqlite3WithPush(pParse, W, 1); }
  1500   1511   
  1501   1512   wqlist(A) ::= nm(X) eidlist_opt(Y) AS LP select(Z) RP. {
  1502   1513     A = sqlite3WithAdd(pParse, 0, &X, Y, Z); /*A-overwrites-X*/
  1503   1514   }
  1504   1515   wqlist(A) ::= wqlist(A) COMMA nm(X) eidlist_opt(Y) AS LP select(Z) RP. {
  1505   1516     A = sqlite3WithAdd(pParse, A, &X, Y, Z);
  1506   1517   }
  1507   1518   %endif  SQLITE_OMIT_CTE

Changes to src/select.c.

  4374   4374     }
  4375   4375     assert( p->pSrc!=0 );
  4376   4376     if( (selFlags & SF_Expanded)!=0 ){
  4377   4377       return WRC_Prune;
  4378   4378     }
  4379   4379     pTabList = p->pSrc;
  4380   4380     pEList = p->pEList;
  4381         -  if( OK_IF_ALWAYS_TRUE(p->pWith) ){
  4382         -    sqlite3WithPush(pParse, p->pWith, 0);
  4383         -  }
         4381  +  sqlite3WithPush(pParse, p->pWith, 0);
  4384   4382   
  4385   4383     /* Make sure cursor numbers have been assigned to all entries in
  4386   4384     ** the FROM clause of the SELECT statement.
  4387   4385     */
  4388   4386     sqlite3SrcListAssignCursors(pParse, pTabList);
  4389   4387   
  4390   4388     /* Look up every table named in the FROM clause of the select.  If