SQLite

Check-in [9d75e1cc]
Login

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

Overview
Comment:Fix incorrect column-usage accounting associated with generated columns and added by check-in [6601da58032d18ae]. Fix for ticket [b92e5e8ec2cdbaa1].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 9d75e1ccc72e9f536f45df3b24e9ecd25076cc1f7cf16b806b19e0e1b68e8326
User & Date: drh 2019-12-08 00:06:39
Context
2019-12-09
02:20
Fix possible null pointer dereferences in the fts5_expr() scalar function. (check-in: c5d44143 user: dan tags: trunk)
2019-12-08
00:06
Fix incorrect column-usage accounting associated with generated columns and added by check-in [6601da58032d18ae]. Fix for ticket [b92e5e8ec2cdbaa1]. (check-in: 9d75e1cc user: drh tags: trunk)
2019-12-07
13:42
Correctly deal with multi-row VALUES clauses that contain window functions. (check-in: 26d991f2 user: drh tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/resolve.c.

547
548
549
550
551
552
553
554

555
556
557
558
559

560
561
562
563
564
565
566
567
568

569
570
571
572
573

574
575
576
577








578
579
580
581
582
583
584
    }
    pParse->checkSchema = 1;
    pTopNC->nErr++;
  }

  /* If a column from a table in pSrcList is referenced, then record
  ** this fact in the pSrcList.a[].colUsed bitmask.  Column 0 causes
  ** bit 0 to be set.  Column 1 sets bit 1.  And so forth.

  **
  ** The colUsed mask is an optimization used to help determine if an
  ** index is a covering index.  The correct answer is still obtained
  ** if the mask contains extra bits.  But omitting bits from the mask
  ** might result in an incorrect answer.

  **
  ** The high-order bit of the mask is a "we-use-them-all" bit.
  ** If the column number is greater than the number of bits in the bitmask
  ** then set the high-order bit of the bitmask.  Also set the high-order
  ** bit if the column is a generated column, as that adds dependencies
  ** that are difficult to track, so we assume that all columns are used.
  */
  if( pExpr->iColumn>=0 && pMatch!=0 ){
    int n = pExpr->iColumn;

    testcase( n==BMS-1 );
    if( n>=BMS ){
      n = BMS-1;
    }
    assert( pExpr->y.pTab!=0 );

    assert( pMatch->iCursor==pExpr->iTable );
    if( pExpr->y.pTab->tabFlags & TF_HasGenerated ){
      Column *pColumn = pExpr->y.pTab->aCol + pExpr->iColumn;
      if( pColumn->colFlags & COLFLAG_GENERATED ) n = BMS-1;








    }
    pMatch->colUsed |= ((Bitmask)1)<<n;
  }

  /* Clean up and return
  */
  sqlite3ExprDelete(db, pExpr->pLeft);







|
>



|
|
>

<
|
|
<
<



>




|
>

|
|
|
>
>
>
>
>
>
>
>







547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562

563
564


565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
    }
    pParse->checkSchema = 1;
    pTopNC->nErr++;
  }

  /* If a column from a table in pSrcList is referenced, then record
  ** this fact in the pSrcList.a[].colUsed bitmask.  Column 0 causes
  ** bit 0 to be set.  Column 1 sets bit 1.  And so forth.  Bit 63 is
  ** set if the 63rd or any subsequent column is used.
  **
  ** The colUsed mask is an optimization used to help determine if an
  ** index is a covering index.  The correct answer is still obtained
  ** if the mask contains extra set bits.  However, it is important to
  ** avoid setting bits beyond the maximum column number of the table.
  ** (See ticket [b92e5e8ec2cdbaa1]).
  **

  ** If a generated column is referenced, set bits for every column
  ** of the table.


  */
  if( pExpr->iColumn>=0 && pMatch!=0 ){
    int n = pExpr->iColumn;
    Table *pTab;
    testcase( n==BMS-1 );
    if( n>=BMS ){
      n = BMS-1;
    }
    pTab = pExpr->y.pTab;
    assert( pTab!=0 );
    assert( pMatch->iCursor==pExpr->iTable );
    if( pTab->tabFlags & TF_HasGenerated ){
      Column *pColumn = pTab->aCol + pExpr->iColumn;
      if( pColumn->colFlags & COLFLAG_GENERATED ){
        testcase( pTab->nCol==63 );
        testcase( pTab->nCol==64 );
        if( pTab->nCol>=64 ){
          pMatch->colUsed = ALLBITS;
        }else{
          pMatch->colUsed = MASKBIT(pTab->nCol)-1;
        }
      }
    }
    pMatch->colUsed |= ((Bitmask)1)<<n;
  }

  /* Clean up and return
  */
  sqlite3ExprDelete(db, pExpr->pLeft);