/ Check-in [7fafab12]
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:Veryquick now runs to completion without segfaulting or asserting. But there are still lots of errors.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | ticket-71e333e7
Files: files | file ages | folders
SHA1: 7fafab12e4c0c832c421975f8329c3214403d281
User & Date: drh 2012-12-07 14:02:14
Original Comment: Veryquick now row to completion without segfaulting or asserting. But there are still lots of errors.
Context
2012-12-07
18:38
Some errors in veryquick resolved. Many more to go. check-in: 972443b4 user: drh tags: ticket-71e333e7
14:02
Veryquick now runs to completion without segfaulting or asserting. But there are still lots of errors. check-in: 7fafab12 user: drh tags: ticket-71e333e7
2012-12-06
21:16
Remove the Expr.pColl field and compute the collating sequence as it is needed. This fixes the test script "shared9.test", though there is still a memory leak. And there are other problems. Consider this a work-in-progress. check-in: fd011cb2 user: drh tags: ticket-71e333e7
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/expr.c.

   102    102         if( j>=0 ){
   103    103           const char *zColl = p->pTab->aCol[j].zColl;
   104    104           pColl = sqlite3FindCollSeq(db, ENC(db), zColl, 0);
   105    105         }
   106    106         break;
   107    107       }
   108    108       if( p->flags & EP_Collate ){
   109         -      if( p->pLeft->flags & EP_Collate ){
          109  +      if( p->pLeft && (p->pLeft->flags & EP_Collate)!=0 ){
   110    110           p = p->pLeft;
   111    111         }else{
   112    112           p = p->pRight;
   113    113         }
   114    114       }else{
   115    115         break;
   116    116       }
   117         -#if 0
   118         -    else if( p->flags & EP_TokenOnly ){
   119         -      break;
   120         -    }else{
   121         -      pColl = sqlite3ExprCollSeq(pParse, p->pLeft);
   122         -      p = p->pRight;
   123         -    }
   124         -#endif
   125    117     }
   126    118     if( sqlite3CheckCollSeq(pParse, pColl) ){ 
   127    119       pColl = 0;
   128    120     }
   129    121     return pColl;
   130    122   }
   131    123   
................................................................................
  3351   3343         break;
  3352   3344       }
  3353   3345     }
  3354   3346     if( isAppropriateForFactoring(pExpr) ){
  3355   3347       int r1 = ++pParse->nMem;
  3356   3348       int r2;
  3357   3349       r2 = sqlite3ExprCodeTarget(pParse, pExpr, r1);
  3358         -    if( NEVER(r1!=r2) ) sqlite3ReleaseTempReg(pParse, r1);
         3350  +    if( r1!=r2 ) sqlite3ReleaseTempReg(pParse, r1);
  3359   3351       pExpr->op2 = pExpr->op;
  3360   3352       pExpr->op = TK_REGISTER;
  3361   3353       pExpr->iTable = r2;
  3362   3354       return WRC_Prune;
  3363   3355     }
  3364   3356     return WRC_Continue;
  3365   3357   }
