/ Check-in [3a13e943]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add start of new test file "select9.test". To test LIMIT, OFFSET and ORDER BY on compound SELECT statements. (CVS 5293)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 3a13e943d8fb4060fc1f0f827a156a730ee64be0
User & Date: danielk1977 2008-06-24 11:21:21
Context
2008-06-24
12:28
Remove a surplus "breakpoint" from select4.test. (CVS 5294) check-in: 3117238c user: drh tags: trunk
11:21
Add start of new test file "select9.test". To test LIMIT, OFFSET and ORDER BY on compound SELECT statements. (CVS 5293) check-in: 3a13e943 user: danielk1977 tags: trunk
09:52
Fix a typo in the documentation for the sqlite3_bind_XXX() APIs. (CVS 5292) check-in: 839457f1 user: danielk1977 tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to test/quick.test.

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
..
64
65
66
67
68
69
70

71
72
73
74
75
76
77
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file runs all tests.
#
# $Id: quick.test,v 1.81 2008/06/21 18:07:37 danielk1977 Exp $

proc lshift {lvar} {
  upvar $lvar l
  set ret [lindex $l 0]
  set l [lrange $l 1 end]
  return $ret
}
................................................................................
  memleak.test
  misc7.test
  misuse.test
  mutex2.test
  onefile.test
  permutations.test
  quick.test

  soak.test
  speed1.test
  speed1p.test
  speed2.test
  speed3.test
  speed4.test
  speed4p.test







|







 







>







2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
..
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file runs all tests.
#
# $Id: quick.test,v 1.82 2008/06/24 11:21:21 danielk1977 Exp $

proc lshift {lvar} {
  upvar $lvar l
  set ret [lindex $l 0]
  set l [lrange $l 1 end]
  return $ret
}
................................................................................
  memleak.test
  misc7.test
  misuse.test
  mutex2.test
  onefile.test
  permutations.test
  quick.test
  select9.test
  soak.test
  speed1.test
  speed1p.test
  speed2.test
  speed3.test
  speed4.test
  speed4p.test

Added test/select9.test.





























































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# 2008 June 24
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library. 
#
# $Id: select9.test,v 1.1 2008/06/24 11:21:21 danielk1977 Exp $

# The tests in this file are focused on test compound SELECT statements 
# that have any or all of an ORDER BY, LIMIT or OFFSET clauses. As of
# version 3.6.0, SQLite contains code to use SQL indexes where possible 
# to optimize such statements.
#

# TODO Points:
#
#   * Are there any "column affinity" issues to consider?

set testdir [file dirname $argv0]
source $testdir/tester.tcl

#-------------------------------------------------------------------------
# test_compound_select TESTNAME SELECT RESULT
#
#   This command is used to run multiple LIMIT/OFFSET test cases based on 
#   the single SELECT statement passed as the second argument. The SELECT
#   statement may not contain a LIMIT or OFFSET clause. This proc tests
#   many statements of the form:
#    
#     "$SELECT limit $X offset $Y"
#    
#   for various values of $X and $Y.
#    
#   The third argument, $RESULT, should contain the expected result of
#   the command [execsql $SELECT].
#    
#   The first argument, $TESTNAME, is used as the base test case name to
#   pass to [do_test] for each individual LIMIT OFFSET test case.
# 
proc test_compound_select {testname sql result} {

  set nCol 1
  db eval $sql A {
    set nCol [llength $A(*)]
    break
  }
  set nRow [expr {[llength $result] / $nCol}]

  set ::compound_sql $sql
  do_test $testname { 
    execsql $::compound_sql
  } $result
#return

  set iLimitIncr  1
  set iLimitEnd   [expr $nRow+1]

  set iOffsetIncr 1
  set iOffsetEnd  $nRow

  for {set iOffset 0} {$iOffset <= $iOffsetEnd} {incr iOffset $iOffsetIncr} {
    for {set iLimit 0} {$iLimit <= ($nRow+1)} {incr iLimit} {
  
      set ::compound_sql "$sql LIMIT $iLimit"
      if {$iOffset != 0} {
        append ::compound_sql " OFFSET $iOffset"
      }
  
      set iStart [expr {$iOffset*$nCol}]
      set iEnd [expr {($iOffset*$nCol) + ($iLimit*$nCol) -1}]
  
      do_test $testname.limit=$iLimit.offset=$iOffset { 
        execsql $::compound_sql
      } [lrange $result $iStart $iEnd]
    }
  }
}

