/ Check-in [470ac8d50c]
Login

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

Overview
Comment:The second option for [61c853857f40da49]: In this mode, columns of VIEWs and subqueries that are formed by expressions have affinity BLOB rather than affinity none, as has usually been the case for a while. But this mode fixes a couple of corner cases involving query flattening and the push-down optimization where that rule was violated.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | tkt-61c853-B
Files: files | file ages | folders
SHA3-256: 470ac8d50ce2f7ccad74f5d7b31d90ba1f959691cbc3174d478f49462e7f82b1
User & Date: drh 2019-08-05 19:34:44
Context
2019-08-05
19:34
The second option for [61c853857f40da49]: In this mode, columns of VIEWs and subqueries that are formed by expressions have affinity BLOB rather than affinity none, as has usually been the case for a while. But this mode fixes a couple of corner cases involving query flattening and the push-down optimization where that rule was violated. Closed-Leaf check-in: 470ac8d50c user: drh tags: tkt-61c853-B
18:01
Refactor field Expr.affinity into Expr.affExpr to avoid confusion with other fields and variables named "affinity" and display affExpr it in sqlite3TreeViewExpr() output. check-in: a29f2a7d07 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/resolve.c.

  1739   1739     if( pList ){
  1740   1740       for(i=0; i<pList->nExpr; i++){
  1741   1741         if( sqlite3ResolveExprNames(pNC, pList->a[i].pExpr) ) return WRC_Abort;
  1742   1742       }
  1743   1743     }
  1744   1744     return WRC_Continue;
  1745   1745   }
         1746  +
         1747  +/*
         1748  +** Set the affinity of all expressions in the result set of a subquery
         1749  +** or view.
         1750  +*/
         1751  +void sqlite3ResolveSubqueryAffinity(ExprList *pList){
         1752  +  int i;
         1753  +  if( pList ){
         1754  +    for(i=0; i<pList->nExpr; i++){
         1755  +      Expr *p = pList->a[i].pExpr;
         1756  +      if( p==0 ) continue;
         1757  +      p->affExpr = sqlite3ExprAffinity(p);
         1758  +      if( p->affExpr==0 ) p->affExpr = SQLITE_AFF_BLOB;
         1759  +    }
         1760  +  }
         1761  +}
  1746   1762   
  1747   1763   /*
  1748   1764   ** Resolve all names in all expressions of a SELECT and in all
  1749   1765   ** decendents of the SELECT, including compounds off of p->pPrior,
  1750   1766   ** subqueries in expressions, and subqueries used as FROM clause
  1751   1767   ** terms.
  1752   1768   **

Changes to src/select.c.

  3899   3899       if( db->mallocFailed ) return 1;
  3900   3900     }
  3901   3901   
  3902   3902     /* Begin flattening the iFrom-th entry of the FROM clause 
  3903   3903     ** in the outer query.
  3904   3904     */
  3905   3905     pSub = pSub1 = pSubitem->pSelect;
         3906  +  sqlite3ResolveSubqueryAffinity(pSub->pEList);
  3906   3907   
  3907   3908     /* Delete the transient table structure associated with the
  3908   3909     ** subquery
  3909   3910     */
  3910   3911     sqlite3DbFree(db, pSubitem->zDatabase);
  3911   3912     sqlite3DbFree(db, pSubitem->zName);
  3912   3913     sqlite3DbFree(db, pSubitem->zAlias);
................................................................................
  4363   4364         pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
  4364   4365         unsetJoinExpr(pNew, -1);
  4365   4366         x.pParse = pParse;
  4366   4367         x.iTable = iCursor;
  4367   4368         x.iNewTable = iCursor;
  4368   4369         x.isLeftJoin = 0;
  4369   4370         x.pEList = pSubq->pEList;
         4371  +      sqlite3ResolveSubqueryAffinity(x.pEList);
  4370   4372         pNew = substExpr(&x, pNew);
  4371   4373         if( pSubq->selFlags & SF_Aggregate ){
  4372   4374           pSubq->pHaving = sqlite3ExprAnd(pParse, pSubq->pHaving, pNew);
  4373   4375         }else{
  4374   4376           pSubq->pWhere = sqlite3ExprAnd(pParse, pSubq->pWhere, pNew);
  4375   4377         }
  4376   4378         pSubq = pSubq->pPrior;

Changes to src/sqliteInt.h.

  4335   4335   void sqlite3CodeRhsOfIN(Parse*, Expr*, int);
  4336   4336   int sqlite3CodeSubselect(Parse*, Expr*);
  4337   4337   void sqlite3SelectPrep(Parse*, Select*, NameContext*);
  4338   4338   void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p);
  4339   4339   int sqlite3MatchSpanName(const char*, const char*, const char*, const char*);
  4340   4340   int sqlite3ResolveExprNames(NameContext*, Expr*);
  4341   4341   int sqlite3ResolveExprListNames(NameContext*, ExprList*);
         4342  +void sqlite3ResolveSubqueryAffinity(ExprList*);
  4342   4343   void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*);
  4343   4344   int sqlite3ResolveSelfReference(Parse*,Table*,int,Expr*,ExprList*);
  4344   4345   int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*);
  4345   4346   void sqlite3ColumnDefault(Vdbe *, Table *, int, int);
  4346   4347   void sqlite3AlterFinishAddColumn(Parse *, Token *);
  4347   4348   void sqlite3AlterBeginAddColumn(Parse *, SrcList *);
  4348   4349   void *sqlite3RenameTokenMap(Parse*, void*, Token*);