................................................................................
  3791   3783       }
  3792   3784     }else if( pA->op!=TK_COLUMN && ALWAYS(pA->op!=TK_AGG_COLUMN) && pA->u.zToken){
  3793   3785       if( ExprHasProperty(pB, EP_IntValue) || NEVER(pB->u.zToken==0) ) return 2;
  3794   3786       if( strcmp(pA->u.zToken,pB->u.zToken)!=0 ){
  3795   3787         return pA->op==TK_COLLATE ? 1 : 2;
  3796   3788       }
  3797   3789     }
         3790  +  if( (pA->flags&EP_Collate)!=(pB->flags&EP_Collate) ) return 1;
  3798   3791     return 0;
  3799   3792   }
  3800   3793   
  3801   3794   /*
  3802   3795   ** Compare two ExprList objects.  Return 0 if they are identical and 
  3803   3796   ** non-zero if they differ in any way.
  3804   3797   **

Changes to src/fkey.c.

   507    507   
   508    508       pLeft = sqlite3Expr(db, TK_REGISTER, 0);
   509    509       if( pLeft ){
   510    510         /* Set the collation sequence and affinity of the LHS of each TK_EQ
   511    511         ** expression to the parent key column defaults.  */
   512    512         if( pIdx ){
   513    513           Column *pCol;
          514  +        Expr *pNew;
          515  +        Token s;
   514    516           iCol = pIdx->aiColumn[i];
   515    517           pCol = &pTab->aCol[iCol];
   516    518           if( pTab->iPKey==iCol ) iCol = -1;
   517    519           pLeft->iTable = regData+iCol+1;
   518    520           pLeft->affinity = pCol->affinity;
   519         -        // fix me.  pLeft->pColl = sqlite3LocateCollSeq(pParse, pCol->zColl);
          521  +        s.z = pCol->zColl;
          522  +        s.n = sqlite3Strlen30(s.z);
          523  +        pNew = sqlite3ExprSetCollByToken(pParse, pLeft, &s);
          524  +        if( pNew ) pLeft = pNew;
   520    525         }else{
   521    526           pLeft->iTable = regData;
   522    527           pLeft->affinity = SQLITE_AFF_INTEGER;
   523    528         }
   524    529       }
   525    530       iCol = aiCol ? aiCol[i] : pFKey->aCol[0].iFrom;
   526    531       assert( iCol>=0 );

Changes to src/resolve.c.

   110    110       pDup = sqlite3ExprDup(db, pOrig, 0);
   111    111       pOrig->u.zToken = zToken;
   112    112       if( pDup==0 ) return;
   113    113       assert( (pDup->flags & (EP_Reduced|EP_TokenOnly))==0 );
   114    114       pDup->flags2 |= EP2_MallocedToken;
   115    115       pDup->u.zToken = sqlite3DbStrDup(db, zToken);
   116    116     }
          117  +  pDup->flags |= EP_Collate & pExpr->flags;
   117    118   
   118    119     /* Before calling sqlite3ExprDelete(), set the EP_Static flag. This 
   119    120     ** prevents ExprDelete() from deleting the Expr structure itself,
   120    121     ** allowing it to be repopulated by the memcpy() on the following line.
   121    122     */
   122    123     ExprSetProperty(pExpr, EP_Static);
   123    124     sqlite3ExprDelete(db, pExpr);

Changes to src/select.c.

  2333   2333         for(i=0; i<nOrderBy; i++){
  2334   2334           CollSeq *pColl;
  2335   2335           Expr *pTerm = pOrderBy->a[i].pExpr;
  2336   2336           if( pTerm->flags & EP_Collate ){
  2337   2337             pColl = sqlite3ExprCollSeq(pParse, pTerm);
  2338   2338           }else{
  2339   2339             pColl = multiSelectCollSeq(pParse, p, aPermute[i]);
         2340  +          pTerm->flags |= EP_Collate;
  2340   2341           }
  2341   2342           pKeyMerge->aColl[i] = pColl;
  2342   2343           pKeyMerge->aSortOrder[i] = pOrderBy->a[i].sortOrder;
  2343   2344         }
  2344   2345       }
  2345   2346     }else{
  2346   2347       pKeyMerge = 0;

Changes to src/where.c.

   661    661     
   662    662             /* Figure out the collation sequence required from an index for
   663    663             ** it to be useful for optimising expression pX. Store this
   664    664             ** value in variable pColl.
   665    665             */
   666    666             assert(pX->pLeft);
   667    667             pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight);
   668         -          assert(pColl || pParse->nErr);
          668  +          if( pColl==0 ) pColl = pParse->db->pDfltColl;
   669    669     
   670    670             for(j=0; pIdx->aiColumn[j]!=iColumn; j++){
   671    671               if( NEVER(j>=pIdx->nColumn) ) return 0;
   672    672             }
   673    673             if( pColl && sqlite3StrICmp(pColl->zName, pIdx->azColl[j]) ) continue;
   674    674           }
   675    675           return pTerm;