#-------------------------------------------------------------------------
# test_compound_select_flippable TESTNAME SELECT RESULT
#
#   This command is for testing statements of the form:
#
#     <simple select 1> <compound op> <simple select 2> ORDER BY <order by>
#
#   where each <simple select> is a simple (non-compound) select statement
#   and <compound op> is one of "INTERSECT", "UNION ALL" or "UNION".
#
#   This proc calls [test_compound_select] twice, once with the select
#   statement as it is passed to this command, and once with the positions
#   of <select statement 1> and <select statement 2> exchanged.
#
proc test_compound_select_flippable {testname sql result} {
  test_compound_select $testname $sql $result

  set select [string trim $sql]
  set RE {(.*)(UNION ALL|INTERSECT|UNION)(.*)(ORDER BY.*)}
  set rc [regexp $RE $select -> s1 op s2 order_by]
  if {!$rc} {error "Statement is unflippable: $select"}

  set flipsql "$s2 $op $s1 $order_by"
  test_compound_select $testname.flipped $flipsql $result
}

#############################################################################
# Begin tests.
#

# Create and populate a sample database.
#
do_test select9-1.0 {
  execsql {
    CREATE TABLE t1(a, b, c);
    CREATE TABLE t2(d, e, f);
    BEGIN;
      INSERT INTO t1 VALUES(1,  'one',   'I');
      INSERT INTO t1 VALUES(3,  NULL,    NULL);
      INSERT INTO t1 VALUES(5,  'five',  'V');
      INSERT INTO t1 VALUES(7,  'seven', 'VII');
      INSERT INTO t1 VALUES(9,  NULL,    NULL);
      INSERT INTO t1 VALUES(2,  'two',   'II');
      INSERT INTO t1 VALUES(4,  'four',  'IV');
      INSERT INTO t1 VALUES(6,  NULL,    NULL);
      INSERT INTO t1 VALUES(8,  'eight', 'VIII');
      INSERT INTO t1 VALUES(10, 'ten',   'X');

      INSERT INTO t2 VALUES(1,  'two',      'IV');
      INSERT INTO t2 VALUES(2,  'four',     'VIII');
      INSERT INTO t2 VALUES(3,  NULL,       NULL);
      INSERT INTO t2 VALUES(4,  'eight',    'XVI');
      INSERT INTO t2 VALUES(5,  'ten',      'XX');
      INSERT INTO t2 VALUES(6,  NULL,       NULL);
      INSERT INTO t2 VALUES(7,  'fourteen', 'XXVIII');
      INSERT INTO t2 VALUES(8,  'sixteen',  'XXXII');
      INSERT INTO t2 VALUES(9,  NULL,       NULL);
      INSERT INTO t2 VALUES(10, 'twenty',   'XL');

    COMMIT;
  }
} {}

