SQLite

Check-in [cc60321a67]
Login

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

Overview
Comment:Always assume that indexed expressions can generate a NULL. Get indexed expressions working for the case of two or more expressions in the same index.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | index-expr
Files: files | file ages | folders
SHA1: cc60321a67bf9f169c090b47afb505f589a6925e
User & Date: drh 2015-08-31 19:38:42.715
Context
2015-08-31
21:16
Not only date/time functions, but also functions like sqlite_version() and changes() need to be prohibited from use inside of indexes. (check-in: 4871313039 user: drh tags: index-expr)
19:38
Always assume that indexed expressions can generate a NULL. Get indexed expressions working for the case of two or more expressions in the same index. (check-in: cc60321a67 user: drh tags: index-expr)
18:13
Case should not be significant when comparing function names. (check-in: e2f1caf117 user: drh tags: index-expr)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/build.c.
3122
3123
3124
3125
3126
3127
3128

3129




3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
    if( pCExpr->op!=TK_COLUMN ){
      if( pTab==pParse->pNewTable ){
        sqlite3ErrorMsg(pParse, "expressions prohibited in PRIMARY KEY and "
                                "UNIQUE constraints");
        goto exit_create_index;
      }
      if( pIndex->aColExpr==0 ){

        pIndex->aColExpr = sqlite3ExprListDup(db, pList, 0);




      }
      j = -2;
      pIndex->aiColumn[i] = -2;
      if( sqlite3ExprCanBeNull(pList->a[i].pExpr) ){
        pIndex->uniqNotNull = 1;
      }
    }else{
      j = pCExpr->iColumn;
      assert( j<=0x7fff );
      if( j<0 ){
        j = pTab->iPKey;
      }else if( pTab->aCol[j].notNull==0 ){
        pIndex->uniqNotNull = 0;







>
|
>
>
>
>



<
|
<







3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137

3138

3139
3140
3141
3142
3143
3144
3145
    if( pCExpr->op!=TK_COLUMN ){
      if( pTab==pParse->pNewTable ){
        sqlite3ErrorMsg(pParse, "expressions prohibited in PRIMARY KEY and "
                                "UNIQUE constraints");
        goto exit_create_index;
      }
      if( pIndex->aColExpr==0 ){
        ExprList *pCopy = sqlite3ExprListDup(db, pList, 0);
        pIndex->aColExpr = pCopy;
        if( !db->mallocFailed ){
          assert( pCopy!=0 );
          pListItem = &pCopy->a[i];
        }
      }
      j = -2;
      pIndex->aiColumn[i] = -2;

      pIndex->uniqNotNull = 0;

    }else{
      j = pCExpr->iColumn;
      assert( j<=0x7fff );
      if( j<0 ){
        j = pTab->iPKey;
      }else if( pTab->aCol[j].notNull==0 ){
        pIndex->uniqNotNull = 0;
Changes to src/where.c.
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
  j = pIdx->aiColumn[iCol];
  if( j>=0 ){
    return pIdx->pTable->aCol[j].notNull;
  }else if( j==(-1) ){
    return 1;
  }else{
    assert( j==(-2) );
    return !sqlite3ExprCanBeNull(pIdx->aColExpr->a[iCol].pExpr);
  }
}

/*
** Return true if the DISTINCT expression-list passed as the third argument
** is redundant.
**







|







391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
  j = pIdx->aiColumn[iCol];
  if( j>=0 ){
    return pIdx->pTable->aCol[j].notNull;
  }else if( j==(-1) ){
    return 1;
  }else{
    assert( j==(-2) );
    return 0;  /* Assume an indexed expression can always yield a NULL */
  }
}

/*
** Return true if the DISTINCT expression-list passed as the third argument
** is redundant.
**