1
0

in2.test 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # 2007 May 12
  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 tests a special case in the b-tree code that can be
  12. # hit by the "IN" operator (or EXISTS, NOT IN, etc.).
  13. #
  14. # $Id: in2.test,v 1.3 2008/07/12 14:52:20 drh Exp $
  15. set testdir [file dirname $argv0]
  16. source $testdir/tester.tcl
  17. do_test in2-1 {
  18. execsql {
  19. CREATE TABLE a(i INTEGER PRIMARY KEY, a);
  20. }
  21. } {}
  22. set ::N 2000
  23. do_test in2-2 {
  24. db transaction {
  25. for {set ::ii 0} {$::ii < $::N} {incr ::ii} {
  26. execsql {INSERT INTO a VALUES($::ii, $::ii)}
  27. }
  28. execsql {INSERT INTO a VALUES(4000, '')}
  29. for {set ::ii 0} {$::ii < $::N} {incr ::ii} {
  30. set ::t [format "x%04d" $ii]
  31. execsql {INSERT INTO a VALUES(NULL, $::t)}
  32. }
  33. }
  34. } {}
  35. # Each iteration of this loop builds a slightly different b-tree to
  36. # evaluate the "IN (...)" operator in the SQL statement. The contents
  37. # of the b-tree are (in sorted order):
  38. #
  39. # $::ii integers.
  40. # a string of zero length.
  41. # $::N short strings.
  42. #
  43. # Records are inserted in sorted order.
  44. #
  45. # The string of zero-length is stored in a b-tree cell with 3 bytes
  46. # of payload. Moving this cell from a leaf node to a internal node
  47. # during b-tree balancing was causing an assertion failure.
  48. #
  49. # This bug only applied to b-trees generated to evaluate IN (..)
  50. # clauses, as it is impossible for persistent b-trees (SQL tables +
  51. # indices) to contain cells smaller than 4 bytes.
  52. #
  53. for {set ::ii 3} {$::ii < $::N} {incr ::ii} {
  54. do_test in2-$::ii {
  55. execsql {
  56. SELECT 1 IN (SELECT a FROM a WHERE (i < $::ii) OR (i >= $::N))
  57. }
  58. } {1}
  59. }
  60. finish_test