/ Check-in [2c201292]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Update trace2.test to account for new FTS queries.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fts3-prefix-search
Files: files | file ages | folders
SHA1: 2c20129297b64f4113b8edb551385eb918279471
User & Date: dan 2011-06-13 18:21:11
Context
2011-06-14
07:14
Remove unused parameters from internal fts3 function. check-in: 06de3f2c user: dan tags: fts3-prefix-search
2011-06-13
18:21
Update trace2.test to account for new FTS queries. check-in: 2c201292 user: dan tags: fts3-prefix-search
17:00
Add tests for deferred tokens to fts3auto.test. Fix a problem with OR queries and deferred tokens. check-in: b9fb69e5 user: dan tags: fts3-prefix-search
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to test/fts3auto.test.

    17     17   source $testdir/malloc_common.tcl
    18     18   
    19     19   set testprefix fts3auto
    20     20   set sfep $sqlite_fts3_enable_parentheses
    21     21   set sqlite_fts3_enable_parentheses 1
    22     22   
    23     23   #--------------------------------------------------------------------------
    24         -# Start of Tcl procs used by tests.
           24  +# Start of Tcl infrastructure used by tests. The entry point is
           25  +# [do_fts3query_test] (described below).
    25     26   #
           27  +
           28  +#    do_fts3query_test TESTNAME ?OPTIONS? TABLE MATCHEXPR
           29  +#
           30  +# This proc runs several test cases on FTS3/4 table $TABLE using match
           31  +# expression $MATCHEXPR. All documents in $TABLE must be formatted so that
           32  +# they can be "tokenized" using the Tcl list commands (llength, lindex etc.).
           33  +# The name and column names used by $TABLE must not require any quoting or
           34  +# escaping when used in SQL statements.
           35  +#
           36  +# $MATCHINFO may be any expression accepted by the FTS4 MATCH operator, 
           37  +# except that the "<column-name>:token" syntax is not supported. Tcl list
           38  +# commands are used to tokenize the expression. Any parenthesis must appear
           39  +# either as separate list elements, or as the first (for opening) or last
           40  +# (for closing) character of a list element. i.e. the expression "(a OR b)c"
           41  +# will not be parsed correctly, but "( a OR b) c" will.
           42  +#
           43  +set sqlite_fts3_enable_parentheses 1
           44  +proc do_fts3query_test {tn tbl expr} {
           45  +
           46  +  get_near_results $tbl $expr aMatchinfo
           47  +  set match $expr
           48  +
           49  +  set matchinfo_asc [list]
           50  +  foreach docid [lsort -integer -incr [array names aMatchinfo]] {
           51  +    lappend matchinfo_asc $docid $aMatchinfo($docid)
           52  +  }
           53  +  set matchinfo_desc [list]
           54  +  foreach docid [lsort -integer -decr [array names aMatchinfo]] {
           55  +    lappend matchinfo_desc $docid $aMatchinfo($docid)
           56  +  }
           57  +
           58  +  set title "(\"$match\" -> [llength [array names aMatchinfo]] rows)"
           59  +
           60  +  do_execsql_test $tn$title.1 "
           61  +    SELECT docid FROM $tbl WHERE $tbl MATCH '$match' ORDER BY docid ASC
           62  +  " [lsort -integer -incr [array names aMatchinfo]] 
           63  +
           64  +  do_execsql_test $tn$title.2 "
           65  +    SELECT docid FROM $tbl WHERE $tbl MATCH '$match' ORDER BY docid DESC
           66  +  " [lsort -integer -decr [array names aMatchinfo]] 
           67  +
           68  +  do_execsql_test $tn$title.3 "
           69  +    SELECT docid, mit(matchinfo($tbl, 'x')) FROM $tbl 
           70  +    WHERE $tbl MATCH '$match' ORDER BY docid DESC
           71  +  " $matchinfo_desc
           72  +
           73  +  do_execsql_test $tn$title.4 "
           74  +    SELECT docid, mit(matchinfo($tbl, 'x')) FROM $tbl 
           75  +    WHERE $tbl MATCH '$match' ORDER BY docid ASC
           76  +  " $matchinfo_asc
           77  +}
           78  +
           79  +
    26     80   proc mit {blob} {
    27     81     set scan(littleEndian) i*
    28     82     set scan(bigEndian) I*
    29     83     binary scan $blob $scan($::tcl_platform(byteOrder)) r
    30     84     return $r
    31     85   }
    32     86   db func mit mit
................................................................................
   248    302   
   249    303           set nullentry [concat $nullleft $nullright]
   250    304         }
   251    305       }
   252    306     }
   253    307   }
   254    308   
   255         -proc do_fts3query_test {tn tbl expr} {
   256         -
   257         -  get_near_results $tbl $expr aMatchinfo
   258         -  set match $expr
   259         -
   260         -  set matchinfo_asc [list]
   261         -  foreach docid [lsort -integer -incr [array names aMatchinfo]] {
   262         -    lappend matchinfo_asc $docid $aMatchinfo($docid)
   263         -  }
   264         -  set matchinfo_desc [list]
   265         -  foreach docid [lsort -integer -decr [array names aMatchinfo]] {
   266         -    lappend matchinfo_desc $docid $aMatchinfo($docid)
   267         -  }
   268         -
   269         -  set title "(\"$match\" -> [llength [array names aMatchinfo]] rows)"
   270         -
   271         -  do_execsql_test $tn$title.1 "
   272         -    SELECT docid FROM $tbl WHERE $tbl MATCH '$match' ORDER BY docid ASC
   273         -  " [lsort -integer -incr [array names aMatchinfo]] 
   274         -
   275         -  do_execsql_test $tn$title.2 "
   276         -    SELECT docid FROM $tbl WHERE $tbl MATCH '$match' ORDER BY docid DESC
   277         -  " [lsort -integer -decr [array names aMatchinfo]] 
   278         -
   279         -  do_execsql_test $tn$title.3 "
   280         -    SELECT docid, mit(matchinfo($tbl, 'x')) FROM $tbl 
   281         -    WHERE $tbl MATCH '$match' ORDER BY docid DESC
   282         -  " $matchinfo_desc
   283         -
   284         -  do_execsql_test $tn$title.4 "
   285         -    SELECT docid, mit(matchinfo($tbl, 'x')) FROM $tbl 
   286         -    WHERE $tbl MATCH '$match' ORDER BY docid ASC
   287         -  " $matchinfo_asc
   288         -} 
   289         -
   290    309   
   291    310   # End of test procs. Actual tests are below this line.
   292    311   #--------------------------------------------------------------------------
   293    312   
   294    313   #--------------------------------------------------------------------------
   295    314   # The following test cases - fts3auto-1.* - focus on testing the Tcl 
   296    315   # command [fts3_near_match], which is used by other tests in this file.
