/ Check-in [a7674ead]
Login

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

Overview
Comment:Modify the sqlite3SelectDup() routine to avoid recursing on Select.pPrior.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | recursive-selectdup
Files: files | file ages | folders
SHA1: a7674ead5be986c66f7d61d598adc7e5728bcd30
User & Date: dan 2017-02-03 14:44:52
Context
2017-02-03
19:16
Avoid a performance problem when very large "VALUES(..), (..), (..)" terms are used in queries. Closed-Leaf check-in: f5306ad6 user: dan tags: recursive-selectdup
14:44
Modify the sqlite3SelectDup() routine to avoid recursing on Select.pPrior. check-in: a7674ead user: dan tags: recursive-selectdup
2017-02-02
20:32
Ensure that all cursors have their positions saved prior to rolling back a savepoint. check-in: 8e03a8e9 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/expr.c.

  1414   1414       struct IdList_item *pNewItem = &pNew->a[i];
  1415   1415       struct IdList_item *pOldItem = &p->a[i];
  1416   1416       pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName);
  1417   1417       pNewItem->idx = pOldItem->idx;
  1418   1418     }
  1419   1419     return pNew;
  1420   1420   }
  1421         -Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){
  1422         -  Select *pNew, *pPrior;
         1421  +Select *sqlite3SelectDup(sqlite3 *db, Select *pDup, int flags){
         1422  +  Select *pRet = 0;
         1423  +  Select *pNext = 0;
         1424  +  Select **pp = &pRet;
         1425  +  Select *p;
         1426  +
  1423   1427     assert( db!=0 );
  1424         -  if( p==0 ) return 0;
  1425         -  pNew = sqlite3DbMallocRawNN(db, sizeof(*p) );
  1426         -  if( pNew==0 ) return 0;
  1427         -  pNew->pEList = sqlite3ExprListDup(db, p->pEList, flags);
  1428         -  pNew->pSrc = sqlite3SrcListDup(db, p->pSrc, flags);
  1429         -  pNew->pWhere = sqlite3ExprDup(db, p->pWhere, flags);
  1430         -  pNew->pGroupBy = sqlite3ExprListDup(db, p->pGroupBy, flags);
  1431         -  pNew->pHaving = sqlite3ExprDup(db, p->pHaving, flags);
  1432         -  pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, flags);
  1433         -  pNew->op = p->op;
  1434         -  pNew->pPrior = pPrior = sqlite3SelectDup(db, p->pPrior, flags);
  1435         -  if( pPrior ) pPrior->pNext = pNew;
  1436         -  pNew->pNext = 0;
  1437         -  pNew->pLimit = sqlite3ExprDup(db, p->pLimit, flags);
  1438         -  pNew->pOffset = sqlite3ExprDup(db, p->pOffset, flags);
  1439         -  pNew->iLimit = 0;
  1440         -  pNew->iOffset = 0;
  1441         -  pNew->selFlags = p->selFlags & ~SF_UsesEphemeral;
  1442         -  pNew->addrOpenEphm[0] = -1;
  1443         -  pNew->addrOpenEphm[1] = -1;
  1444         -  pNew->nSelectRow = p->nSelectRow;
  1445         -  pNew->pWith = withDup(db, p->pWith);
  1446         -  sqlite3SelectSetName(pNew, p->zSelName);
  1447         -  return pNew;
         1428  +  for(p=pDup; p; p=p->pPrior){
         1429  +    Select *pNew = sqlite3DbMallocRawNN(db, sizeof(*p) );
         1430  +    if( pNew==0 ) break;
         1431  +    pNew->pEList = sqlite3ExprListDup(db, p->pEList, flags);
         1432  +    pNew->pSrc = sqlite3SrcListDup(db, p->pSrc, flags);
         1433  +    pNew->pWhere = sqlite3ExprDup(db, p->pWhere, flags);
         1434  +    pNew->pGroupBy = sqlite3ExprListDup(db, p->pGroupBy, flags);
         1435  +    pNew->pHaving = sqlite3ExprDup(db, p->pHaving, flags);
         1436  +    pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, flags);
         1437  +    pNew->op = p->op;
         1438  +    pNew->pNext = pNext;
         1439  +    pNew->pPrior = 0;
         1440  +    pNew->pLimit = sqlite3ExprDup(db, p->pLimit, flags);
         1441  +    pNew->pOffset = sqlite3ExprDup(db, p->pOffset, flags);
         1442  +    pNew->iLimit = 0;
         1443  +    pNew->iOffset = 0;
         1444  +    pNew->selFlags = p->selFlags & ~SF_UsesEphemeral;
         1445  +    pNew->addrOpenEphm[0] = -1;
         1446  +    pNew->addrOpenEphm[1] = -1;
         1447  +    pNew->nSelectRow = p->nSelectRow;
         1448  +    pNew->pWith = withDup(db, p->pWith);
         1449  +    sqlite3SelectSetName(pNew, p->zSelName);
         1450  +    *pp = pNew;
         1451  +    pp = &pNew->pPrior;
         1452  +    pNext = pNew;
         1453  +  }
         1454  +
         1455  +  return pRet;
  1448   1456   }
  1449   1457   #else
  1450   1458   Select *sqlite3SelectDup(sqlite3 *db, Select *p, int flags){
  1451   1459     assert( p==0 );
  1452   1460     return 0;
  1453   1461   }
  1454   1462   #endif