SQLite

Check-in [e721975faa]
Login

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

Overview
Comment:Extend [3e9ed1ae] so that covering indexes on WITHOUT ROWID tables are also identified.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e721975faa0925be4029330550ff2a9666041ff7
User & Date: dan 2016-02-24 20:16:28.164
Context
2016-02-25
13:33
In the command-line shell: When the ".import" command is creating a new table using column names from the first row of CSV input, make sure double-quotes in the name are properly escaped. (check-in: 2e67a1c823 user: drh tags: trunk)
2016-02-24
21:42
Initial work on an automated VSIX testing tool. Not working or tested yet. (check-in: 496e4ac984 user: mistachkin tags: vsixTest)
20:16
Extend [3e9ed1ae] so that covering indexes on WITHOUT ROWID tables are also identified. (check-in: e721975faa user: dan tags: trunk)
19:57
Change a char* to const char* in order to suppress some harmless compiler warnings. (check-in: 56f62e34ae user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/build.c.
3188
3189
3190
3191
3192
3193
3194




3195
3196


3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
        i++;
      }
    }
    assert( i==pIndex->nColumn );
  }else{
    pIndex->aiColumn[i] = XN_ROWID;
    pIndex->azColl[i] = sqlite3StrBINARY;




    /* If this index contains every column of its table, then mark
    ** it as a covering index */


    if( pTblName!=0 && pIndex->nColumn>=pTab->nCol ){
      pIndex->isCovering = 1;
      for(j=0; j<pTab->nCol; j++){
        if( j==pTab->iPKey ) continue;
        if( sqlite3ColumnOfIndex(pIndex,j)>=0 ) continue;
        pIndex->isCovering = 0;
        break;
      }
    }
  }
  sqlite3DefaultRowEst(pIndex);
  if( pParse->pNewTable==0 ) estimateIndexWidth(pIndex);

  if( pTab==pParse->pNewTable ){
    /* This routine has been called to create an automatic index as a
    ** result of a PRIMARY KEY or UNIQUE clause on a column definition, or
    ** a PRIMARY KEY or UNIQUE clause following the column definitions.
    ** i.e. one of:
    **







>
>
>
>
|
|
>
>
|
|
|
|
|
|
|
|
|
<
<
<







3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211



3212
3213
3214
3215
3216
3217
3218
        i++;
      }
    }
    assert( i==pIndex->nColumn );
  }else{
    pIndex->aiColumn[i] = XN_ROWID;
    pIndex->azColl[i] = sqlite3StrBINARY;
  }
  sqlite3DefaultRowEst(pIndex);
  if( pParse->pNewTable==0 ) estimateIndexWidth(pIndex);

  /* If this index contains every column of its table, then mark
  ** it as a covering index */
  assert( HasRowid(pTab) 
      || pTab->iPKey<0 || sqlite3ColumnOfIndex(pIndex, pTab->iPKey)>=0 );
  if( pTblName!=0 && pIndex->nColumn>=pTab->nCol ){
    pIndex->isCovering = 1;
    for(j=0; j<pTab->nCol; j++){
      if( j==pTab->iPKey ) continue;
      if( sqlite3ColumnOfIndex(pIndex,j)>=0 ) continue;
      pIndex->isCovering = 0;
      break;
    }
  }




  if( pTab==pParse->pNewTable ){
    /* This routine has been called to create an automatic index as a
    ** result of a PRIMARY KEY or UNIQUE clause on a column definition, or
    ** a PRIMARY KEY or UNIQUE clause following the column definitions.
    ** i.e. one of:
    **
Changes to test/coveridxscan.test.
84
85
86
87
88
89
90































91
92
93
} {3 4 5}
do_test 4.2 {
  db eval {SELECT a, c FROM t1}
} {5 3 4 2 3 1}
do_test 4.3 {
  db eval {SELECT b FROM t1}
} {2 4 8}

































finish_test







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
} {3 4 5}
do_test 4.2 {
  db eval {SELECT a, c FROM t1}
} {5 3 4 2 3 1}
do_test 4.3 {
  db eval {SELECT b FROM t1}
} {2 4 8}

#-------------------------------------------------------------------------
# Test that indexes with large numbers of columns can be correctly 
# identified as covering indexes.
reset_db
set L [list]
for {set i 1} {$i<120} {incr i} {
  lappend L "c$i"
}
set cols [join $L ,]

do_execsql_test 5.1.0 "
  CREATE TABLE t1(a, b, c, $cols, PRIMARY KEY(a, b, c)) WITHOUT ROWID;
  CREATE INDEX i1 ON t1($cols);

  CREATE TABLE t2(i INTEGER PRIMARY KEY, $cols);
  CREATE INDEX i2 ON t2($cols);
"

do_eqp_test 5.1.1 {
  SELECT * FROM t1 ORDER BY c1, c2;
} {
  0 0 0 {SCAN TABLE t1 USING COVERING INDEX i1}
}

do_eqp_test 5.1.2 {
  SELECT * FROM t2 ORDER BY c1, c2;
} {
  0 0 0 {SCAN TABLE t2 USING COVERING INDEX i2}
}



finish_test