Tie up the loose ends in the ExprList size reduction.

FossilOrigin-Name: 59d0f3afe5249a2a6453fe7bc810c2c7beb896d3800174c7c90f9304c0b1ad88
diff --git a/src/alter.c b/src/alter.c
index f3467fa..3bc779a 100644
--- a/src/alter.c
+++ b/src/alter.c
@@ -764,7 +764,7 @@
   if( ALWAYS(p->pEList) ){
     ExprList *pList = p->pEList;
     for(i=0; i<pList->nExpr; i++){
-      if( pList->a[i].zEName ){
+      if( pList->a[i].zEName && pList->a[i].eEName==ENAME_NAME ){
         sqlite3RenameTokenRemap(pParse, 0, (void*)pList->a[i].zEName);
       }
     }
@@ -808,7 +808,9 @@
     sWalker.xExprCallback = renameUnmapExprCb;
     sqlite3WalkExprList(&sWalker, pEList);
     for(i=0; i<pEList->nExpr; i++){
-      sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zEName);
+      if( pEList->a[i].eEName==ENAME_NAME ){
+        sqlite3RenameTokenRemap(pParse, 0, (void*)pEList->a[i].zEName);
+      }
     }
   }
 }
@@ -947,7 +949,9 @@
     int i;
     for(i=0; i<pEList->nExpr; i++){
       char *zName = pEList->a[i].zEName;
-      if( 0==sqlite3_stricmp(zName, zOld) ){
+      if( pEList->a[i].eEName==ENAME_NAME
+       && 0==sqlite3_stricmp(zName, zOld)
+      ){
         renameTokenFind(pParse, pCtx, (void*)zName);
       }
     }
diff --git a/src/expr.c b/src/expr.c
index 0ca1d04..150e34a 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -1745,6 +1745,7 @@
     assert( pList->nExpr>0 );
     pItem = &pList->a[pList->nExpr-1];
     assert( pItem->zEName==0 );
+    assert( pItem->eEName==ENAME_NAME );
     pItem->zEName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
     if( dequote ) sqlite3Dequote(pItem->zEName);
     if( IN_RENAME_OBJECT ){
diff --git a/src/resolve.c b/src/resolve.c
index cce9210..572e0a9 100644
--- a/src/resolve.c
+++ b/src/resolve.c
@@ -132,13 +132,16 @@
 ** and zCol.  If any of zDb, zTab, and zCol are NULL then those fields will
 ** match anything.
 */
-int sqlite3MatchSpanName(
-  const char *zSpan,
+int sqlite3MatchEName(
+  const struct ExprList_item *pItem,
   const char *zCol,
   const char *zTab,
   const char *zDb
 ){
   int n;
+  const char *zSpan;
+  if( pItem->eEName!=ENAME_TAB ) return 0;
+  zSpan = pItem->zEName;
   for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
   if( zDb && (sqlite3StrNICmp(zSpan, zDb, n)!=0 || zDb[n]!=0) ){
     return 0;
@@ -267,7 +270,7 @@
           int hit = 0;
           pEList = pItem->pSelect->pEList;
           for(j=0; j<pEList->nExpr; j++){
-            if( sqlite3MatchSpanName(pEList->a[j].zEName, zCol, zTab, zDb) ){
+            if( sqlite3MatchEName(&pEList->a[j], zCol, zTab, zDb) ){
               cnt++;
               cntTab = 2;
               pMatch = pItem;
@@ -448,8 +451,11 @@
       pEList = pNC->uNC.pEList;
       assert( pEList!=0 );
       for(j=0; j<pEList->nExpr; j++){
-        char *zAs = pEList->a[j].zEName;
-        if( zAs!=0 && sqlite3StrICmp(zAs, zCol)==0 ){
+        char *zAs;
+        if( pEList->a[j].eEName==ENAME_NAME
+         && (zAs = pEList->a[j].zEName)!=0
+         && sqlite3StrICmp(zAs, zCol)==0
+        ){
           Expr *pOrig;
           assert( pExpr->pLeft==0 && pExpr->pRight==0 );
           assert( pExpr->x.pList==0 );
@@ -1116,7 +1122,10 @@
     char *zCol = pE->u.zToken;
     for(i=0; i<pEList->nExpr; i++){
       char *zAs = pEList->a[i].zEName;
-      if( zAs!=0 && sqlite3StrICmp(zAs, zCol)==0 ){
+      if( pEList->a[i].eEName==ENAME_NAME
+       && (zAs = pEList->a[i].zEName)!=0
+       && sqlite3StrICmp(zAs, zCol)==0
+      ){
         return i+1;
       }
     }
diff --git a/src/select.c b/src/select.c
index 57bf685..11c25e7 100644
--- a/src/select.c
+++ b/src/select.c
@@ -5044,7 +5044,7 @@
 
             assert( zName );
             if( zTName && pSub
-             && sqlite3MatchSpanName(pSub->pEList->a[j].zEName, 0, zTName, 0)==0
+             && sqlite3MatchEName(&pSub->pEList->a[j], 0, zTName, 0)==0
             ){
               continue;
             }
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index 7425b29..d022436 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -2653,16 +2653,16 @@
 ** In order to try to keep memory usage down, the Expr.a.zEName field
 ** is used for multiple purposes:
 **
-**     bNameIsTab    bNameIsSpan        Usage
-**     ----------    -----------        -------------------------
-**       false          false           (1) the AS of result set column
-**                                      (2) COLUMN= of an UPDATE
+**     eEName          Usage
+**    ----------       -------------------------
+**    ENAME_NAME       (1) the AS of result set column
+**                     (2) COLUMN= of an UPDATE
 **
-**       true           false           DB.TABLE.NAME used to resolve names
-**                                      of subqueries
+**    ENAME_TAB        DB.TABLE.NAME used to resolve names
+**                     of subqueries
 **
-**       false          true            Text of the original result set
-**                                      expression.
+**    ENAME_SPAN       Text of the original result set
+**                     expression.
 */
 struct ExprList {
   int nExpr;             /* Number of expressions on the list */
@@ -4430,7 +4430,12 @@
 int sqlite3CodeSubselect(Parse*, Expr*);
 void sqlite3SelectPrep(Parse*, Select*, NameContext*);
 void sqlite3SelectWrongNumTermsError(Parse *pParse, Select *p);
-int sqlite3MatchSpanName(const char*, const char*, const char*, const char*);
+int sqlite3MatchEName(
+  const struct ExprList_item*,
+  const char*,
+  const char*,
+  const char*
+);
 int sqlite3ResolveExprNames(NameContext*, Expr*);
 int sqlite3ResolveExprListNames(NameContext*, ExprList*);
 void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*);