AryaWu/sqlite
0
1# 2015-01-052#3# The author disclaims copyright to this source code. In place of4# 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 of13# VALUE terms works and does not hit the SQLITE_LIMIT_COMPOUND_SELECT limit.14#15 16set testdir [file dirname $argv0]17source $testdir/tester.tcl18set testprefix selectG19 20# Do an INSERT with a VALUES clause that contains 100,000 entries. Verify21# that this insert happens quickly (in less than 10 seconds). Actually, the22# insert will normally happen in less than 0.5 seconds on a workstation, but23# we allow plenty of overhead for slower machines. The speed test checks24# for an O(N*N) inefficiency that was once in the code and that would make25# the insert run for over a minute.26#27do_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 does40# not cause processor stack overflow.41#42do_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 $sql49} {1}50 51# Only the left-most term of a multi-valued VALUES within a scalar52# expression is evaluated.53#54do_test 120 {55 set n [llength [split [db eval "explain $sql"] \n]]56 expr {$n<10}57} {1}58 59finish_test60 