aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/resolve.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/resolve.c b/src/resolve.c
index 9be62c090..fbfdf118e 100644
--- a/src/resolve.c
+++ b/src/resolve.c
@@ -551,9 +551,18 @@ static int lookupName(
/* 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.
+ ** 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;
@@ -561,7 +570,12 @@ static int lookupName(
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;
}