# Each iteration of this loop runs the same tests with a different set
# of indexes present within the database schema. The data returned by
# the compound SELECT statements in the test cases should be the same 
# in each case.
#
set iOuterLoop 1
foreach indexes [list {
  /* Do not create any indexes. */
} {
  CREATE INDEX i1 ON t1(a)
} {
  CREATE INDEX i2 ON t1(b)
} {
  CREATE INDEX i3 ON t2(d)
} {
  CREATE INDEX i4 ON t2(e)
}] {

  do_test select9-1.$iOuterLoop.1 {
    execsql $indexes
  } {}

  # Test some 2-way UNION ALL queries. No WHERE clauses.
  #
  test_compound_select select9-1.$iOuterLoop.2 {
    SELECT a, b FROM t1 UNION ALL SELECT d, e FROM t2 
  } {1 one 3 {} 5 five 7 seven 9 {} 2 two 4 four 6 {} 8 eight 10 ten 1 two 2 four 3 {} 4 eight 5 ten 6 {} 7 fourteen 8 sixteen 9 {} 10 twenty}
  test_compound_select select9-1.$iOuterLoop.3 {
    SELECT a, b FROM t1 UNION ALL SELECT d, e FROM t2 ORDER BY 1 
  } {1 one 1 two 2 two 2 four 3 {} 3 {} 4 four 4 eight 5 five 5 ten 6 {} 6 {} 7 seven 7 fourteen 8 eight 8 sixteen 9 {} 9 {} 10 ten 10 twenty}
  test_compound_select select9-1.$iOuterLoop.4 {
    SELECT a, b FROM t1 UNION ALL SELECT d, e FROM t2 ORDER BY 2 
  } {3 {} 9 {} 6 {} 3 {} 6 {} 9 {} 8 eight 4 eight 5 five 4 four 2 four 7 fourteen 1 one 7 seven 8 sixteen 10 ten 5 ten 10 twenty 2 two 1 two}
  test_compound_select_flippable select9-1.$iOuterLoop.5 {
    SELECT a, b FROM t1 UNION ALL SELECT d, e FROM t2 ORDER BY 1, 2
  } {1 one 1 two 2 four 2 two 3 {} 3 {} 4 eight 4 four 5 five 5 ten 6 {} 6 {} 7 fourteen 7 seven 8 eight 8 sixteen 9 {} 9 {} 10 ten 10 twenty}
  test_compound_select_flippable select9-1.$iOuterLoop.6 {
    SELECT a, b FROM t1 UNION ALL SELECT d, e FROM t2 ORDER BY 2, 1
  } {3 {} 3 {} 6 {} 6 {} 9 {} 9 {} 4 eight 8 eight 5 five 2 four 4 four 7 fourteen 1 one 7 seven 8 sixteen 5 ten 10 ten 10 twenty 1 two 2 two}

  # Test some 2-way UNION queries.
  #
  test_compound_select select9-1.$iOuterLoop.7 {
    SELECT a, b FROM t1 UNION SELECT d, e FROM t2 
  } {1 one 1 two 2 four 2 two 3 {} 4 eight 4 four 5 five 5 ten 6 {} 7 fourteen 7 seven 8 eight 8 sixteen 9 {} 10 ten 10 twenty}

  test_compound_select select9-1.$iOuterLoop.8 {
    SELECT a, b FROM t1 UNION SELECT d, e FROM t2 ORDER BY 1 
  } {1 one 1 two 2 four 2 two 3 {} 4 eight 4 four 5 five 5 ten 6 {} 7 fourteen 7 seven 8 eight 8 sixteen 9 {} 10 ten 10 twenty}

  test_compound_select select9-1.$iOuterLoop.9 {
    SELECT a, b FROM t1 UNION SELECT d, e FROM t2 ORDER BY 2 
  } {3 {} 6 {} 9 {} 4 eight 8 eight 5 five 2 four 4 four 7 fourteen 1 one 7 seven 8 sixteen 5 ten 10 ten 10 twenty 1 two 2 two}

  test_compound_select_flippable select9-1.$iOuterLoop.10 {
    SELECT a, b FROM t1 UNION SELECT d, e FROM t2 ORDER BY 1, 2
  } {1 one 1 two 2 four 2 two 3 {} 4 eight 4 four 5 five 5 ten 6 {} 7 fourteen 7 seven 8 eight 8 sixteen 9 {} 10 ten 10 twenty}

  test_compound_select_flippable select9-1.$iOuterLoop.11 {
    SELECT a, b FROM t1 UNION SELECT d, e FROM t2 ORDER BY 2, 1
  } {3 {} 6 {} 9 {} 4 eight 8 eight 5 five 2 four 4 four 7 fourteen 1 one 7 seven 8 sixteen 5 ten 10 ten 10 twenty 1 two 2 two}

  # Test some 2-way INTERSECT queries.
  #
  test_compound_select select9-1.$iOuterLoop.11 {
    SELECT a, b FROM t1 INTERSECT SELECT d, e FROM t2 
  } {3 {} 6 {} 9 {}}
  test_compound_select_flippable select9-1.$iOuterLoop.12 {
    SELECT a, b FROM t1 INTERSECT SELECT d, e FROM t2 ORDER BY 1
  } {3 {} 6 {} 9 {}}
  test_compound_select select9-1.$iOuterLoop.13 {
    SELECT a, b FROM t1 INTERSECT SELECT d, e FROM t2 ORDER BY 2
  } {3 {} 6 {} 9 {}}
  test_compound_select_flippable select9-1.$iOuterLoop.14 {
    SELECT a, b FROM t1 INTERSECT SELECT d, e FROM t2 ORDER BY 2, 1
  } {3 {} 6 {} 9 {}}
  test_compound_select_flippable select9-1.$iOuterLoop.15 {
    SELECT a, b FROM t1 INTERSECT SELECT d, e FROM t2 ORDER BY 1, 2
  } {3 {} 6 {} 9 {}}

  # Test some 2-way EXCEPT queries.
  #
  test_compound_select select9-1.$iOuterLoop.16 {
    SELECT a, b FROM t1 EXCEPT SELECT d, e FROM t2 
  } {1 one 2 two 4 four 5 five 7 seven 8 eight 10 ten}

  test_compound_select select9-1.$iOuterLoop.17 {
    SELECT a, b FROM t1 EXCEPT SELECT d, e FROM t2 ORDER BY 1 
  } {1 one 2 two 4 four 5 five 7 seven 8 eight 10 ten}

  test_compound_select select9-1.$iOuterLoop.18 {
    SELECT a, b FROM t1 EXCEPT SELECT d, e FROM t2 ORDER BY 2 
  } {8 eight 5 five 4 four 1 one 7 seven 10 ten 2 two}

  test_compound_select select9-1.$iOuterLoop.19 {
    SELECT a, b FROM t1 EXCEPT SELECT d, e FROM t2 ORDER BY 1, 2
  } {1 one 2 two 4 four 5 five 7 seven 8 eight 10 ten}

  test_compound_select select9-1.$iOuterLoop.20 {
    SELECT a, b FROM t1 EXCEPT SELECT d, e FROM t2 ORDER BY 2, 1
  } {8 eight 5 five 4 four 1 one 7 seven 10 ten 2 two}

  incr iOuterLoop
}

finish_test

Changes to test/veryquick.test.

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
..
86
87
88
89
90
91
92

93
94
95
96
97
98
99
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file runs all tests.
#
# $Id: veryquick.test,v 1.6 2008/06/21 19:20:13 danielk1977 Exp $

proc lshift {lvar} {
  upvar $lvar l
  set ret [lindex $l 0]
  set l [lrange $l 1 end]
  return $ret
}
................................................................................
  memleak.test
  misc7.test
  misuse.test
  mutex2.test
  onefile.test
  permutations.test
  quick.test

  soak.test
  speed1.test
  speed1p.test
  speed2.test
  speed3.test
  speed4.test
  speed4p.test







|







 







>







2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
..
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file runs all tests.
#
# $Id: veryquick.test,v 1.7 2008/06/24 11:21:21 danielk1977 Exp $

proc lshift {lvar} {
  upvar $lvar l
  set ret [lindex $l 0]
  set l [lrange $l 1 end]
  return $ret
}
................................................................................
  memleak.test
  misc7.test
  misuse.test
  mutex2.test
  onefile.test
  permutations.test
  quick.test
  select9.test
  soak.test
  speed1.test
  speed1p.test
  speed2.test
  speed3.test
  speed4.test
  speed4p.test