SQLite

Check-in [04fe12b590]
Login

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

Overview
Comment:When reading from an index, the shared-cache lock must be on the corresponding table.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | est_count_pragma
Files: files | file ages | folders
SHA1: 04fe12b590ab67e40cd079b5e614b787f5f525ad
User & Date: drh 2016-10-21 18:01:40.991
Context
2016-10-25
13:57
First attempt at a utility program to compute sqlite_stat1 without doing a full table scan. (check-in: 7b83581a43 user: drh tags: est_count_pragma)
2016-10-21
18:01
When reading from an index, the shared-cache lock must be on the corresponding table. (check-in: 04fe12b590 user: drh tags: est_count_pragma)
17:45
Merge updates from trunk, and especially the ".mode quote" enhancement to the shell. (check-in: 0c8a5b8844 user: drh tags: est_count_pragma)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/pragma.c.
1437
1438
1439
1440
1441
1442
1443

1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455

1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
  ** then begin returning rows, one by one.  A max of <limit> rows will
  ** be returned.
  */
  case PragTyp_BTREE_SAMPLE: {
    Index *pIdx;
    Table *pTab = 0;
    Pgno iRoot = 0;

    int nCol = 0;
    const char *zName = 0;
    int iLimit = 10;
    int i;
    int regResult;
    int regLimit;
    int addrTop;
    int addrJmp;
    int addrSkip;
    double r;
    if( (pIdx = sqlite3FindIndex(db, zRight, zDb))!=0 ){
      iRoot = pIdx->tnum;

      zName = pIdx->zName;
      nCol = pIdx->nColumn;
    }else if( (pTab = sqlite3FindTable(db, zRight, zDb))!=0 ){
      zName = pTab->zName;
      if( HasRowid(pTab) ){
        iRoot = pTab->tnum;
        nCol = pTab->nCol;
      }else{
        pIdx = sqlite3PrimaryKeyIndex(pTab);
        iRoot = pIdx->tnum;
        nCol = pIdx->nColumn;
      }
    }else{
      break;
    }
    sqlite3VdbeSetNumCols(v, nCol);
    for(i=0; i<nCol; i++){







>












>





|



|







1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
  ** then begin returning rows, one by one.  A max of <limit> rows will
  ** be returned.
  */
  case PragTyp_BTREE_SAMPLE: {
    Index *pIdx;
    Table *pTab = 0;
    Pgno iRoot = 0;
    Pgno iLock = 0;
    int nCol = 0;
    const char *zName = 0;
    int iLimit = 10;
    int i;
    int regResult;
    int regLimit;
    int addrTop;
    int addrJmp;
    int addrSkip;
    double r;
    if( (pIdx = sqlite3FindIndex(db, zRight, zDb))!=0 ){
      iRoot = pIdx->tnum;
      iLock = pIdx->pTable->tnum;
      zName = pIdx->zName;
      nCol = pIdx->nColumn;
    }else if( (pTab = sqlite3FindTable(db, zRight, zDb))!=0 ){
      zName = pTab->zName;
      if( HasRowid(pTab) ){
        iLock = iRoot = pTab->tnum;
        nCol = pTab->nCol;
      }else{
        pIdx = sqlite3PrimaryKeyIndex(pTab);
        iLock = iRoot = pIdx->tnum;
        nCol = pIdx->nColumn;
      }
    }else{
      break;
    }
    sqlite3VdbeSetNumCols(v, nCol);
    for(i=0; i<nCol; i++){
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
    }
    if( r<0.0 ) r = 0.0;
    if( r>1.0 ) r = 1.0;
    if( pValues->nId>=3 ){
      iLimit = sqlite3Atoi(pValues->a[2].zName);
    }
    pParse->nTab++;
    sqlite3TableLock(pParse, iDb, iRoot, 0, zName);
    sqlite3CodeVerifySchema(pParse, iDb);
    sqlite3VdbeAddOp4Int(v, OP_OpenRead, 0, iRoot, iDb, nCol);
    if( pIdx ) sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
    regLimit = ++pParse->nMem;
    regResult = pParse->nMem+1;
    pParse->nMem += nCol;
    sqlite3VdbeAddOp2(v, OP_Integer, iLimit, regLimit);







|







1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
    }
    if( r<0.0 ) r = 0.0;
    if( r>1.0 ) r = 1.0;
    if( pValues->nId>=3 ){
      iLimit = sqlite3Atoi(pValues->a[2].zName);
    }
    pParse->nTab++;
    sqlite3TableLock(pParse, iDb, iLock, 0, zName);
    sqlite3CodeVerifySchema(pParse, iDb);
    sqlite3VdbeAddOp4Int(v, OP_OpenRead, 0, iRoot, iDb, nCol);
    if( pIdx ) sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
    regLimit = ++pParse->nMem;
    regResult = pParse->nMem+1;
    pParse->nMem += nCol;
    sqlite3VdbeAddOp2(v, OP_Integer, iLimit, regLimit);