| OLD | NEW |
| (Empty) |
| 1 # 2001 September 15. | |
| 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 # | |
| 12 # This file implements regression tests for SQLite library. The | |
| 13 # focus of this file is testing the sorter (code in vdbesort.c). | |
| 14 # | |
| 15 | |
| 16 set testdir [file dirname $argv0] | |
| 17 source $testdir/tester.tcl | |
| 18 set testprefix sort | |
| 19 | |
| 20 # Create a bunch of data to sort against | |
| 21 # | |
| 22 do_test sort-1.0 { | |
| 23 execsql { | |
| 24 CREATE TABLE t1( | |
| 25 n int, | |
| 26 v varchar(10), | |
| 27 log int, | |
| 28 roman varchar(10), | |
| 29 flt real | |
| 30 ); | |
| 31 INSERT INTO t1 VALUES(1,'one',0,'I',3.141592653); | |
| 32 INSERT INTO t1 VALUES(2,'two',1,'II',2.15); | |
| 33 INSERT INTO t1 VALUES(3,'three',1,'III',4221.0); | |
| 34 INSERT INTO t1 VALUES(4,'four',2,'IV',-0.0013442); | |
| 35 INSERT INTO t1 VALUES(5,'five',2,'V',-11); | |
| 36 INSERT INTO t1 VALUES(6,'six',2,'VI',0.123); | |
| 37 INSERT INTO t1 VALUES(7,'seven',2,'VII',123.0); | |
| 38 INSERT INTO t1 VALUES(8,'eight',3,'VIII',-1.6); | |
| 39 } | |
| 40 execsql {SELECT count(*) FROM t1} | |
| 41 } {8} | |
| 42 | |
| 43 do_test sort-1.1 { | |
| 44 execsql {SELECT n FROM t1 ORDER BY n} | |
| 45 } {1 2 3 4 5 6 7 8} | |
| 46 do_test sort-1.1.1 { | |
| 47 execsql {SELECT n FROM t1 ORDER BY n ASC} | |
| 48 } {1 2 3 4 5 6 7 8} | |
| 49 do_test sort-1.1.1 { | |
| 50 execsql {SELECT ALL n FROM t1 ORDER BY n ASC} | |
| 51 } {1 2 3 4 5 6 7 8} | |
| 52 do_test sort-1.2 { | |
| 53 execsql {SELECT n FROM t1 ORDER BY n DESC} | |
| 54 } {8 7 6 5 4 3 2 1} | |
| 55 do_test sort-1.3a { | |
| 56 execsql {SELECT v FROM t1 ORDER BY v} | |
| 57 } {eight five four one seven six three two} | |
| 58 do_test sort-1.3b { | |
| 59 execsql {SELECT n FROM t1 ORDER BY v} | |
| 60 } {8 5 4 1 7 6 3 2} | |
| 61 do_test sort-1.4 { | |
| 62 execsql {SELECT n FROM t1 ORDER BY v DESC} | |
| 63 } {2 3 6 7 1 4 5 8} | |
| 64 do_test sort-1.5 { | |
| 65 execsql {SELECT flt FROM t1 ORDER BY flt} | |
| 66 } {-11.0 -1.6 -0.0013442 0.123 2.15 3.141592653 123.0 4221.0} | |
| 67 do_test sort-1.6 { | |
| 68 execsql {SELECT flt FROM t1 ORDER BY flt DESC} | |
| 69 } {4221.0 123.0 3.141592653 2.15 0.123 -0.0013442 -1.6 -11.0} | |
| 70 do_test sort-1.7 { | |
| 71 execsql {SELECT roman FROM t1 ORDER BY roman} | |
| 72 } {I II III IV V VI VII VIII} | |
| 73 do_test sort-1.8 { | |
| 74 execsql {SELECT n FROM t1 ORDER BY log, flt} | |
| 75 } {1 2 3 5 4 6 7 8} | |
| 76 do_test sort-1.8.1 { | |
| 77 execsql {SELECT n FROM t1 ORDER BY log asc, flt} | |
| 78 } {1 2 3 5 4 6 7 8} | |
| 79 do_test sort-1.8.2 { | |
| 80 execsql {SELECT n FROM t1 ORDER BY log, flt ASC} | |
| 81 } {1 2 3 5 4 6 7 8} | |
| 82 do_test sort-1.8.3 { | |
| 83 execsql {SELECT n FROM t1 ORDER BY log ASC, flt asc} | |
| 84 } {1 2 3 5 4 6 7 8} | |
| 85 do_test sort-1.9 { | |
| 86 execsql {SELECT n FROM t1 ORDER BY log, flt DESC} | |
| 87 } {1 3 2 7 6 4 5 8} | |
| 88 do_test sort-1.9.1 { | |
| 89 execsql {SELECT n FROM t1 ORDER BY log ASC, flt DESC} | |
| 90 } {1 3 2 7 6 4 5 8} | |
| 91 do_test sort-1.10 { | |
| 92 execsql {SELECT n FROM t1 ORDER BY log DESC, flt} | |
| 93 } {8 5 4 6 7 2 3 1} | |
| 94 do_test sort-1.11 { | |
| 95 execsql {SELECT n FROM t1 ORDER BY log DESC, flt DESC} | |
| 96 } {8 7 6 4 5 3 2 1} | |
| 97 | |
| 98 # These tests are designed to reach some hard-to-reach places | |
| 99 # inside the string comparison routines. | |
| 100 # | |
| 101 # (Later) The sorting behavior changed in 2.7.0. But we will | |
| 102 # keep these tests. You can never have too many test cases! | |
| 103 # | |
| 104 do_test sort-2.1.1 { | |
| 105 execsql { | |
| 106 UPDATE t1 SET v='x' || -flt; | |
| 107 UPDATE t1 SET v='x-2b' where v=='x-0.123'; | |
| 108 SELECT v FROM t1 ORDER BY v; | |
| 109 } | |
| 110 } {x-123.0 x-2.15 x-2b x-3.141592653 x-4221.0 x0.0013442 x1.6 x11.0} | |
| 111 do_test sort-2.1.2 { | |
| 112 execsql { | |
| 113 SELECT v FROM t1 ORDER BY substr(v,2,999); | |
| 114 } | |
| 115 } {x-123.0 x-2.15 x-2b x-3.141592653 x-4221.0 x0.0013442 x1.6 x11.0} | |
| 116 do_test sort-2.1.3 { | |
| 117 execsql { | |
| 118 SELECT v FROM t1 ORDER BY substr(v,2,999)+0.0; | |
| 119 } | |
| 120 } {x-4221.0 x-123.0 x-3.141592653 x-2.15 x-2b x0.0013442 x1.6 x11.0} | |
| 121 do_test sort-2.1.4 { | |
| 122 execsql { | |
| 123 SELECT v FROM t1 ORDER BY substr(v,2,999) DESC; | |
| 124 } | |
| 125 } {x11.0 x1.6 x0.0013442 x-4221.0 x-3.141592653 x-2b x-2.15 x-123.0} | |
| 126 do_test sort-2.1.5 { | |
| 127 execsql { | |
| 128 SELECT v FROM t1 ORDER BY substr(v,2,999)+0.0 DESC; | |
| 129 } | |
| 130 } {x11.0 x1.6 x0.0013442 x-2b x-2.15 x-3.141592653 x-123.0 x-4221.0} | |
| 131 | |
| 132 # This is a bug fix for 2.2.4. | |
| 133 # Strings are normally mapped to upper-case for a caseless comparison. | |
| 134 # But this can cause problems for characters in between 'Z' and 'a'. | |
| 135 # | |
| 136 do_test sort-3.1 { | |
| 137 execsql { | |
| 138 CREATE TABLE t2(a,b); | |
| 139 INSERT INTO t2 VALUES('AGLIENTU',1); | |
| 140 INSERT INTO t2 VALUES('AGLIE`',2); | |
| 141 INSERT INTO t2 VALUES('AGNA',3); | |
| 142 SELECT a, b FROM t2 ORDER BY a; | |
| 143 } | |
| 144 } {AGLIENTU 1 AGLIE` 2 AGNA 3} | |
| 145 do_test sort-3.2 { | |
| 146 execsql { | |
| 147 SELECT a, b FROM t2 ORDER BY a DESC; | |
| 148 } | |
| 149 } {AGNA 3 AGLIE` 2 AGLIENTU 1} | |
| 150 do_test sort-3.3 { | |
| 151 execsql { | |
| 152 DELETE FROM t2; | |
| 153 INSERT INTO t2 VALUES('aglientu',1); | |
| 154 INSERT INTO t2 VALUES('aglie`',2); | |
| 155 INSERT INTO t2 VALUES('agna',3); | |
| 156 SELECT a, b FROM t2 ORDER BY a; | |
| 157 } | |
| 158 } {aglie` 2 aglientu 1 agna 3} | |
| 159 do_test sort-3.4 { | |
| 160 execsql { | |
| 161 SELECT a, b FROM t2 ORDER BY a DESC; | |
| 162 } | |
| 163 } {agna 3 aglientu 1 aglie` 2} | |
| 164 | |
| 165 # Version 2.7.0 testing. | |
| 166 # | |
| 167 do_test sort-4.1 { | |
| 168 execsql { | |
| 169 INSERT INTO t1 VALUES(9,'x2.7',3,'IX',4.0e5); | |
| 170 INSERT INTO t1 VALUES(10,'x5.0e10',3,'X',-4.0e5); | |
| 171 INSERT INTO t1 VALUES(11,'x-4.0e9',3,'XI',4.1e4); | |
| 172 INSERT INTO t1 VALUES(12,'x01234567890123456789',3,'XII',-4.2e3); | |
| 173 SELECT n FROM t1 ORDER BY n; | |
| 174 } | |
| 175 } {1 2 3 4 5 6 7 8 9 10 11 12} | |
| 176 do_test sort-4.2 { | |
| 177 execsql { | |
| 178 SELECT n||'' FROM t1 ORDER BY 1; | |
| 179 } | |
| 180 } {1 10 11 12 2 3 4 5 6 7 8 9} | |
| 181 do_test sort-4.3 { | |
| 182 execsql { | |
| 183 SELECT n+0 FROM t1 ORDER BY 1; | |
| 184 } | |
| 185 } {1 2 3 4 5 6 7 8 9 10 11 12} | |
| 186 do_test sort-4.4 { | |
| 187 execsql { | |
| 188 SELECT n||'' FROM t1 ORDER BY 1 DESC; | |
| 189 } | |
| 190 } {9 8 7 6 5 4 3 2 12 11 10 1} | |
| 191 do_test sort-4.5 { | |
| 192 execsql { | |
| 193 SELECT n+0 FROM t1 ORDER BY 1 DESC; | |
| 194 } | |
| 195 } {12 11 10 9 8 7 6 5 4 3 2 1} | |
| 196 do_test sort-4.6 { | |
| 197 execsql { | |
| 198 SELECT v FROM t1 ORDER BY 1; | |
| 199 } | |
| 200 } {x-123.0 x-2.15 x-2b x-3.141592653 x-4.0e9 x-4221.0 x0.0013442 x01234567890123
456789 x1.6 x11.0 x2.7 x5.0e10} | |
| 201 do_test sort-4.7 { | |
| 202 execsql { | |
| 203 SELECT v FROM t1 ORDER BY 1 DESC; | |
| 204 } | |
| 205 } {x5.0e10 x2.7 x11.0 x1.6 x01234567890123456789 x0.0013442 x-4221.0 x-4.0e9 x-3
.141592653 x-2b x-2.15 x-123.0} | |
| 206 do_test sort-4.8 { | |
| 207 execsql { | |
| 208 SELECT substr(v,2,99) FROM t1 ORDER BY 1; | |
| 209 } | |
| 210 } {-123.0 -2.15 -2b -3.141592653 -4.0e9 -4221.0 0.0013442 01234567890123456789 1
.6 11.0 2.7 5.0e10} | |
| 211 #do_test sort-4.9 { | |
| 212 # execsql { | |
| 213 # SELECT substr(v,2,99)+0.0 FROM t1 ORDER BY 1; | |
| 214 # } | |
| 215 #} {-4000000000 -4221 -123 -3.141592653 -2.15 -2 0.0013442 1.6 2.7 11 5000000000
0 1.23456789012346e+18} | |
| 216 | |
| 217 do_test sort-5.1 { | |
| 218 execsql { | |
| 219 create table t3(a,b); | |
| 220 insert into t3 values(5,NULL); | |
| 221 insert into t3 values(6,NULL); | |
| 222 insert into t3 values(3,NULL); | |
| 223 insert into t3 values(4,'cd'); | |
| 224 insert into t3 values(1,'ab'); | |
| 225 insert into t3 values(2,NULL); | |
| 226 select a from t3 order by b, a; | |
| 227 } | |
| 228 } {2 3 5 6 1 4} | |
| 229 do_test sort-5.2 { | |
| 230 execsql { | |
| 231 select a from t3 order by b, a desc; | |
| 232 } | |
| 233 } {6 5 3 2 1 4} | |
| 234 do_test sort-5.3 { | |
| 235 execsql { | |
| 236 select a from t3 order by b desc, a; | |
| 237 } | |
| 238 } {4 1 2 3 5 6} | |
| 239 do_test sort-5.4 { | |
| 240 execsql { | |
| 241 select a from t3 order by b desc, a desc; | |
| 242 } | |
| 243 } {4 1 6 5 3 2} | |
| 244 | |
| 245 do_test sort-6.1 { | |
| 246 execsql { | |
| 247 create index i3 on t3(b,a); | |
| 248 select a from t3 order by b, a; | |
| 249 } | |
| 250 } {2 3 5 6 1 4} | |
| 251 do_test sort-6.2 { | |
| 252 execsql { | |
| 253 select a from t3 order by b, a desc; | |
| 254 } | |
| 255 } {6 5 3 2 1 4} | |
| 256 do_test sort-6.3 { | |
| 257 execsql { | |
| 258 select a from t3 order by b desc, a; | |
| 259 } | |
| 260 } {4 1 2 3 5 6} | |
| 261 do_test sort-6.4 { | |
| 262 execsql { | |
| 263 select a from t3 order by b desc, a desc; | |
| 264 } | |
| 265 } {4 1 6 5 3 2} | |
| 266 | |
| 267 do_test sort-7.1 { | |
| 268 execsql { | |
| 269 CREATE TABLE t4( | |
| 270 a INTEGER, | |
| 271 b VARCHAR(30) | |
| 272 ); | |
| 273 INSERT INTO t4 VALUES(1,1); | |
| 274 INSERT INTO t4 VALUES(2,2); | |
| 275 INSERT INTO t4 VALUES(11,11); | |
| 276 INSERT INTO t4 VALUES(12,12); | |
| 277 SELECT a FROM t4 ORDER BY 1; | |
| 278 } | |
| 279 } {1 2 11 12} | |
| 280 do_test sort-7.2 { | |
| 281 execsql { | |
| 282 SELECT b FROM t4 ORDER BY 1 | |
| 283 } | |
| 284 } {1 11 12 2} | |
| 285 | |
| 286 # Omit tests sort-7.3 to sort-7.8 if view support was disabled at | |
| 287 # compilatation time. | |
| 288 ifcapable view { | |
| 289 do_test sort-7.3 { | |
| 290 execsql { | |
| 291 CREATE VIEW v4 AS SELECT * FROM t4; | |
| 292 SELECT a FROM v4 ORDER BY 1; | |
| 293 } | |
| 294 } {1 2 11 12} | |
| 295 do_test sort-7.4 { | |
| 296 execsql { | |
| 297 SELECT b FROM v4 ORDER BY 1; | |
| 298 } | |
| 299 } {1 11 12 2} | |
| 300 | |
| 301 ifcapable compound { | |
| 302 do_test sort-7.5 { | |
| 303 execsql { | |
| 304 SELECT a FROM t4 UNION SELECT a FROM v4 ORDER BY 1; | |
| 305 } | |
| 306 } {1 2 11 12} | |
| 307 do_test sort-7.6 { | |
| 308 execsql { | |
| 309 SELECT b FROM t4 UNION SELECT a FROM v4 ORDER BY 1; | |
| 310 } | |
| 311 } {1 2 11 12 1 11 12 2} ;# text from t4.b and numeric from v4.a | |
| 312 do_test sort-7.7 { | |
| 313 execsql { | |
| 314 SELECT a FROM t4 UNION SELECT b FROM v4 ORDER BY 1; | |
| 315 } | |
| 316 } {1 2 11 12 1 11 12 2} ;# numeric from t4.a and text from v4.b | |
| 317 do_test sort-7.8 { | |
| 318 execsql { | |
| 319 SELECT b FROM t4 UNION SELECT b FROM v4 ORDER BY 1; | |
| 320 } | |
| 321 } {1 11 12 2} | |
| 322 } ;# ifcapable compound | |
| 323 } ;# ifcapable view | |
| 324 | |
| 325 #### Version 3 works differently here: | |
| 326 #do_test sort-7.9 { | |
| 327 # execsql { | |
| 328 # SELECT b FROM t4 UNION SELECT b FROM v4 ORDER BY 1 COLLATE numeric; | |
| 329 # } | |
| 330 #} {1 2 11 12} | |
| 331 #do_test sort-7.10 { | |
| 332 # execsql { | |
| 333 # SELECT b FROM t4 UNION SELECT b FROM v4 ORDER BY 1 COLLATE integer; | |
| 334 # } | |
| 335 #} {1 2 11 12} | |
| 336 #do_test sort-7.11 { | |
| 337 # execsql { | |
| 338 # SELECT b FROM t4 UNION SELECT b FROM v4 ORDER BY 1 COLLATE text; | |
| 339 # } | |
| 340 #} {1 11 12 2} | |
| 341 #do_test sort-7.12 { | |
| 342 # execsql { | |
| 343 # SELECT b FROM t4 UNION SELECT b FROM v4 ORDER BY 1 COLLATE blob; | |
| 344 # } | |
| 345 #} {1 11 12 2} | |
| 346 #do_test sort-7.13 { | |
| 347 # execsql { | |
| 348 # SELECT b FROM t4 UNION SELECT b FROM v4 ORDER BY 1 COLLATE clob; | |
| 349 # } | |
| 350 #} {1 11 12 2} | |
| 351 #do_test sort-7.14 { | |
| 352 # execsql { | |
| 353 # SELECT b FROM t4 UNION SELECT b FROM v4 ORDER BY 1 COLLATE varchar; | |
| 354 # } | |
| 355 #} {1 11 12 2} | |
| 356 | |
| 357 # Ticket #297 | |
| 358 # | |
| 359 do_test sort-8.1 { | |
| 360 execsql { | |
| 361 CREATE TABLE t5(a real, b text); | |
| 362 INSERT INTO t5 VALUES(100,'A1'); | |
| 363 INSERT INTO t5 VALUES(100.0,'A2'); | |
| 364 SELECT * FROM t5 ORDER BY a, b; | |
| 365 } | |
| 366 } {100.0 A1 100.0 A2} | |
| 367 | |
| 368 | |
| 369 ifcapable {bloblit} { | |
| 370 # BLOBs should sort after TEXT | |
| 371 # | |
| 372 do_test sort-9.1 { | |
| 373 execsql { | |
| 374 CREATE TABLE t6(x, y); | |
| 375 INSERT INTO t6 VALUES(1,1); | |
| 376 INSERT INTO t6 VALUES(2,'1'); | |
| 377 INSERT INTO t6 VALUES(3,x'31'); | |
| 378 INSERT INTO t6 VALUES(4,NULL); | |
| 379 SELECT x FROM t6 ORDER BY y; | |
| 380 } | |
| 381 } {4 1 2 3} | |
| 382 do_test sort-9.2 { | |
| 383 execsql { | |
| 384 SELECT x FROM t6 ORDER BY y DESC; | |
| 385 } | |
| 386 } {3 2 1 4} | |
| 387 do_test sort-9.3 { | |
| 388 execsql { | |
| 389 SELECT x FROM t6 WHERE y<1 | |
| 390 } | |
| 391 } {} | |
| 392 do_test sort-9.4 { | |
| 393 execsql { | |
| 394 SELECT x FROM t6 WHERE y<'1' | |
| 395 } | |
| 396 } {1} | |
| 397 do_test sort-9.5 { | |
| 398 execsql { | |
| 399 SELECT x FROM t6 WHERE y<x'31' | |
| 400 } | |
| 401 } {1 2} | |
| 402 do_test sort-9.6 { | |
| 403 execsql { | |
| 404 SELECT x FROM t6 WHERE y>1 | |
| 405 } | |
| 406 } {2 3} | |
| 407 do_test sort-9.7 { | |
| 408 execsql { | |
| 409 SELECT x FROM t6 WHERE y>'1' | |
| 410 } | |
| 411 } {3} | |
| 412 } ;# endif bloblit | |
| 413 | |
| 414 # Ticket #1092 - ORDER BY on rowid fields. | |
| 415 do_test sort-10.1 { | |
| 416 execsql { | |
| 417 CREATE TABLE t7(c INTEGER PRIMARY KEY); | |
| 418 INSERT INTO t7 VALUES(1); | |
| 419 INSERT INTO t7 VALUES(2); | |
| 420 INSERT INTO t7 VALUES(3); | |
| 421 INSERT INTO t7 VALUES(4); | |
| 422 } | |
| 423 } {} | |
| 424 do_test sort-10.2 { | |
| 425 execsql { | |
| 426 SELECT c FROM t7 WHERE c<=3 ORDER BY c DESC; | |
| 427 } | |
| 428 } {3 2 1} | |
| 429 do_test sort-10.3 { | |
| 430 execsql { | |
| 431 SELECT c FROM t7 WHERE c<3 ORDER BY c DESC; | |
| 432 } | |
| 433 } {2 1} | |
| 434 | |
| 435 # ticket #1358. Just because one table in a join gives a unique | |
| 436 # result does not mean they all do. We cannot disable sorting unless | |
| 437 # all tables in the join give unique results. | |
| 438 # | |
| 439 do_test sort-11.1 { | |
| 440 execsql { | |
| 441 create table t8(a unique, b, c); | |
| 442 insert into t8 values(1,2,3); | |
| 443 insert into t8 values(2,3,4); | |
| 444 create table t9(x,y); | |
| 445 insert into t9 values(2,4); | |
| 446 insert into t9 values(2,3); | |
| 447 select y from t8, t9 where a=1 order by a, y; | |
| 448 } | |
| 449 } {3 4} | |
| 450 | |
| 451 # Trouble reported on the mailing list. Check for overly aggressive | |
| 452 # (which is to say, incorrect) optimization of order-by with a rowid | |
| 453 # in a join. | |
| 454 # | |
| 455 do_test sort-12.1 { | |
| 456 execsql { | |
| 457 create table a (id integer primary key); | |
| 458 create table b (id integer primary key, aId integer, text); | |
| 459 insert into a values (1); | |
| 460 insert into b values (2, 1, 'xxx'); | |
| 461 insert into b values (1, 1, 'zzz'); | |
| 462 insert into b values (3, 1, 'yyy'); | |
| 463 select a.id, b.id, b.text from a join b on (a.id = b.aId) | |
| 464 order by a.id, b.text; | |
| 465 } | |
| 466 } {1 2 xxx 1 3 yyy 1 1 zzz} | |
| 467 | |
| 468 #------------------------------------------------------------------------- | |
| 469 # Check that the sorter in vdbesort.c sorts in a stable fashion. | |
| 470 # | |
| 471 do_execsql_test sort-13.0 { | |
| 472 CREATE TABLE t10(a, b); | |
| 473 } | |
| 474 do_test sort-13.1 { | |
| 475 db transaction { | |
| 476 for {set i 0} {$i < 100000} {incr i} { | |
| 477 execsql { INSERT INTO t10 VALUES( $i/10, $i%10 ) } | |
| 478 } | |
| 479 } | |
| 480 } {} | |
| 481 do_execsql_test sort-13.2 { | |
| 482 SELECT a, b FROM t10 ORDER BY a; | |
| 483 } [db eval {SELECT a, b FROM t10 ORDER BY a, b}] | |
| 484 do_execsql_test sort-13.3 { | |
| 485 PRAGMA cache_size = 5; | |
| 486 SELECT a, b FROM t10 ORDER BY a; | |
| 487 } [db eval {SELECT a, b FROM t10 ORDER BY a, b}] | |
| 488 | |
| 489 #------------------------------------------------------------------------- | |
| 490 # Sort some large ( > 4KiB) records. | |
| 491 # | |
| 492 proc cksum {x} { | |
| 493 set i1 1 | |
| 494 set i2 2 | |
| 495 binary scan $x c* L | |
| 496 foreach {a b} $L { | |
| 497 set i1 [expr (($i2<<3) + $a) & 0x7FFFFFFF] | |
| 498 set i2 [expr (($i1<<3) + $b) & 0x7FFFFFFF] | |
| 499 } | |
| 500 list $i1 $i2 | |
| 501 } | |
| 502 db func cksum cksum | |
| 503 | |
| 504 do_execsql_test sort-14.0 { | |
| 505 PRAGMA cache_size = 5; | |
| 506 CREATE TABLE t11(a, b); | |
| 507 INSERT INTO t11 VALUES(randomblob(5000), NULL); | |
| 508 INSERT INTO t11 SELECT randomblob(5000), NULL FROM t11; --2 | |
| 509 INSERT INTO t11 SELECT randomblob(5000), NULL FROM t11; --3 | |
| 510 INSERT INTO t11 SELECT randomblob(5000), NULL FROM t11; --4 | |
| 511 INSERT INTO t11 SELECT randomblob(5000), NULL FROM t11; --5 | |
| 512 INSERT INTO t11 SELECT randomblob(5000), NULL FROM t11; --6 | |
| 513 INSERT INTO t11 SELECT randomblob(5000), NULL FROM t11; --7 | |
| 514 INSERT INTO t11 SELECT randomblob(5000), NULL FROM t11; --8 | |
| 515 INSERT INTO t11 SELECT randomblob(5000), NULL FROM t11; --9 | |
| 516 UPDATE t11 SET b = cksum(a); | |
| 517 } | |
| 518 | |
| 519 foreach {tn mmap_limit} { | |
| 520 1 0 | |
| 521 2 1000000 | |
| 522 } { | |
| 523 do_test sort-14.$tn { | |
| 524 sqlite3_test_control SQLITE_TESTCTRL_SORTER_MMAP db $mmap_limit | |
| 525 set prev "" | |
| 526 db eval { SELECT * FROM t11 ORDER BY b } { | |
| 527 if {$b != [cksum $a]} {error "checksum failed"} | |
| 528 if {[string compare $b $prev] < 0} {error "sort failed"} | |
| 529 set prev $b | |
| 530 } | |
| 531 set {} {} | |
| 532 } {} | |
| 533 } | |
| 534 | |
| 535 #------------------------------------------------------------------------- | |
| 536 # | |
| 537 foreach {tn mmap_limit nWorker tmpstore coremutex fakeheap softheaplimit} { | |
| 538 1 0 3 file true false 0 | |
| 539 2 0 3 file true true 0 | |
| 540 3 0 0 file true false 0 | |
| 541 4 1000000 3 file true false 0 | |
| 542 5 0 0 memory false true 0 | |
| 543 6 0 0 file false true 1000000 | |
| 544 7 0 0 file false true 10000 | |
| 545 } { | |
| 546 db close | |
| 547 sqlite3_shutdown | |
| 548 if {$coremutex} { | |
| 549 sqlite3_config multithread | |
| 550 } else { | |
| 551 sqlite3_config singlethread | |
| 552 } | |
| 553 sqlite3_initialize | |
| 554 sorter_test_fakeheap $fakeheap | |
| 555 sqlite3_soft_heap_limit $softheaplimit | |
| 556 | |
| 557 reset_db | |
| 558 sqlite3_test_control SQLITE_TESTCTRL_SORTER_MMAP db $mmap_limit | |
| 559 execsql "PRAGMA temp_store = $tmpstore; PRAGMA threads = $nWorker" | |
| 560 | |
| 561 | |
| 562 set ten [string repeat X 10300] | |
| 563 set one [string repeat y 200] | |
| 564 | |
| 565 if {$softheaplimit} { | |
| 566 execsql { PRAGMA cache_size = 20 }; | |
| 567 } else { | |
| 568 execsql { PRAGMA cache_size = 5 }; | |
| 569 } | |
| 570 | |
| 571 do_execsql_test 15.$tn.1 { | |
| 572 WITH rr AS ( | |
| 573 SELECT 4, $ten UNION ALL | |
| 574 SELECT 2, $one UNION ALL | |
| 575 SELECT 1, $ten UNION ALL | |
| 576 SELECT 3, $one | |
| 577 ) | |
| 578 SELECT * FROM rr ORDER BY 1; | |
| 579 } [list 1 $ten 2 $one 3 $one 4 $ten] | |
| 580 | |
| 581 do_execsql_test 15.$tn.2 { | |
| 582 CREATE TABLE t1(a); | |
| 583 INSERT INTO t1 VALUES(4); | |
| 584 INSERT INTO t1 VALUES(5); | |
| 585 INSERT INTO t1 VALUES(3); | |
| 586 INSERT INTO t1 VALUES(2); | |
| 587 INSERT INTO t1 VALUES(6); | |
| 588 INSERT INTO t1 VALUES(1); | |
| 589 CREATE INDEX i1 ON t1(a); | |
| 590 SELECT * FROM t1 ORDER BY a; | |
| 591 } {1 2 3 4 5 6} | |
| 592 | |
| 593 do_execsql_test 15.$tn.3 { | |
| 594 WITH rr AS ( | |
| 595 SELECT 4, $ten UNION ALL | |
| 596 SELECT 2, $one | |
| 597 ) | |
| 598 SELECT * FROM rr ORDER BY 1; | |
| 599 } [list 2 $one 4 $ten] | |
| 600 | |
| 601 sorter_test_fakeheap 0 | |
| 602 } | |
| 603 | |
| 604 db close | |
| 605 sqlite3_shutdown | |
| 606 set t(0) singlethread | |
| 607 set t(1) multithread | |
| 608 set t(2) serialized | |
| 609 sqlite3_config $t($sqlite_options(threadsafe)) | |
| 610 sqlite3_initialize | |
| 611 sqlite3_soft_heap_limit 0 | |
| 612 | |
| 613 reset_db | |
| 614 do_catchsql_test 16.1 { | |
| 615 CREATE TABLE t1(a, b, c); | |
| 616 INSERT INTO t1 VALUES(1, 2, 3); | |
| 617 INSERT INTO t1 VALUES(1, NULL, 3); | |
| 618 INSERT INTO t1 VALUES(NULL, 2, 3); | |
| 619 INSERT INTO t1 VALUES(1, 2, NULL); | |
| 620 INSERT INTO t1 VALUES(4, 5, 6); | |
| 621 CREATE UNIQUE INDEX i1 ON t1(b, a, c); | |
| 622 } {0 {}} | |
| 623 reset_db | |
| 624 do_catchsql_test 16.2 { | |
| 625 CREATE TABLE t1(a, b, c); | |
| 626 INSERT INTO t1 VALUES(1, 2, 3); | |
| 627 INSERT INTO t1 VALUES(1, NULL, 3); | |
| 628 INSERT INTO t1 VALUES(1, 2, 3); | |
| 629 INSERT INTO t1 VALUES(1, 2, NULL); | |
| 630 INSERT INTO t1 VALUES(4, 5, 6); | |
| 631 CREATE UNIQUE INDEX i1 ON t1(b, a, c); | |
| 632 } {1 {UNIQUE constraint failed: t1.b, t1.a, t1.c}} | |
| 633 | |
| 634 reset_db | |
| 635 do_execsql_test 17.1 { | |
| 636 SELECT * FROM sqlite_master ORDER BY sql; | |
| 637 } {} | |
| 638 | |
| 639 finish_test | |
| OLD | NEW |