gitlab.com/CoiaPrant/sqlite3@v1.19.1/testdata/tcl/selectG.test (about)

     1  # 2015-01-05
     2  #
     3  # The author disclaims copyright to this source code.  In place of
     4  # a legal notice, here is a blessing:
     5  #
     6  #    May you do good and not evil.
     7  #    May you find forgiveness for yourself and forgive others.
     8  #    May you share freely, never taking more than you give.
     9  #
    10  #***********************************************************************
    11  #
    12  # This file verifies that INSERT operations with a very large number of
    13  # VALUE terms works and does not hit the SQLITE_LIMIT_COMPOUND_SELECT limit.
    14  #
    15  
    16  set testdir [file dirname $argv0]
    17  source $testdir/tester.tcl
    18  set testprefix selectG
    19  
    20  # Do an INSERT with a VALUES clause that contains 100,000 entries.  Verify
    21  # that this insert happens quickly (in less than 10 seconds).  Actually, the
    22  # insert will normally happen in less than 0.5 seconds on a workstation, but
    23  # we allow plenty of overhead for slower machines.  The speed test checks
    24  # for an O(N*N) inefficiency that was once in the code and that would make
    25  # the insert run for over a minute.
    26  #
    27  do_test 100 {
    28    set sql "CREATE TABLE t1(x);\nINSERT INTO t1(x) VALUES"
    29    for {set i 1} {$i<100000} {incr i} {
    30      append sql "($i),"
    31    }
    32    append sql "($i);"
    33    set microsec [lindex [time {db eval $sql}] 0]
    34    db eval {
    35      SELECT count(x), sum(x), avg(x), $microsec<10000000 FROM t1;
    36    }
    37  } {100000 5000050000 50000.5 1}
    38    
    39  # 2018-01-14.  A 100K-entry VALUES clause within a scalar expression does
    40  # not cause processor stack overflow.
    41  #
    42  do_test 110 {
    43    set sql "SELECT (VALUES"
    44    for {set i 1} {$i<100000} {incr i} {
    45      append sql "($i),"
    46    }
    47    append sql "($i));"
    48    db eval $sql
    49  } {1}
    50  
    51  # Only the left-most term of a multi-valued VALUES within a scalar
    52  # expression is evaluated.
    53  #
    54  do_test 120 {
    55    set n [llength [split [db eval "explain $sql"] \n]]
    56    expr {$n<10}
    57  } {1}
    58  
    59  finish_test