index2.test 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # 2005 January 11
  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. # This file implements regression tests for SQLite library. The
  12. # focus of this file is testing the CREATE INDEX statement.
  13. #
  14. # $Id: index2.test,v 1.3 2006/03/03 19:12:30 drh Exp $
  15. set testdir [file dirname $argv0]
  16. source $testdir/tester.tcl
  17. # Create a table with a large number of columns
  18. #
  19. do_test index2-1.1 {
  20. set sql {CREATE TABLE t1(}
  21. for {set i 1} {$i<1000} {incr i} {
  22. append sql "c$i,"
  23. }
  24. append sql "c1000);"
  25. execsql $sql
  26. } {}
  27. do_test index2-1.2 {
  28. set sql {INSERT INTO t1 VALUES(}
  29. for {set i 1} {$i<1000} {incr i} {
  30. append sql $i,
  31. }
  32. append sql {1000);}
  33. execsql $sql
  34. } {}
  35. do_test index2-1.3 {
  36. execsql {SELECT c123 FROM t1}
  37. } 123
  38. do_test index2-1.4 {
  39. execsql BEGIN
  40. for {set j 1} {$j<=100} {incr j} {
  41. set sql {INSERT INTO t1 VALUES(}
  42. for {set i 1} {$i<1000} {incr i} {
  43. append sql [expr {$j*10000+$i}],
  44. }
  45. append sql "[expr {$j*10000+1000}]);"
  46. execsql $sql
  47. }
  48. execsql COMMIT
  49. execsql {SELECT count(*) FROM t1}
  50. } 101
  51. do_test index2-1.5 {
  52. execsql {SELECT round(sum(c1000)) FROM t1}
  53. } {50601000.0}
  54. # Create indices with many columns
  55. #
  56. do_test index2-2.1 {
  57. set sql "CREATE INDEX t1i1 ON t1("
  58. for {set i 1} {$i<1000} {incr i} {
  59. append sql c$i,
  60. }
  61. append sql c1000)
  62. execsql $sql
  63. } {}
  64. do_test index2-2.2 {
  65. ifcapable explain {
  66. execsql {EXPLAIN SELECT c9 FROM t1 ORDER BY c1, c2, c3, c4, c5}
  67. }
  68. execsql {SELECT c9 FROM t1 ORDER BY c1, c2, c3, c4, c5, c6 LIMIT 5}
  69. } {9 10009 20009 30009 40009}
  70. finish_test