stat.test 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. # 2010 July 09
  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 SELECT statement.
  13. #
  14. set testdir [file dirname $argv0]
  15. source $testdir/tester.tcl
  16. ifcapable !vtab||!compound {
  17. finish_test
  18. return
  19. }
  20. set ::asc 1
  21. proc a_string {n} { string range [string repeat [incr ::asc]. $n] 1 $n }
  22. db func a_string a_string
  23. register_dbstat_vtab db
  24. do_execsql_test stat-0.0 {
  25. PRAGMA auto_vacuum = OFF;
  26. CREATE VIRTUAL TABLE temp.stat USING dbstat;
  27. SELECT * FROM stat;
  28. } {}
  29. ifcapable wal {
  30. do_execsql_test stat-0.1 {
  31. PRAGMA journal_mode = WAL;
  32. PRAGMA journal_mode = delete;
  33. SELECT name, path, pageno, pagetype, ncell, payload, unused, mx_payload
  34. FROM stat;
  35. } {wal delete sqlite_master / 1 leaf 0 0 916 0}
  36. }
  37. do_test stat-1.0 {
  38. execsql {
  39. CREATE TABLE t1(a, b);
  40. CREATE INDEX i1 ON t1(b);
  41. INSERT INTO t1(rowid, a, b) VALUES(2, 2, 3);
  42. INSERT INTO t1(rowid, a, b) VALUES(3, 4, 5);
  43. }
  44. } {}
  45. do_test stat-1.1 {
  46. execsql {
  47. SELECT name, path, pageno, pagetype, ncell, payload, unused, mx_payload
  48. FROM stat WHERE name = 't1';
  49. }
  50. } {t1 / 2 leaf 2 10 998 5}
  51. do_test stat-1.2 {
  52. execsql {
  53. SELECT name, path, pageno, pagetype, ncell, payload, unused, mx_payload
  54. FROM stat WHERE name = 'i1';
  55. }
  56. } {i1 / 3 leaf 2 10 1000 5}
  57. do_test stat-1.3 {
  58. execsql {
  59. SELECT name, path, pageno, pagetype, ncell, payload, unused, mx_payload
  60. FROM stat WHERE name = 'sqlite_master';
  61. }
  62. } {sqlite_master / 1 leaf 2 77 831 40}
  63. do_test stat-1.4 {
  64. execsql {
  65. DROP TABLE t1;
  66. }
  67. } {}
  68. do_execsql_test stat-2.1 {
  69. CREATE TABLE t3(a PRIMARY KEY, b);
  70. INSERT INTO t3(rowid, a, b) VALUES(2, a_string(111), a_string(222));
  71. INSERT INTO t3 SELECT a_string(110+rowid), a_string(221+rowid) FROM t3
  72. ORDER BY rowid;
  73. INSERT INTO t3 SELECT a_string(110+rowid), a_string(221+rowid) FROM t3
  74. ORDER BY rowid;
  75. INSERT INTO t3 SELECT a_string(110+rowid), a_string(221+rowid) FROM t3
  76. ORDER BY rowid;
  77. INSERT INTO t3 SELECT a_string(110+rowid), a_string(221+rowid) FROM t3
  78. ORDER BY rowid;
  79. INSERT INTO t3 SELECT a_string(110+rowid), a_string(221+rowid) FROM t3
  80. ORDER BY rowid;
  81. SELECT name, path, pageno, pagetype, ncell, payload, unused, mx_payload
  82. FROM stat WHERE name != 'sqlite_master';
  83. } [list \
  84. sqlite_autoindex_t3_1 / 3 internal 3 368 623 125 \
  85. sqlite_autoindex_t3_1 /000/ 8 leaf 8 946 46 123 \
  86. sqlite_autoindex_t3_1 /001/ 9 leaf 8 988 2 131 \
  87. sqlite_autoindex_t3_1 /002/ 15 leaf 7 857 137 132 \
  88. sqlite_autoindex_t3_1 /003/ 20 leaf 6 739 257 129 \
  89. t3 / 2 internal 15 0 907 0 \
  90. t3 /000/ 4 leaf 2 678 328 340 \
  91. t3 /001/ 5 leaf 2 682 324 342 \
  92. t3 /002/ 6 leaf 2 682 324 342 \
  93. t3 /003/ 7 leaf 2 690 316 346 \
  94. t3 /004/ 10 leaf 2 682 324 342 \
  95. t3 /005/ 11 leaf 2 690 316 346 \
  96. t3 /006/ 12 leaf 2 698 308 350 \
  97. t3 /007/ 13 leaf 2 706 300 354 \
  98. t3 /008/ 14 leaf 2 682 324 342 \
  99. t3 /009/ 16 leaf 2 690 316 346 \
  100. t3 /00a/ 17 leaf 2 698 308 350 \
  101. t3 /00b/ 18 leaf 2 706 300 354 \
  102. t3 /00c/ 19 leaf 2 714 292 358 \
  103. t3 /00d/ 21 leaf 2 722 284 362 \
  104. t3 /00e/ 22 leaf 2 730 276 366 \
  105. t3 /00f/ 23 leaf 2 738 268 370 \
  106. ]
  107. do_execsql_test stat-2.2 { DROP TABLE t3 } {}
  108. do_execsql_test stat-3.1 {
  109. CREATE TABLE t4(x);
  110. CREATE INDEX i4 ON t4(x);
  111. INSERT INTO t4(rowid, x) VALUES(2, a_string(7777));
  112. SELECT name, path, pageno, pagetype, ncell, payload, unused, mx_payload
  113. FROM stat WHERE name != 'sqlite_master';
  114. } [list \
  115. i4 / 3 leaf 1 103 905 7782 \
  116. i4 /000+000000 9 overflow 0 1020 0 0 \
  117. i4 /000+000001 10 overflow 0 1020 0 0 \
  118. i4 /000+000002 11 overflow 0 1020 0 0 \
  119. i4 /000+000003 12 overflow 0 1020 0 0 \
  120. i4 /000+000004 13 overflow 0 1020 0 0 \
  121. i4 /000+000005 14 overflow 0 1020 0 0 \
  122. i4 /000+000006 15 overflow 0 1020 0 0 \
  123. i4 /000+000007 16 overflow 0 539 481 0 \
  124. t4 / 2 leaf 1 640 367 7780 \
  125. t4 /000+000000 22 overflow 0 1020 0 0 \
  126. t4 /000+000001 23 overflow 0 1020 0 0 \
  127. t4 /000+000002 21 overflow 0 1020 0 0 \
  128. t4 /000+000003 20 overflow 0 1020 0 0 \
  129. t4 /000+000004 19 overflow 0 1020 0 0 \
  130. t4 /000+000005 18 overflow 0 1020 0 0 \
  131. t4 /000+000006 17 overflow 0 1020 0 0 \
  132. ]
  133. do_execsql_test stat-4.1 {
  134. CREATE TABLE t5(x);
  135. CREATE INDEX i5 ON t5(x);
  136. SELECT name, path, pageno, pagetype, ncell, payload, unused, mx_payload
  137. FROM stat WHERE name = 't5' OR name = 'i5';
  138. } [list \
  139. i5 / 5 leaf 0 0 1016 0 \
  140. t5 / 4 leaf 0 0 1016 0 \
  141. ]
  142. db close
  143. forcedelete test.db
  144. sqlite3 db test.db
  145. register_dbstat_vtab db
  146. breakpoint
  147. do_execsql_test stat-5.1 {
  148. PRAGMA auto_vacuum = OFF;
  149. CREATE VIRTUAL TABLE temp.stat USING dbstat;
  150. CREATE TABLE t1(x);
  151. INSERT INTO t1 VALUES(zeroblob(1513));
  152. INSERT INTO t1 VALUES(zeroblob(1514));
  153. SELECT name, path, pageno, pagetype, ncell, payload, unused, mx_payload
  154. FROM stat WHERE name = 't1';
  155. } [list \
  156. t1 / 2 leaf 2 993 5 1517 \
  157. t1 /000+000000 3 overflow 0 1020 0 0 \
  158. t1 /001+000000 4 overflow 0 1020 0 0 \
  159. ]
  160. finish_test