................................................................................
   325    344     1    "fts4(a, b)"
   326    345     2    "fts4(a, b, order=DESC)"
   327    346     3    "fts4(a, b, order=ASC)"
   328    347     4    "fts4(a, b, prefix=1)"
   329    348     5    "fts4(a, b, order=DESC, prefix=1)"
   330    349     6    "fts4(a, b, order=ASC, prefix=1)"
   331    350   } {
   332         -break
   333    351     do_test 2.$tn.1 {
   334    352       catchsql { DROP TABLE t1 }
   335    353       execsql  "CREATE VIRTUAL TABLE t1 USING $create"
   336    354       for {set i 0} {$i<32} {incr i} {
   337    355         set doc [list]
   338    356         if {$i&0x01} {lappend doc one}
   339    357         if {$i&0x02} {lappend doc two}
................................................................................
   386    404   foreach {tn create} {
   387    405     1    "fts4(x)"
   388    406     2    "fts4(x, order=DESC)"
   389    407   } {
   390    408     catchsql { DROP TABLE t1 }
   391    409     execsql  "CREATE VIRTUAL TABLE t1 USING $create"
   392    410     do_execsql_test 3.$tn.1 {
   393         -    INSERT INTO t1 VALUES('a b c d e f g h i j k');
   394         -    INSERT INTO t1 VALUES('b c d e f g h i j k a');
   395         -    INSERT INTO t1 VALUES('c d e f g h i j k a b');
   396         -    INSERT INTO t1 VALUES('d e f g h i j k a b c');
   397         -    INSERT INTO t1 VALUES('e f g h i j k a b c d');
   398         -    INSERT INTO t1 VALUES('f g h i j k a b c d e');
   399         -    INSERT INTO t1 VALUES('a c e g i k');
   400         -    INSERT INTO t1 VALUES('a d g j');
   401         -    INSERT INTO t1 VALUES('c a b');
          411  +    INSERT INTO t1(docid, x) VALUES(-2, 'a b c d e f g h i j k');
          412  +    INSERT INTO t1(docid, x) VALUES(-1, 'b c d e f g h i j k a');
          413  +    INSERT INTO t1(docid, x) VALUES(0, 'c d e f g h i j k a b');
          414  +    INSERT INTO t1(docid, x) VALUES(1, 'd e f g h i j k a b c');
          415  +    INSERT INTO t1(docid, x) VALUES(2, 'e f g h i j k a b c d');
          416  +    INSERT INTO t1(docid, x) VALUES(3, 'f g h i j k a b c d e');
          417  +    INSERT INTO t1(docid, x) VALUES(4, 'a c e g i k');
          418  +    INSERT INTO t1(docid, x) VALUES(5, 'a d g j');
          419  +    INSERT INTO t1(docid, x) VALUES(6, 'c a b');
   402    420     }
   403    421   
   404    422     make_token_deferrable t1 c
   405    423   
   406    424     set ::fts3_deferred [list]
   407    425     foreach {tn2 expr} {
   408    426       1     {a OR c}

Changes to test/trace2.test.

   137    137       "-- INSERT INTO 'main'.'x1_segdir' VALUES(?,?,?,?,?,?)"
   138    138     }
   139    139   
   140    140     do_trace_test 2.3 {
   141    141       INSERT INTO x1(x1) VALUES('optimize');
   142    142     } {
   143    143       "INSERT INTO x1(x1) VALUES('optimize');"
   144         -    "-- SELECT idx, start_block, leaves_end_block, end_block, root FROM 'main'.'x1_segdir' ORDER BY level DESC, idx ASC"
   145         -    "-- SELECT count(*), max(level) FROM 'main'.'x1_segdir'"
          144  +    "-- SELECT idx, start_block, leaves_end_block, end_block, root FROM 'main'.'x1_segdir' WHERE level BETWEEN ? AND ?ORDER BY level DESC, idx ASC"
          145  +    "-- SELECT max(level) FROM 'main'.'x1_segdir' WHERE level BETWEEN ? AND ?"
   146    146       "-- SELECT coalesce((SELECT max(blockid) FROM 'main'.'x1_segments') + 1, 1)"
   147         -    "-- DELETE FROM 'main'.'x1_segdir'"
          147  +    "-- DELETE FROM 'main'.'x1_segdir' WHERE level BETWEEN ? AND ?"
   148    148       "-- INSERT INTO 'main'.'x1_segdir' VALUES(?,?,?,?,?,?)"
   149    149     }
   150    150   }
   151    151   
   152    152   finish_test