SQLite

Check-in [85dc12625d]
Login

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

Overview
Comment:Optimize range constraints on the rowid column of fts3/4 tables even if there is no MATCH clause in the query.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 85dc12625d300fe48f3c096f54ebcb8b6ef4e30a
User & Date: dan 2015-01-29 11:52:22.452
Context
2015-01-29
18:38
Split up the SRC variable in Makefile.msc to avoid over-long cmd.exe commands when TOP is set to a long pathname. (check-in: 7d70ac65c1 user: drh tags: trunk)
17:54
Add the INITMODE test-control. (check-in: 5940af8e78 user: drh tags: initmode-testctrl)
11:52
Optimize range constraints on the rowid column of fts3/4 tables even if there is no MATCH clause in the query. (check-in: 85dc12625d user: dan tags: trunk)
2015-01-27
21:24
Fix harmless compiler warnings. (check-in: e7d2ec048c user: mistachkin tags: trunk)
Changes
Side-by-Side Diff Ignore Whitespace Patch
Changes to ext/fts3/fts3.c.
3160
3161
3162
3163
3164
3165
3166

3167
3168
3169
3170










3171
3172
3173
3174
3175
3176
3177
3160
3161
3162
3163
3164
3165
3166
3167




3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184







+
-
-
-
-
+
+
+
+
+
+
+
+
+
+








  /* Compile a SELECT statement for this cursor. For a full-table-scan, the
  ** statement loops through all rows of the %_content table. For a
  ** full-text query or docid lookup, the statement retrieves a single
  ** row by docid.
  */
  if( eSearch==FTS3_FULLSCAN_SEARCH ){
    if( pDocidGe || pDocidLe ){
    zSql = sqlite3_mprintf(
        "SELECT %s ORDER BY rowid %s",
        p->zReadExprlist, (pCsr->bDesc ? "DESC" : "ASC")
    );
      zSql = sqlite3_mprintf(
          "SELECT %s WHERE rowid BETWEEN %lld AND %lld ORDER BY rowid %s",
          p->zReadExprlist, pCsr->iMinDocid, pCsr->iMaxDocid,
          (pCsr->bDesc ? "DESC" : "ASC")
      );
    }else{
      zSql = sqlite3_mprintf("SELECT %s ORDER BY rowid %s", 
          p->zReadExprlist, (pCsr->bDesc ? "DESC" : "ASC")
      );
    }
    if( zSql ){
      rc = sqlite3_prepare_v2(p->db, zSql, -1, &pCsr->pStmt, 0);
      sqlite3_free(zSql);
    }else{
      rc = SQLITE_NOMEM;
    }
  }else if( eSearch==FTS3_DOCID_SEARCH ){
Changes to test/fts3query.test.
204
205
206
207
208
209
210

211






































































212


204
205
206
207
208
209
210
211

212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284







+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
  6 "SELECT snippet(t3, 'XXX', 'YYY', 'ZZZ', 0) FROM t3 WHERE t3 MATCH 'gestures'" 
  {{no XXXgesturesYYY}}

  7 "SELECT snippet(t3, 'XXX', 'YYY', 'ZZZ', 1, 5) FROM t3 WHERE t3 MATCH 'gestures'" 
  {{ZZZthe hand XXXgesturesYYY (called beatsZZZ}}
}

# Test some range queries on the rowid field.

# 
do_execsql_test 7.1 {
  CREATE VIRTUAL TABLE ft4 USING fts4(x);
  CREATE TABLE t4(x);
}

set SMALLINT -9223372036854775808
set LARGEINT  9223372036854775807
do_test 7.2 {
  db transaction {
    foreach {iFirst nEntry} [subst {
      0                      100
      $SMALLINT              100
      [expr $LARGEINT - 99]  100
    }] {
      for {set i 0} {$i < $nEntry} {incr i} {
        set iRowid [expr $i + $iFirst]
        execsql {
          INSERT INTO ft4(rowid, x) VALUES($iRowid, 'x y z');
          INSERT INTO  t4(rowid, x) VALUES($iRowid, 'x y z');
        }
      }
    }
  }
} {}

foreach {tn iFirst iLast} [subst {
  1   5 10
  2   $SMALLINT [expr $SMALLINT+5]
  3   $SMALLINT [expr $SMALLINT+50]
  4   [expr $LARGEINT-5] $LARGEINT
  5   $LARGEINT $LARGEINT
  6   $SMALLINT $LARGEINT
  7   $SMALLINT $SMALLINT
  8   $LARGEINT $SMALLINT
}] {
  set res [db eval { 
    SELECT rowid FROM t4 WHERE rowid BETWEEN $iFirst AND $iLast 
  } ]

  do_execsql_test 7.2.$tn.1.[llength $res] {
    SELECT rowid FROM ft4 WHERE rowid BETWEEN $iFirst AND $iLast
  } $res
  do_execsql_test 7.2.$tn.2.[llength $res] {
    SELECT rowid FROM ft4 WHERE rowid BETWEEN $iFirst AND $iLast
    ORDER BY rowid DESC
  } [lsort -decr -integer $res]
}

foreach ii [db eval {SELECT rowid FROM t4}] {
  set res1 [db eval {SELECT rowid FROM t4 WHERE rowid > $ii}]
  set res2 [db eval {SELECT rowid FROM t4 WHERE rowid < $ii}]

  do_execsql_test 7.3.$ii.1 {
    SELECT rowid FROM ft4 WHERE rowid > $ii
  } $res1

  do_execsql_test 7.3.$ii.2 {
    SELECT rowid FROM ft4 WHERE rowid < $ii
  } $res2

  do_execsql_test 7.3.$ii.3 {
    SELECT rowid FROM ft4 WHERE rowid > $ii ORDER BY rowid DESC
  } [lsort -integer -decr $res1]

  do_execsql_test 7.3.$ii.4 {
    SELECT rowid FROM ft4 WHERE rowid < $ii ORDER BY rowid DESC
  } [lsort -integer -decr $res2]
}

finish_test