SQLite

Check-in [6601da58]
Login

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

Overview
Comment:Whenever a generated column is used, assume that all columns are used.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 6601da58032d18ae00b466c0f2077fb2b1ecd84225b56e1787724bea478eedc9
User & Date: drh 2019-11-21 19:37:00
References
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)
Context
2019-11-21
20:10
Fix an out-of-bounds array reference in the generated column logic. Problem discovered by valgrind. (check-in: a0ab42f7 user: drh tags: trunk)
19:37
Whenever a generated column is used, assume that all columns are used. (check-in: 6601da58 user: drh tags: trunk)
18:28
Fix a problem that comes up when using generated columns that evaluate to a constant in an index and then making use of that index in a join. (check-in: 8b12e95f user: drh tags: trunk)
Changes
Unified Diff 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
    }
    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.  If the







  ** column number is greater than the number of bits in the bitmask
  ** then set the high-order bit of the bitmask.


  */
  if( pExpr->iColumn>=0 && pMatch!=0 ){
    int n = pExpr->iColumn;
    testcase( n==BMS-1 );
    if( n>=BMS ){
      n = BMS-1;
    }

    assert( pMatch->iCursor==pExpr->iTable );




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

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







|
>
>
>
>
>
>
>
|
|
>
>







>

>
>
>
>







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
    }
    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 *pCol = pExpr->y.pTab->aCol + pExpr->iColumn;
      if( pCol->colFlags & COLFLAG_GENERATED ) n = BMS-1;
    }
    pMatch->colUsed |= ((Bitmask)1)<<n;
  }

  /* Clean up and return
  */
  sqlite3ExprDelete(db, pExpr->pLeft);
  pExpr->pLeft = 0;
Changes to test/gencol1.test.
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257






258
259
  );
  UPDATE t0 SET c0 = NULL;
} {1 {generated column loop on "c2"}}

# 2019-11-21 Problems in the new generated column logic
# reported by Yongheng Chen and Rui Zhong
do_execsql_test gencol1-9.10 {
  DROP TABLE IF EXISTS t1;
  DROP TABLE IF EXISTS t2;
  CREATE TABLE t1(aa , bb AS (17) UNIQUE);
  INSERT INTO t1 VALUES(17);
  CREATE TABLE t2(cc);
  INSERT INTO t2 VALUES(41);
  SELECT * FROM t2 JOIN t1 WHERE t1.bb=t1.aa AND t1.bb=17;
} {41 17 17}








finish_test







|
<






|
>
>
>
>
>
>


242
243
244
245
246
247
248
249

250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
  );
  UPDATE t0 SET c0 = NULL;
} {1 {generated column loop on "c2"}}

# 2019-11-21 Problems in the new generated column logic
# reported by Yongheng Chen and Rui Zhong
do_execsql_test gencol1-9.10 {
  DROP TABLE t1;

  CREATE TABLE t1(aa , bb AS (17) UNIQUE);
  INSERT INTO t1 VALUES(17);
  CREATE TABLE t2(cc);
  INSERT INTO t2 VALUES(41);
  SELECT * FROM t2 JOIN t1 WHERE t1.bb=t1.aa AND t1.bb=17;
} {41 17 17}
do_execsql_test gencol1-9.20 {
  CREATE TABLE t3(aa INT PRIMARY KEY, bb UNIQUE AS(aa));
  INSERT INTO t3 VALUES(1);
  SELECT 100, * FROM t3;
  DELETE FROM t3 WHERE (SELECT bb FROM t3);
  SELECT 200, * FROM t3;
} {100 1 1}

finish_test