orderby3.test 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. # 2013 January 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 that the optimizations that disable
  13. # ORDER BY clauses work correctly on a 3-way join. See ticket
  14. # http://www.sqlite.org/src/956e4d7f89
  15. #
  16. set testdir [file dirname $argv0]
  17. source $testdir/tester.tcl
  18. set ::testprefix orderby3
  19. # Generate test data for a join. Verify that the join gets the
  20. # correct answer.
  21. #
  22. do_execsql_test 1.0 {
  23. CREATE TABLE t1(a INTEGER PRIMARY KEY);
  24. CREATE TABLE t2(b INTEGER PRIMARY KEY, c INTEGER);
  25. CREATE TABLE t3(d INTEGER);
  26. INSERT INTO t1 VALUES(1),(2),(3);
  27. INSERT INTO t2 VALUES(3, 1);
  28. INSERT INTO t2 VALUES(4, 2);
  29. INSERT INTO t2 VALUES(5, 3);
  30. INSERT INTO t3 VALUES(4),(3),(5);
  31. } {}
  32. do_execsql_test 1.1.asc {
  33. SELECT t1.a
  34. FROM t1, t2, t3
  35. WHERE t1.a=t2.c AND t2.b=t3.d
  36. ORDER BY t1.a;
  37. } {1 2 3}
  38. do_execsql_test 1.1.desc {
  39. SELECT t1.a
  40. FROM t1, t2, t3
  41. WHERE t1.a=t2.c AND t2.b=t3.d
  42. ORDER BY t1.a DESC;
  43. } {3 2 1}
  44. do_execsql_test 1.123.asc {
  45. SELECT t1.a
  46. FROM t1 CROSS JOIN t2 CROSS JOIN t3
  47. WHERE t1.a=t2.c AND t2.b=t3.d
  48. ORDER BY t1.a;
  49. } {1 2 3}
  50. do_execsql_test 1.123.desc {
  51. SELECT t1.a
  52. FROM t1 CROSS JOIN t2 CROSS JOIN t3
  53. WHERE t1.a=t2.c AND t2.b=t3.d
  54. ORDER BY t1.a DESC;
  55. } {3 2 1}
  56. do_execsql_test 1.132.asc {
  57. SELECT t1.a
  58. FROM t1 CROSS JOIN t3 CROSS JOIN t2
  59. WHERE t1.a=t2.c AND t2.b=t3.d
  60. ORDER BY t1.a;
  61. } {1 2 3}
  62. do_execsql_test 1.132.desc {
  63. SELECT t1.a
  64. FROM t1 CROSS JOIN t3 CROSS JOIN t2
  65. WHERE t1.a=t2.c AND t2.b=t3.d
  66. ORDER BY t1.a DESC;
  67. } {3 2 1}
  68. do_execsql_test 1.213.asc {
  69. SELECT t1.a
  70. FROM t2 CROSS JOIN t1 CROSS JOIN t3
  71. WHERE t1.a=t2.c AND t2.b=t3.d
  72. ORDER BY t1.a;
  73. } {1 2 3}
  74. do_execsql_test 1.213.desc {
  75. SELECT t1.a
  76. FROM t2 CROSS JOIN t1 CROSS JOIN t3
  77. WHERE t1.a=t2.c AND t2.b=t3.d
  78. ORDER BY t1.a DESC;
  79. } {3 2 1}
  80. do_execsql_test 1.231.asc {
  81. SELECT t1.a
  82. FROM t2 CROSS JOIN t3 CROSS JOIN t1
  83. WHERE t1.a=t2.c AND t2.b=t3.d
  84. ORDER BY t1.a;
  85. } {1 2 3}
  86. do_execsql_test 1.231.desc {
  87. SELECT t1.a
  88. FROM t2 CROSS JOIN t3 CROSS JOIN t1
  89. WHERE t1.a=t2.c AND t2.b=t3.d
  90. ORDER BY t1.a DESC;
  91. } {3 2 1}
  92. do_execsql_test 1.312.asc {
  93. SELECT t1.a
  94. FROM t3 CROSS JOIN t1 CROSS JOIN t2
  95. WHERE t1.a=t2.c AND t2.b=t3.d
  96. ORDER BY t1.a;
  97. } {1 2 3}
  98. do_execsql_test 1.312.desc {
  99. SELECT t1.a
  100. FROM t3 CROSS JOIN t1 CROSS JOIN t2
  101. WHERE t1.a=t2.c AND t2.b=t3.d
  102. ORDER BY t1.a DESC;
  103. } {3 2 1}
  104. do_execsql_test 1.321.asc {
  105. SELECT t1.a
  106. FROM t3 CROSS JOIN t2 CROSS JOIN t1
  107. WHERE t1.a=t2.c AND t2.b=t3.d
  108. ORDER BY t1.a;
  109. } {1 2 3}
  110. do_execsql_test 1.321.desc {
  111. SELECT t1.a
  112. FROM t3 CROSS JOIN t2 CROSS JOIN t1
  113. WHERE t1.a=t2.c AND t2.b=t3.d
  114. ORDER BY t1.a DESC;
  115. } {3 2 1}
  116. finish_test