tkt-4dd95f6943.test 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. # 2013 March 13
  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.
  12. #
  13. set testdir [file dirname $argv0]
  14. source $testdir/tester.tcl
  15. set ::testprefix tkt-4dd95f6943
  16. do_execsql_test 1.0 {
  17. CREATE TABLE t1(x);
  18. INSERT INTO t1 VALUES (3), (4), (2), (1), (5), (6);
  19. }
  20. foreach {tn1 idx} {
  21. 1 { CREATE INDEX i1 ON t1(x ASC) }
  22. 2 { CREATE INDEX i1 ON t1(x DESC) }
  23. } {
  24. do_execsql_test 1.$tn1.1 { DROP INDEX IF EXISTS i1; }
  25. do_execsql_test 1.$tn1.2 $idx
  26. do_execsql_test 1.$tn1.3 {
  27. SELECT x FROM t1 WHERE x IN(2, 4, 5) ORDER BY x ASC;
  28. } {2 4 5}
  29. do_execsql_test 1.$tn1.4 {
  30. SELECT x FROM t1 WHERE x IN(2, 4, 5) ORDER BY x DESC;
  31. } {5 4 2}
  32. }
  33. do_execsql_test 2.0 {
  34. CREATE TABLE t2(x, y);
  35. INSERT INTO t2 VALUES (5, 3), (5, 4), (5, 2), (5, 1), (5, 5), (5, 6);
  36. INSERT INTO t2 VALUES (1, 3), (1, 4), (1, 2), (1, 1), (1, 5), (1, 6);
  37. INSERT INTO t2 VALUES (3, 3), (3, 4), (3, 2), (3, 1), (3, 5), (3, 6);
  38. INSERT INTO t2 VALUES (2, 3), (2, 4), (2, 2), (2, 1), (2, 5), (2, 6);
  39. INSERT INTO t2 VALUES (4, 3), (4, 4), (4, 2), (4, 1), (4, 5), (4, 6);
  40. INSERT INTO t2 VALUES (6, 3), (6, 4), (6, 2), (6, 1), (6, 5), (6, 6);
  41. CREATE TABLE t3(a, b);
  42. INSERT INTO t3 VALUES (2, 2), (4, 4), (5, 5);
  43. CREATE UNIQUE INDEX t3i1 ON t3(a ASC);
  44. CREATE UNIQUE INDEX t3i2 ON t3(b DESC);
  45. }
  46. foreach {tn1 idx} {
  47. 1 { CREATE INDEX i1 ON t2(x ASC, y ASC) }
  48. 2 { CREATE INDEX i1 ON t2(x ASC, y DESC) }
  49. 3 { CREATE INDEX i1 ON t2(x DESC, y ASC) }
  50. 4 { CREATE INDEX i1 ON t2(x DESC, y DESC) }
  51. 5 { CREATE INDEX i1 ON t2(y ASC, x ASC) }
  52. 6 { CREATE INDEX i1 ON t2(y ASC, x DESC) }
  53. 7 { CREATE INDEX i1 ON t2(y DESC, x ASC) }
  54. 8 { CREATE INDEX i1 ON t2(y DESC, x DESC) }
  55. } {
  56. do_execsql_test 2.$tn1.1 { DROP INDEX IF EXISTS i1; }
  57. do_execsql_test 2.$tn1.2 $idx
  58. foreach {tn2 inexpr} {
  59. 3 "(2, 4, 5)"
  60. 4 "(SELECT a FROM t3)"
  61. 5 "(SELECT b FROM t3)"
  62. } {
  63. do_execsql_test 2.$tn1.$tn2.1 "
  64. SELECT x, y FROM t2 WHERE x = 1 AND y IN $inexpr ORDER BY x ASC, y ASC;
  65. " {1 2 1 4 1 5}
  66. do_execsql_test 2.$tn1.$tn2.2 "
  67. SELECT x, y FROM t2 WHERE x = 2 AND y IN $inexpr ORDER BY x ASC, y DESC;
  68. " {2 5 2 4 2 2}
  69. do_execsql_test 2.$tn1.$tn2.3 "
  70. SELECT x, y FROM t2 WHERE x = 3 AND y IN $inexpr ORDER BY x DESC, y ASC;
  71. " {3 2 3 4 3 5}
  72. do_execsql_test 2.$tn1.$tn2.4 "
  73. SELECT x, y FROM t2 WHERE x = 4 AND y IN $inexpr ORDER BY x DESC, y DESC;
  74. " {4 5 4 4 4 2}
  75. do_execsql_test 2.$tn1.$tn2.5 "
  76. SELECT a, x, y FROM t2, t3 WHERE a = 4 AND x = 1 AND y IN $inexpr
  77. ORDER BY a, x ASC, y ASC;
  78. " {4 1 2 4 1 4 4 1 5}
  79. do_execsql_test 2.$tn1.$tn2.6 "
  80. SELECT a, x, y FROM t2, t3 WHERE a = 2 AND x = 1 AND y IN $inexpr
  81. ORDER BY x ASC, y ASC;
  82. " {2 1 2 2 1 4 2 1 5}
  83. do_execsql_test 2.$tn1.$tn2.7 "
  84. SELECT a, x, y FROM t2, t3 WHERE a = 4 AND x = 1 AND y IN $inexpr
  85. ORDER BY a, x ASC, y DESC;
  86. " {4 1 5 4 1 4 4 1 2}
  87. do_execsql_test 2.$tn1.8 "
  88. SELECT a, x, y FROM t2, t3 WHERE a = 2 AND x = 1 AND y IN $inexpr
  89. ORDER BY x ASC, y DESC;
  90. " {2 1 5 2 1 4 2 1 2}
  91. do_execsql_test 2.$tn1.$tn2.9 "
  92. SELECT a, x, y FROM t2, t3 WHERE a = 4 AND x = 1 AND y IN $inexpr
  93. ORDER BY a, x DESC, y ASC;
  94. " {4 1 2 4 1 4 4 1 5}
  95. do_execsql_test 2.$tn1.10 "
  96. SELECT a, x, y FROM t2, t3 WHERE a = 2 AND x = 1 AND y IN $inexpr
  97. ORDER BY x DESC, y ASC;
  98. " {2 1 2 2 1 4 2 1 5}
  99. do_execsql_test 2.$tn1.$tn2.11 "
  100. SELECT a, x, y FROM t2, t3 WHERE a = 4 AND x = 1 AND y IN $inexpr
  101. ORDER BY a, x DESC, y DESC;
  102. " {4 1 5 4 1 4 4 1 2}
  103. do_execsql_test 2.$tn1.$tn2.12 "
  104. SELECT a, x, y FROM t2, t3 WHERE a = 2 AND x = 1 AND y IN $inexpr
  105. ORDER BY x DESC, y DESC;
  106. " {2 1 5 2 1 4 2 1 2}
  107. }
  108. }
  109. do_execsql_test 3.0 {
  110. CREATE TABLE t7(x);
  111. INSERT INTO t7 VALUES (1), (2), (3);
  112. CREATE INDEX i7 ON t7(x);
  113. CREATE TABLE t8(y);
  114. INSERT INTO t8 VALUES (1), (2), (3);
  115. }
  116. foreach {tn idxdir sortdir sortdata} {
  117. 1 ASC ASC {1 2 3}
  118. 2 ASC DESC {3 2 1}
  119. 3 DESC ASC {1 2 3}
  120. 4 ASC DESC {3 2 1}
  121. } {
  122. do_execsql_test 3.$tn "
  123. DROP INDEX IF EXISTS i8;
  124. CREATE UNIQUE INDEX i8 ON t8(y $idxdir);
  125. SELECT x FROM t7 WHERE x IN (SELECT y FROM t8) ORDER BY x $sortdir;
  126. " $sortdata
  127. }
  128. finish_test