bigrow.test 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. # 2001 September 23
  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 stressing the library by putting large amounts
  13. # of data in a single row of a table.
  14. #
  15. # $Id: bigrow.test,v 1.4 2001/11/24 00:31:47 drh Exp $
  16. set testdir [file dirname $argv0]
  17. source $testdir/tester.tcl
  18. # Make a big string that we can use for test data
  19. #
  20. do_test bigrow-1.0 {
  21. set ::bigstr {}
  22. for {set i 1} {$i<=9999} {incr i} {
  23. set sep [string index "abcdefghijklmnopqrstuvwxyz" [expr {$i%26}]]
  24. append ::bigstr "$sep [format %04d $i] "
  25. }
  26. string length $::bigstr
  27. } {69993}
  28. # Make a table into which we can insert some but records.
  29. #
  30. do_test bigrow-1.1 {
  31. execsql {
  32. CREATE TABLE t1(a text, b text, c text);
  33. SELECT name FROM sqlite_master
  34. WHERE type='table' OR type='index'
  35. ORDER BY name
  36. }
  37. } {t1}
  38. do_test bigrow-1.2 {
  39. set ::big1 [string range $::bigstr 0 65519]
  40. set sql "INSERT INTO t1 VALUES('abc',"
  41. append sql "'$::big1', 'xyz');"
  42. execsql $sql
  43. execsql {SELECT a, c FROM t1}
  44. } {abc xyz}
  45. do_test bigrow-1.3 {
  46. execsql {SELECT b FROM t1}
  47. } [list $::big1]
  48. do_test bigrow-1.4 {
  49. set ::big2 [string range $::bigstr 0 65520]
  50. set sql "INSERT INTO t1 VALUES('abc2',"
  51. append sql "'$::big2', 'xyz2');"
  52. set r [catch {execsql $sql} msg]
  53. lappend r $msg
  54. } {0 {}}
  55. do_test bigrow-1.4.1 {
  56. execsql {SELECT b FROM t1 ORDER BY c}
  57. } [list $::big1 $::big2]
  58. do_test bigrow-1.4.2 {
  59. execsql {SELECT c FROM t1 ORDER BY c}
  60. } {xyz xyz2}
  61. do_test bigrow-1.4.3 {
  62. execsql {DELETE FROM t1 WHERE a='abc2'}
  63. execsql {SELECT c FROM t1}
  64. } {xyz}
  65. do_test bigrow-1.5 {
  66. execsql {
  67. UPDATE t1 SET a=b, b=a;
  68. SELECT b,c FROM t1
  69. }
  70. } {abc xyz}
  71. do_test bigrow-1.6 {
  72. execsql {
  73. SELECT * FROM t1
  74. }
  75. } [list $::big1 abc xyz]
  76. do_test bigrow-1.7 {
  77. execsql {
  78. INSERT INTO t1 VALUES('1','2','3');
  79. INSERT INTO t1 VALUES('A','B','C');
  80. SELECT b FROM t1 WHERE a=='1';
  81. }
  82. } {2}
  83. do_test bigrow-1.8 {
  84. execsql "SELECT b FROM t1 WHERE a=='$::big1'"
  85. } {abc}
  86. do_test bigrow-1.9 {
  87. execsql "SELECT b FROM t1 WHERE a!='$::big1' ORDER BY a"
  88. } {2 B}
  89. # Try doing some indexing on big columns
  90. #
  91. do_test bigrow-2.1 {
  92. execsql {
  93. CREATE INDEX i1 ON t1(a)
  94. }
  95. execsql "SELECT b FROM t1 WHERE a=='$::big1'"
  96. } {abc}
  97. do_test bigrow-2.2 {
  98. execsql {
  99. UPDATE t1 SET a=b, b=a
  100. }
  101. execsql "SELECT b FROM t1 WHERE a=='abc'"
  102. } [list $::big1]
  103. do_test bigrow-2.3 {
  104. execsql {
  105. UPDATE t1 SET a=b, b=a
  106. }
  107. execsql "SELECT b FROM t1 WHERE a=='$::big1'"
  108. } {abc}
  109. catch {unset ::bigstr}
  110. catch {unset ::big1}
  111. catch {unset ::big2}
  112. # Mosts of the tests above were created back when rows were limited in
  113. # size to 64K. Now rows can be much bigger. Test that logic. Also
  114. # make sure things work correctly at the transition boundries between
  115. # row sizes of 256 to 257 bytes and from 65536 to 65537 bytes.
  116. #
  117. # We begin by testing the 256..257 transition.
  118. #
  119. do_test bigrow-3.1 {
  120. execsql {
  121. DELETE FROM t1;
  122. INSERT INTO t1(a,b,c) VALUES('one','abcdefghijklmnopqrstuvwxyz0123','hi');
  123. }
  124. execsql {SELECT a,length(b),c FROM t1}
  125. } {one 30 hi}
  126. do_test bigrow-3.2 {
  127. execsql {
  128. UPDATE t1 SET b=b||b;
  129. UPDATE t1 SET b=b||b;
  130. UPDATE t1 SET b=b||b;
  131. }
  132. execsql {SELECT a,length(b),c FROM t1}
  133. } {one 240 hi}
  134. for {set i 1} {$i<10} {incr i} {
  135. do_test bigrow-3.3.$i {
  136. execsql "UPDATE t1 SET b=b||'$i'"
  137. execsql {SELECT a,length(b),c FROM t1}
  138. } "one [expr {240+$i}] hi"
  139. }
  140. # Now test the 65536..65537 row-size transition.
  141. #
  142. do_test bigrow-4.1 {
  143. execsql {
  144. DELETE FROM t1;
  145. INSERT INTO t1(a,b,c) VALUES('one','abcdefghijklmnopqrstuvwxyz0123','hi');
  146. }
  147. execsql {SELECT a,length(b),c FROM t1}
  148. } {one 30 hi}
  149. do_test bigrow-4.2 {
  150. execsql {
  151. UPDATE t1 SET b=b||b;
  152. UPDATE t1 SET b=b||b;
  153. UPDATE t1 SET b=b||b;
  154. UPDATE t1 SET b=b||b;
  155. UPDATE t1 SET b=b||b;
  156. UPDATE t1 SET b=b||b;
  157. UPDATE t1 SET b=b||b;
  158. UPDATE t1 SET b=b||b;
  159. UPDATE t1 SET b=b||b;
  160. UPDATE t1 SET b=b||b;
  161. UPDATE t1 SET b=b||b;
  162. UPDATE t1 SET b=b||b;
  163. }
  164. execsql {SELECT a,length(b),c FROM t1}
  165. } {one 122880 hi}
  166. do_test bigrow-4.3 {
  167. execsql {
  168. UPDATE t1 SET b=substr(b,1,65515)
  169. }
  170. execsql {SELECT a,length(b),c FROM t1}
  171. } {one 65515 hi}
  172. for {set i 1} {$i<10} {incr i} {
  173. do_test bigrow-4.4.$i {
  174. execsql "UPDATE t1 SET b=b||'$i'"
  175. execsql {SELECT a,length(b),c FROM t1}
  176. } "one [expr {65515+$i}] hi"
  177. }
  178. # Check to make sure the library recovers safely if a row contains
  179. # too much data.
  180. #
  181. do_test bigrow-5.1 {
  182. execsql {
  183. DELETE FROM t1;
  184. INSERT INTO t1(a,b,c) VALUES('one','abcdefghijklmnopqrstuvwxyz0123','hi');
  185. }
  186. execsql {SELECT a,length(b),c FROM t1}
  187. } {one 30 hi}
  188. set i 1
  189. for {set sz 60} {$sz<1048560} {incr sz $sz} {
  190. do_test bigrow-5.2.$i {
  191. execsql {
  192. UPDATE t1 SET b=b||b;
  193. SELECT a,length(b),c FROM t1;
  194. }
  195. } "one $sz hi"
  196. incr i
  197. }
  198. do_test bigrow-5.3 {
  199. set r [catch {execsql {UPDATE t1 SET b=b||b}} msg]
  200. lappend r $msg
  201. } {1 {too much data for one table row}}
  202. do_test bigrow-5.4 {
  203. execsql {DROP TABLE t1}
  204. } {}
  205. finish_test