0000: 23 20 32 30 31 35 2d 30 38 2d 33 31 0a 23 0a 23 # 2015-08-31.#.#
0010: 20 54 68 65 20 61 75 74 68 6f 72 20 64 69 73 63 The author disc
0020: 6c 61 69 6d 73 20 63 6f 70 79 72 69 67 68 74 20 laims copyright
0030: 74 6f 20 74 68 69 73 20 73 6f 75 72 63 65 20 63 to this source c
0040: 6f 64 65 2e 20 20 49 6e 20 70 6c 61 63 65 20 6f ode. In place o
0050: 66 0a 23 20 61 20 6c 65 67 61 6c 20 6e 6f 74 69 f.# a legal noti
0060: 63 65 2c 20 68 65 72 65 20 69 73 20 61 20 62 6c ce, here is a bl
0070: 65 73 73 69 6e 67 3a 0a 23 0a 23 20 20 20 20 4d essing:.#.# M
0080: 61 79 20 79 6f 75 20 64 6f 20 67 6f 6f 64 20 61 ay you do good a
0090: 6e 64 20 6e 6f 74 20 65 76 69 6c 2e 0a 23 20 20 nd not evil..#
00a0: 20 20 4d 61 79 20 79 6f 75 20 66 69 6e 64 20 66 May you find f
00b0: 6f 72 67 69 76 65 6e 65 73 73 20 66 6f 72 20 79 orgiveness for y
00c0: 6f 75 72 73 65 6c 66 20 61 6e 64 20 66 6f 72 67 ourself and forg
00d0: 69 76 65 20 6f 74 68 65 72 73 2e 0a 23 20 20 20 ive others..#
00e0: 20 4d 61 79 20 79 6f 75 20 73 68 61 72 65 20 66 May you share f
00f0: 72 65 65 6c 79 2c 20 6e 65 76 65 72 20 74 61 6b reely, never tak
0100: 69 6e 67 20 6d 6f 72 65 20 74 68 61 6e 20 79 6f ing more than yo
0110: 75 20 67 69 76 65 2e 0a 23 0a 23 2a 2a 2a 2a 2a u give..#.#*****
0120: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0130: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0140: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0150: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0160: 2a 2a 0a 23 20 54 68 69 73 20 66 69 6c 65 20 69 **.# This file i
0170: 6d 70 6c 65 6d 65 6e 74 73 20 72 65 67 72 65 73 mplements regres
0180: 73 69 6f 6e 20 74 65 73 74 73 20 66 6f 72 20 53 sion tests for S
0190: 51 4c 69 74 65 20 6c 69 62 72 61 72 79 2e 20 20 QLite library.
01a0: 54 68 65 0a 23 20 66 6f 63 75 73 20 6f 66 20 74 The.# focus of t
01b0: 68 69 73 20 66 69 6c 65 20 69 73 20 74 65 73 74 his file is test
01c0: 69 6e 67 20 69 6e 64 65 78 65 73 20 6f 6e 20 65 ing indexes on e
01d0: 78 70 72 65 73 73 69 6f 6e 73 2e 0a 23 0a 0a 73 xpressions..#..s
01e0: 65 74 20 74 65 73 74 64 69 72 20 5b 66 69 6c 65 et testdir [file
01f0: 20 64 69 72 6e 61 6d 65 20 24 61 72 67 76 30 5d dirname $argv0]
0200: 0a 73 6f 75 72 63 65 20 24 74 65 73 74 64 69 72 .source $testdir
0210: 2f 74 65 73 74 65 72 2e 74 63 6c 0a 0a 64 6f 5f /tester.tcl..do_
0220: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 69 6e 64 execsql_test ind
0230: 65 78 65 78 70 72 31 2d 31 30 30 20 7b 0a 20 20 exexpr1-100 {.
0240: 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 31 28 CREATE TABLE t1(
0250: 61 2c 62 2c 63 29 3b 0a 20 20 49 4e 53 45 52 54 a,b,c);. INSERT
0260: 20 49 4e 54 4f 20 74 31 28 61 2c 62 2c 63 29 0a INTO t1(a,b,c).
0270: 20 20 20 20 20 20 2f 2a 20 20 31 32 33 34 35 36 /* 123456
0280: 37 38 39 20 31 32 33 34 35 36 37 38 39 20 31 32 789 123456789 12
0290: 33 34 35 36 37 38 39 20 31 32 33 34 35 36 37 38 3456789 12345678
02a0: 39 20 31 32 33 34 35 36 37 38 39 20 31 32 33 34 9 123456789 1234
02b0: 35 36 37 38 39 20 2a 2f 20 0a 20 20 56 41 4c 55 56789 */ . VALU
02c0: 45 53 28 27 49 6e 5f 74 68 65 5f 62 65 67 69 6e ES('In_the_begin
02d0: 6e 69 6e 67 5f 77 61 73 5f 74 68 65 5f 57 6f 72 ning_was_the_Wor
02e0: 64 27 2c 31 2c 31 29 2c 0a 20 20 20 20 20 20 20 d',1,1),.
02f0: 20 28 27 61 6e 64 5f 74 68 65 5f 57 6f 72 64 5f ('and_the_Word_
0300: 77 61 73 5f 77 69 74 68 5f 47 6f 64 27 2c 31 2c was_with_God',1,
0310: 32 29 2c 0a 20 20 20 20 20 20 20 20 28 27 61 6e 2),. ('an
0320: 64 5f 74 68 65 5f 57 6f 72 64 5f 77 61 73 5f 47 d_the_Word_was_G
0330: 6f 64 27 2c 31 2c 33 29 2c 0a 20 20 20 20 20 20 od',1,3),.
0340: 20 20 28 27 54 68 65 5f 73 61 6d 65 5f 77 61 73 ('The_same_was
0350: 5f 69 6e 5f 74 68 65 5f 62 65 67 69 6e 6e 69 6e _in_the_beginnin
0360: 67 5f 77 69 74 68 5f 47 6f 64 27 2c 32 2c 31 29 g_with_God',2,1)
0370: 2c 0a 20 20 20 20 20 20 20 20 28 27 41 6c 6c 5f ,. ('All_
0380: 74 68 69 6e 67 73 5f 77 65 72 65 5f 6d 61 64 65 things_were_made
0390: 5f 62 79 5f 68 69 6d 27 2c 33 2c 31 29 2c 0a 20 _by_him',3,1),.
03a0: 20 20 20 20 20 20 20 28 27 61 6e 64 5f 77 69 74 ('and_wit
03b0: 68 6f 75 74 5f 68 69 6d 5f 77 61 73 5f 6e 6f 74 hout_him_was_not
03c0: 5f 61 6e 79 5f 74 68 69 6e 67 5f 6d 61 64 65 5f _any_thing_made_
03d0: 74 68 61 74 5f 77 61 73 5f 6d 61 64 65 27 2c 33 that_was_made',3
03e0: 2c 32 29 3b 0a 20 20 43 52 45 41 54 45 20 49 4e ,2);. CREATE IN
03f0: 44 45 58 20 74 31 61 31 20 4f 4e 20 74 31 28 73 DEX t1a1 ON t1(s
0400: 75 62 73 74 72 28 61 2c 31 2c 31 32 29 29 3b 0a ubstr(a,1,12));.
0410: 7d 20 7b 7d 0a 64 6f 5f 65 78 65 63 73 71 6c 5f } {}.do_execsql_
0420: 74 65 73 74 20 69 6e 64 65 78 65 78 70 72 31 2d test indexexpr1-
0430: 31 31 30 20 7b 0a 20 20 53 45 4c 45 43 54 20 62 110 {. SELECT b
0440: 2c 20 63 2c 20 27 7c 27 20 46 52 4f 4d 20 74 31 , c, '|' FROM t1
0450: 20 57 48 45 52 45 20 73 75 62 73 74 72 28 61 2c WHERE substr(a,
0460: 31 2c 31 32 29 3d 3d 27 61 6e 64 5f 74 68 65 5f 1,12)=='and_the_
0470: 57 6f 72 64 27 20 4f 52 44 45 52 20 42 59 20 62 Word' ORDER BY b
0480: 2c 20 63 3b 0a 7d 20 7b 31 20 32 20 7c 20 31 20 , c;.} {1 2 | 1
0490: 33 20 7c 7d 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 3 |}.do_execsql_
04a0: 74 65 73 74 20 69 6e 64 65 78 65 78 70 72 31 2d test indexexpr1-
04b0: 31 31 30 65 71 70 20 7b 0a 20 20 45 58 50 4c 41 110eqp {. EXPLA
04c0: 49 4e 20 51 55 45 52 59 20 50 4c 41 4e 0a 20 20 IN QUERY PLAN.
04d0: 53 45 4c 45 43 54 20 62 2c 20 63 2c 20 27 7c 27 SELECT b, c, '|'
04e0: 20 46 52 4f 4d 20 74 31 20 57 48 45 52 45 20 73 FROM t1 WHERE s
04f0: 75 62 73 74 72 28 61 2c 31 2c 31 32 29 3d 3d 27 ubstr(a,1,12)=='
0500: 61 6e 64 5f 74 68 65 5f 57 6f 72 64 27 20 4f 52 and_the_Word' OR
0510: 44 45 52 20 42 59 20 62 2c 20 63 3b 0a 7d 20 7b DER BY b, c;.} {
0520: 2f 55 53 49 4e 47 20 49 4e 44 45 58 20 74 31 61 /USING INDEX t1a
0530: 31 2f 7d 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 1/}.do_execsql_t
0540: 65 73 74 20 69 6e 64 65 78 65 78 70 72 31 2d 31 est indexexpr1-1
0550: 32 30 20 7b 0a 20 20 53 45 4c 45 43 54 20 62 2c 20 {. SELECT b,
0560: 20 63 2c 20 27 7c 27 20 46 52 4f 4d 20 74 31 20 c, '|' FROM t1
0570: 57 48 45 52 45 20 27 61 6e 64 5f 74 68 65 5f 57 WHERE 'and_the_W
0580: 6f 72 64 27 3d 3d 73 75 62 73 74 72 28 61 2c 31 ord'==substr(a,1
0590: 2c 31 32 29 20 4f 52 44 45 52 20 42 59 20 62 2c ,12) ORDER BY b,
05a0: 20 63 3b 0a 7d 20 7b 31 20 32 20 7c 20 31 20 33 c;.} {1 2 | 1 3
05b0: 20 7c 7d 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 |}.do_execsql_t
05c0: 65 73 74 20 69 6e 64 65 78 65 78 70 72 31 2d 31 est indexexpr1-1
05d0: 32 30 65 71 70 20 7b 0a 20 20 45 58 50 4c 41 49 20eqp {. EXPLAI
05e0: 4e 20 51 55 45 52 59 20 50 4c 41 4e 0a 20 20 53 N QUERY PLAN. S
05f0: 45 4c 45 43 54 20 62 2c 20 63 2c 20 27 7c 27 20 ELECT b, c, '|'
0600: 46 52 4f 4d 20 74 31 20 57 48 45 52 45 20 27 61 FROM t1 WHERE 'a
0610: 6e 64 5f 74 68 65 5f 57 6f 72 64 27 3d 3d 73 75 nd_the_Word'==su
0620: 62 73 74 72 28 61 2c 31 2c 31 32 29 20 4f 52 44 bstr(a,1,12) ORD
0630: 45 52 20 42 59 20 62 2c 20 63 3b 0a 7d 20 7b 2f ER BY b, c;.} {/
0640: 55 53 49 4e 47 20 49 4e 44 45 58 20 74 31 61 31 USING INDEX t1a1
0650: 2f 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 /}..do_execsql_t
0660: 65 73 74 20 69 6e 64 65 78 65 78 70 72 31 2d 31 est indexexpr1-1
0670: 33 30 20 7b 0a 20 20 43 52 45 41 54 45 20 49 4e 30 {. CREATE IN
0680: 44 45 58 20 74 31 62 61 20 4f 4e 20 74 31 28 62 DEX t1ba ON t1(b
0690: 2c 73 75 62 73 74 72 28 61 2c 32 2c 33 29 2c 63 ,substr(a,2,3),c
06a0: 29 3b 0a 20 20 53 45 4c 45 43 54 20 63 20 46 52 );. SELECT c FR
06b0: 4f 4d 20 74 31 20 57 48 45 52 45 20 62 3d 31 20 OM t1 WHERE b=1
06c0: 41 4e 44 20 73 75 62 73 74 72 28 61 2c 32 2c 33 AND substr(a,2,3
06d0: 29 3d 27 6e 64 5f 27 20 4f 52 44 45 52 20 42 59 )='nd_' ORDER BY
06e0: 20 63 3b 0a 7d 20 7b 32 20 33 7d 0a 64 6f 5f 65 c;.} {2 3}.do_e
06f0: 78 65 63 73 71 6c 5f 74 65 73 74 20 69 6e 64 65 xecsql_test inde
0700: 78 65 78 70 72 31 2d 31 33 30 65 71 70 20 7b 0a xexpr1-130eqp {.
0710: 20 20 45 58 50 4c 41 49 4e 20 51 55 45 52 59 20 EXPLAIN QUERY
0720: 50 4c 41 4e 0a 20 20 53 45 4c 45 43 54 20 63 20 PLAN. SELECT c
0730: 46 52 4f 4d 20 74 31 20 57 48 45 52 45 20 62 3d FROM t1 WHERE b=
0740: 31 20 41 4e 44 20 73 75 62 73 74 72 28 61 2c 32 1 AND substr(a,2
0750: 2c 33 29 3d 27 6e 64 5f 27 20 4f 52 44 45 52 20 ,3)='nd_' ORDER
0760: 42 59 20 63 3b 0a 7d 20 7b 2f 55 53 49 4e 47 20 BY c;.} {/USING
0770: 49 4e 44 45 58 20 74 31 62 61 2f 7d 0a 0a 64 6f INDEX t1ba/}..do
0780: 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 69 6e _execsql_test in
0790: 64 65 78 65 78 70 72 31 2d 31 34 30 20 7b 0a 20 dexexpr1-140 {.
07a0: 20 53 45 4c 45 43 54 20 72 6f 77 69 64 2c 20 73 SELECT rowid, s
07b0: 75 62 73 74 72 28 61 2c 62 2c 33 29 2c 20 27 7c ubstr(a,b,3), '|
07c0: 27 20 46 52 4f 4d 20 74 31 20 4f 52 44 45 52 20 ' FROM t1 ORDER
07d0: 42 59 20 32 3b 0a 7d 20 7b 31 20 49 6e 5f 20 7c BY 2;.} {1 In_ |
07e0: 20 32 20 61 6e 64 20 7c 20 33 20 61 6e 64 20 7c 2 and | 3 and |
07f0: 20 36 20 64 5f 77 20 7c 20 34 20 68 65 5f 20 7c 6 d_w | 4 he_ |
0800: 20 35 20 6c 5f 74 20 7c 7d 0a 64 6f 5f 65 78 65 5 l_t |}.do_exe
0810: 63 73 71 6c 5f 74 65 73 74 20 69 6e 64 65 78 65 csql_test indexe
0820: 78 70 72 31 2d 31 34 31 20 7b 0a 20 20 43 52 45 xpr1-141 {. CRE
0830: 41 54 45 20 49 4e 44 45 58 20 74 31 61 62 78 20 ATE INDEX t1abx
0840: 4f 4e 20 74 31 28 73 75 62 73 74 72 28 61 2c 62 ON t1(substr(a,b
0850: 2c 33 29 29 3b 0a 20 20 53 45 4c 45 43 54 20 72 ,3));. SELECT r
0860: 6f 77 69 64 20 46 52 4f 4d 20 74 31 20 57 48 45 owid FROM t1 WHE
0870: 52 45 20 73 75 62 73 74 72 28 61 2c 62 2c 33 29 RE substr(a,b,3)
0880: 3c 3d 27 61 6e 64 27 20 4f 52 44 45 52 20 42 59 <='and' ORDER BY
0890: 20 2b 72 6f 77 69 64 3b 0a 7d 20 7b 31 20 32 20 +rowid;.} {1 2
08a0: 33 7d 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 3}.do_execsql_te
08b0: 73 74 20 69 6e 64 65 78 65 78 70 72 31 2d 31 34 st indexexpr1-14
08c0: 31 65 71 70 20 7b 0a 20 20 45 58 50 4c 41 49 4e 1eqp {. EXPLAIN
08d0: 20 51 55 45 52 59 20 50 4c 41 4e 0a 20 20 53 45 QUERY PLAN. SE
08e0: 4c 45 43 54 20 72 6f 77 69 64 20 46 52 4f 4d 20 LECT rowid FROM
08f0: 74 31 20 57 48 45 52 45 20 73 75 62 73 74 72 28 t1 WHERE substr(
0900: 61 2c 62 2c 33 29 3c 3d 27 61 6e 64 27 20 4f 52 a,b,3)<='and' OR
0910: 44 45 52 20 42 59 20 2b 72 6f 77 69 64 3b 0a 7d DER BY +rowid;.}
0920: 20 7b 2f 55 53 49 4e 47 20 49 4e 44 45 58 20 74 {/USING INDEX t
0930: 31 61 62 78 2f 7d 0a 64 6f 5f 65 78 65 63 73 71 1abx/}.do_execsq
0940: 6c 5f 74 65 73 74 20 69 6e 64 65 78 65 78 70 72 l_test indexexpr
0950: 31 2d 31 34 32 20 7b 0a 20 20 53 45 4c 45 43 54 1-142 {. SELECT
0960: 20 72 6f 77 69 64 20 46 52 4f 4d 20 74 31 20 57 rowid FROM t1 W
0970: 48 45 52 45 20 2b 73 75 62 73 74 72 28 61 2c 62 HERE +substr(a,b
0980: 2c 33 29 3c 3d 27 61 6e 64 27 20 4f 52 44 45 52 ,3)<='and' ORDER
0990: 20 42 59 20 2b 72 6f 77 69 64 3b 0a 7d 20 7b 31 BY +rowid;.} {1
09a0: 20 32 20 33 7d 0a 64 6f 5f 65 78 65 63 73 71 6c 2 3}.do_execsql
09b0: 5f 74 65 73 74 20 69 6e 64 65 78 65 78 70 72 31 _test indexexpr1
09c0: 2d 31 35 30 20 7b 0a 20 20 53 45 4c 45 43 54 20 -150 {. SELECT
09d0: 72 6f 77 69 64 20 46 52 4f 4d 20 74 31 20 57 48 rowid FROM t1 WH
09e0: 45 52 45 20 73 75 62 73 74 72 28 61 2c 62 2c 33 ERE substr(a,b,3
09f0: 29 20 49 4e 20 28 27 61 6e 64 27 2c 27 6c 5f 74 ) IN ('and','l_t
0a00: 27 2c 27 78 79 7a 27 29 0a 20 20 20 4f 52 44 45 ','xyz'). ORDE
0a10: 52 20 42 59 20 2b 72 6f 77 69 64 3b 0a 7d 20 7b R BY +rowid;.} {
0a20: 32 20 33 20 35 7d 0a 64 6f 5f 65 78 65 63 73 71 2 3 5}.do_execsq
0a30: 6c 5f 74 65 73 74 20 69 6e 64 65 78 65 78 70 72 l_test indexexpr
0a40: 31 2d 31 35 30 65 71 70 20 7b 0a 20 20 45 58 50 1-150eqp {. EXP
0a50: 4c 41 49 4e 20 51 55 45 52 59 20 50 4c 41 4e 0a LAIN QUERY PLAN.
0a60: 20 20 53 45 4c 45 43 54 20 72 6f 77 69 64 20 46 SELECT rowid F
0a70: 52 4f 4d 20 74 31 20 57 48 45 52 45 20 73 75 62 ROM t1 WHERE sub
0a80: 73 74 72 28 61 2c 62 2c 33 29 20 49 4e 20 28 27 str(a,b,3) IN ('
0a90: 61 6e 64 27 2c 27 6c 5f 74 27 2c 27 78 79 7a 27 and','l_t','xyz'
0aa0: 29 0a 20 20 20 4f 52 44 45 52 20 42 59 20 2b 72 ). ORDER BY +r
0ab0: 6f 77 69 64 3b 0a 7d 20 7b 2f 55 53 49 4e 47 20 owid;.} {/USING
0ac0: 49 4e 44 45 58 20 74 31 61 62 78 2f 7d 0a 0a 64 INDEX t1abx/}..d
0ad0: 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 69 o_execsql_test i
0ae0: 6e 64 65 78 65 78 70 72 31 2d 31 36 30 20 7b 0a ndexexpr1-160 {.
0af0: 20 20 41 4c 54 45 52 20 54 41 42 4c 45 20 74 31 ALTER TABLE t1
0b00: 20 41 44 44 20 43 4f 4c 55 4d 4e 20 64 3b 0a 20 ADD COLUMN d;.
0b10: 20 55 50 44 41 54 45 20 74 31 20 53 45 54 20 64 UPDATE t1 SET d
0b20: 3d 6c 65 6e 67 74 68 28 61 29 3b 0a 20 20 43 52 =length(a);. CR
0b30: 45 41 54 45 20 49 4e 44 45 58 20 74 31 61 32 20 EATE INDEX t1a2
0b40: 4f 4e 20 74 31 28 53 55 42 53 54 52 28 61 2c 20 ON t1(SUBSTR(a,
0b50: 32 37 2c 20 33 29 29 20 57 48 45 52 45 20 64 3e 27, 3)) WHERE d>
0b60: 3d 32 39 3b 0a 20 20 53 45 4c 45 43 54 20 72 6f =29;. SELECT ro
0b70: 77 69 64 2c 20 62 2c 20 63 20 46 52 4f 4d 20 74 wid, b, c FROM t
0b80: 31 0a 20 20 20 57 48 45 52 45 20 73 75 62 73 74 1. WHERE subst
0b90: 72 28 61 2c 32 37 2c 33 29 3d 3d 27 6f 72 64 27 r(a,27,3)=='ord'
0ba0: 20 41 4e 44 20 64 3e 3d 32 39 3b 0a 7d 20 7b 31 AND d>=29;.} {1
0bb0: 20 31 20 31 7d 0a 64 6f 5f 65 78 65 63 73 71 6c 1 1}.do_execsql
0bc0: 5f 74 65 73 74 20 69 6e 64 65 78 65 78 70 72 31 _test indexexpr1
0bd0: 2d 31 36 30 65 71 70 20 7b 0a 20 20 45 58 50 4c -160eqp {. EXPL
0be0: 41 49 4e 20 51 55 45 52 59 20 50 4c 41 4e 0a 20 AIN QUERY PLAN.
0bf0: 20 53 45 4c 45 43 54 20 72 6f 77 69 64 2c 20 62 SELECT rowid, b
0c00: 2c 20 63 20 46 52 4f 4d 20 74 31 0a 20 20 20 57 , c FROM t1. W
0c10: 48 45 52 45 20 73 75 62 73 74 72 28 61 2c 32 37 HERE substr(a,27
0c20: 2c 33 29 3d 3d 27 6f 72 64 27 20 41 4e 44 20 64 ,3)=='ord' AND d
0c30: 3e 3d 32 39 3b 0a 7d 20 7b 2f 55 53 49 4e 47 20 >=29;.} {/USING
0c40: 49 4e 44 45 58 20 74 31 61 32 2f 7d 0a 0a 23 20 INDEX t1a2/}..#
0c50: 4f 52 44 45 52 20 42 59 20 75 73 69 6e 67 20 61 ORDER BY using a
0c60: 6e 20 69 6e 64 65 78 65 64 20 65 78 70 72 65 73 n indexed expres
0c70: 73 69 6f 6e 0a 23 0a 64 6f 5f 65 78 65 63 73 71 sion.#.do_execsq
0c80: 6c 5f 74 65 73 74 20 69 6e 64 65 78 65 78 70 72 l_test indexexpr
0c90: 31 2d 31 37 30 20 7b 0a 20 20 43 52 45 41 54 45 1-170 {. CREATE
0ca0: 20 49 4e 44 45 58 20 74 31 61 6c 65 6e 20 4f 4e INDEX t1alen ON
0cb0: 20 74 31 28 6c 65 6e 67 74 68 28 61 29 29 3b 0a t1(length(a));.
0cc0: 20 20 53 45 4c 45 43 54 20 6c 65 6e 67 74 68 28 SELECT length(
0cd0: 61 29 20 46 52 4f 4d 20 74 31 20 4f 52 44 45 52 a) FROM t1 ORDER
0ce0: 20 42 59 20 6c 65 6e 67 74 68 28 61 29 3b 0a 7d BY length(a);.}
0cf0: 20 7b 32 30 20 32 35 20 32 37 20 32 39 20 33 38 {20 25 27 29 38
0d00: 20 35 32 7d 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 52}.do_execsql_
0d10: 74 65 73 74 20 69 6e 64 65 78 65 78 70 72 31 2d test indexexpr1-
0d20: 31 37 30 65 71 70 20 7b 0a 20 20 45 58 50 4c 41 170eqp {. EXPLA
0d30: 49 4e 20 51 55 45 52 59 20 50 4c 41 4e 0a 20 20 IN QUERY PLAN.
0d40: 53 45 4c 45 43 54 20 6c 65 6e 67 74 68 28 61 29 SELECT length(a)
0d50: 20 46 52 4f 4d 20 74 31 20 4f 52 44 45 52 20 42 FROM t1 ORDER B
0d60: 59 20 6c 65 6e 67 74 68 28 61 29 3b 0a 7d 20 7b Y length(a);.} {
0d70: 2f 53 43 41 4e 20 54 41 42 4c 45 20 74 31 20 55 /SCAN TABLE t1 U
0d80: 53 49 4e 47 20 49 4e 44 45 58 20 74 31 61 6c 65 SING INDEX t1ale
0d90: 6e 2f 7d 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 n/}.do_execsql_t
0da0: 65 73 74 20 69 6e 64 65 78 65 78 70 72 31 2d 31 est indexexpr1-1
0db0: 37 31 20 7b 0a 20 20 53 45 4c 45 43 54 20 6c 65 71 {. SELECT le
0dc0: 6e 67 74 68 28 61 29 20 46 52 4f 4d 20 74 31 20 ngth(a) FROM t1
0dd0: 4f 52 44 45 52 20 42 59 20 6c 65 6e 67 74 68 28 ORDER BY length(
0de0: 61 29 20 44 45 53 43 3b 0a 7d 20 7b 35 32 20 33 a) DESC;.} {52 3
0df0: 38 20 32 39 20 32 37 20 32 35 20 32 30 7d 0a 64 8 29 27 25 20}.d
0e00: 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 69 o_execsql_test i
0e10: 6e 64 65 78 65 78 70 72 31 2d 31 37 31 65 71 70 ndexexpr1-171eqp
0e20: 20 7b 0a 20 20 45 58 50 4c 41 49 4e 20 51 55 45 {. EXPLAIN QUE
0e30: 52 59 20 50 4c 41 4e 0a 20 20 53 45 4c 45 43 54 RY PLAN. SELECT
0e40: 20 6c 65 6e 67 74 68 28 61 29 20 46 52 4f 4d 20 length(a) FROM
0e50: 74 31 20 4f 52 44 45 52 20 42 59 20 6c 65 6e 67 t1 ORDER BY leng
0e60: 74 68 28 61 29 20 44 45 53 43 3b 0a 7d 20 7b 2f th(a) DESC;.} {/
0e70: 53 43 41 4e 20 54 41 42 4c 45 20 74 31 20 55 53 SCAN TABLE t1 US
0e80: 49 4e 47 20 49 4e 44 45 58 20 74 31 61 6c 65 6e ING INDEX t1alen
0e90: 2f 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 /}..do_execsql_t
0ea0: 65 73 74 20 69 6e 64 65 78 65 78 70 72 31 2d 32 est indexexpr1-2
0eb0: 30 30 20 7b 0a 20 20 44 52 4f 50 20 54 41 42 4c 00 {. DROP TABL
0ec0: 45 20 74 31 3b 0a 20 20 43 52 45 41 54 45 20 54 E t1;. CREATE T
0ed0: 41 42 4c 45 20 74 31 28 69 64 20 41 4e 59 20 50 ABLE t1(id ANY P
0ee0: 52 49 4d 41 52 59 20 4b 45 59 2c 20 61 2c 62 2c RIMARY KEY, a,b,
0ef0: 63 29 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 c) WITHOUT ROWID
0f00: 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 ;. INSERT INTO
0f10: 74 31 28 69 64 2c 61 2c 62 2c 63 29 0a 20 20 56 t1(id,a,b,c). V
0f20: 41 4c 55 45 53 28 31 2c 27 49 6e 5f 74 68 65 5f ALUES(1,'In_the_
0f30: 62 65 67 69 6e 6e 69 6e 67 5f 77 61 73 5f 74 68 beginning_was_th
0f40: 65 5f 57 6f 72 64 27 2c 31 2c 31 29 2c 0a 20 20 e_Word',1,1),.
0f50: 20 20 20 20 20 20 28 32 2c 27 61 6e 64 5f 74 68 (2,'and_th
0f60: 65 5f 57 6f 72 64 5f 77 61 73 5f 77 69 74 68 5f e_Word_was_with_
0f70: 47 6f 64 27 2c 31 2c 32 29 2c 0a 20 20 20 20 20 God',1,2),.
0f80: 20 20 20 28 33 2c 27 61 6e 64 5f 74 68 65 5f 57 (3,'and_the_W
0f90: 6f 72 64 5f 77 61 73 5f 47 6f 64 27 2c 31 2c 33 ord_was_God',1,3
0fa0: 29 2c 0a 20 20 20 20 20 20 20 20 28 34 2c 27 54 ),. (4,'T
0fb0: 68 65 5f 73 61 6d 65 5f 77 61 73 5f 69 6e 5f 74 he_same_was_in_t
0fc0: 68 65 5f 62 65 67 69 6e 6e 69 6e 67 5f 77 69 74 he_beginning_wit
0fd0: 68 5f 47 6f 64 27 2c 32 2c 31 29 2c 0a 20 20 20 h_God',2,1),.
0fe0: 20 20 20 20 20 28 35 2c 27 41 6c 6c 5f 74 68 69 (5,'All_thi
0ff0: 6e 67 73 5f 77 65 72 65 5f 6d 61 64 65 5f 62 79 ngs_were_made_by
1000: 5f 68 69 6d 27 2c 33 2c 31 29 2c 0a 20 20 20 20 _him',3,1),.
1010: 20 20 20 20 28 36 2c 27 61 6e 64 5f 77 69 74 68 (6,'and_with
1020: 6f 75 74 5f 68 69 6d 5f 77 61 73 5f 6e 6f 74 5f out_him_was_not_
1030: 61 6e 79 5f 74 68 69 6e 67 5f 6d 61 64 65 5f 74 any_thing_made_t
1040: 68 61 74 5f 77 61 73 5f 6d 61 64 65 27 2c 33 2c hat_was_made',3,
1050: 32 29 3b 0a 20 20 43 52 45 41 54 45 20 49 4e 44 2);. CREATE IND
1060: 45 58 20 74 31 61 31 20 4f 4e 20 74 31 28 73 75 EX t1a1 ON t1(su
1070: 62 73 74 72 28 61 2c 31 2c 31 32 29 29 3b 0a 7d bstr(a,1,12));.}
1080: 20 7b 7d 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 {}.do_execsql_t
1090: 65 73 74 20 69 6e 64 65 78 65 78 70 72 31 2d 32 est indexexpr1-2
10a0: 31 30 20 7b 0a 20 20 53 45 4c 45 43 54 20 62 2c 10 {. SELECT b,
10b0: 20 63 2c 20 27 7c 27 20 46 52 4f 4d 20 74 31 20 c, '|' FROM t1
10c0: 57 48 45 52 45 20 73 75 62 73 74 72 28 61 2c 31 WHERE substr(a,1
10d0: 2c 31 32 29 3d 3d 27 61 6e 64 5f 74 68 65 5f 57 ,12)=='and_the_W
10e0: 6f 72 64 27 20 4f 52 44 45 52 20 42 59 20 62 2c ord' ORDER BY b,
10f0: 20 63 3b 0a 7d 20 7b 31 20 32 20 7c 20 31 20 33 c;.} {1 2 | 1 3
1100: 20 7c 7d 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 |}.do_execsql_t
1110: 65 73 74 20 69 6e 64 65 78 65 78 70 72 31 2d 32 est indexexpr1-2
1120: 31 30 65 71 70 20 7b 0a 20 20 45 58 50 4c 41 49 10eqp {. EXPLAI
1130: 4e 20 51 55 45 52 59 20 50 4c 41 4e 0a 20 20 53 N QUERY PLAN. S
1140: 45 4c 45 43 54 20 62 2c 20 63 2c 20 27 7c 27 20 ELECT b, c, '|'
1150: 46 52 4f 4d 20 74 31 20 57 48 45 52 45 20 73 75 FROM t1 WHERE su
1160: 62 73 74 72 28 61 2c 31 2c 31 32 29 3d 3d 27 61 bstr(a,1,12)=='a
1170: 6e 64 5f 74 68 65 5f 57 6f 72 64 27 20 4f 52 44 nd_the_Word' ORD
1180: 45 52 20 42 59 20 62 2c 20 63 3b 0a 7d 20 7b 2f ER BY b, c;.} {/
1190: 55 53 49 4e 47 20 49 4e 44 45 58 20 74 31 61 31 USING INDEX t1a1
11a0: 2f 7d 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 /}.do_execsql_te
11b0: 73 74 20 69 6e 64 65 78 65 78 70 72 31 2d 32 32 st indexexpr1-22
11c0: 30 20 7b 0a 20 20 53 45 4c 45 43 54 20 62 2c 20 0 {. SELECT b,
11d0: 63 2c 20 27 7c 27 20 46 52 4f 4d 20 74 31 20 57 c, '|' FROM t1 W
11e0: 48 45 52 45 20 27 61 6e 64 5f 74 68 65 5f 57 6f HERE 'and_the_Wo
11f0: 72 64 27 3d 3d 73 75 62 73 74 72 28 61 2c 31 2c rd'==substr(a,1,
1200: 31 32 29 20 4f 52 44 45 52 20 42 59 20 62 2c 20 12) ORDER BY b,
1210: 63 3b 0a 7d 20 7b 31 20 32 20 7c 20 31 20 33 20 c;.} {1 2 | 1 3
1220: 7c 7d 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 |}.do_execsql_te
1230: 73 74 20 69 6e 64 65 78 65 78 70 72 31 2d 32 32 st indexexpr1-22
1240: 30 65 71 70 20 7b 0a 20 20 45 58 50 4c 41 49 4e 0eqp {. EXPLAIN
1250: 20 51 55 45 52 59 20 50 4c 41 4e 0a 20 20 53 45 QUERY PLAN. SE
1260: 4c 45 43 54 20 62 2c 20 63 2c 20 27 7c 27 20 46 LECT b, c, '|' F
1270: 52 4f 4d 20 74 31 20 57 48 45 52 45 20 27 61 6e ROM t1 WHERE 'an
1280: 64 5f 74 68 65 5f 57 6f 72 64 27 3d 3d 73 75 62 d_the_Word'==sub
1290: 73 74 72 28 61 2c 31 2c 31 32 29 20 4f 52 44 45 str(a,1,12) ORDE
12a0: 52 20 42 59 20 62 2c 20 63 3b 0a 7d 20 7b 2f 55 R BY b, c;.} {/U
12b0: 53 49 4e 47 20 49 4e 44 45 58 20 74 31 61 31 2f SING INDEX t1a1/
12c0: 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 }..do_execsql_te
12d0: 73 74 20 69 6e 64 65 78 65 78 70 72 31 2d 32 33 st indexexpr1-23
12e0: 30 20 7b 0a 20 20 43 52 45 41 54 45 20 49 4e 44 0 {. CREATE IND
12f0: 45 58 20 74 31 62 61 20 4f 4e 20 74 31 28 62 2c EX t1ba ON t1(b,
1300: 73 75 62 73 74 72 28 61 2c 32 2c 33 29 2c 63 29 substr(a,2,3),c)
1310: 3b 0a 20 20 53 45 4c 45 43 54 20 63 20 46 52 4f ;. SELECT c FRO
1320: 4d 20 74 31 20 57 48 45 52 45 20 62 3d 31 20 41 M t1 WHERE b=1 A
1330: 4e 44 20 73 75 62 73 74 72 28 61 2c 32 2c 33 29 ND substr(a,2,3)
1340: 3d 27 6e 64 5f 27 20 4f 52 44 45 52 20 42 59 20 ='nd_' ORDER BY
1350: 63 3b 0a 7d 20 7b 32 20 33 7d 0a 64 6f 5f 65 78 c;.} {2 3}.do_ex
1360: 65 63 73 71 6c 5f 74 65 73 74 20 69 6e 64 65 78 ecsql_test index
1370: 65 78 70 72 31 2d 32 33 30 65 71 70 20 7b 0a 20 expr1-230eqp {.
1380: 20 45 58 50 4c 41 49 4e 20 51 55 45 52 59 20 50 EXPLAIN QUERY P
1390: 4c 41 4e 0a 20 20 53 45 4c 45 43 54 20 63 20 46 LAN. SELECT c F
13a0: 52 4f 4d 20 74 31 20 57 48 45 52 45 20 62 3d 31 ROM t1 WHERE b=1
13b0: 20 41 4e 44 20 73 75 62 73 74 72 28 61 2c 32 2c AND substr(a,2,
13c0: 33 29 3d 27 6e 64 5f 27 20 4f 52 44 45 52 20 42 3)='nd_' ORDER B
13d0: 59 20 63 3b 0a 7d 20 7b 2f 55 53 49 4e 47 20 49 Y c;.} {/USING I
13e0: 4e 44 45 58 20 74 31 62 61 2f 7d 0a 0a 64 6f 5f NDEX t1ba/}..do_
13f0: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 69 6e 64 execsql_test ind
1400: 65 78 65 78 70 72 31 2d 32 34 30 20 7b 0a 20 20 exexpr1-240 {.
1410: 53 45 4c 45 43 54 20 69 64 2c 20 73 75 62 73 74 SELECT id, subst
1420: 72 28 61 2c 62 2c 33 29 2c 20 27 7c 27 20 46 52 r(a,b,3), '|' FR
1430: 4f 4d 20 74 31 20 4f 52 44 45 52 20 42 59 20 32 OM t1 ORDER BY 2
1440: 3b 0a 7d 20 7b 31 20 49 6e 5f 20 7c 20 32 20 61 ;.} {1 In_ | 2 a
1450: 6e 64 20 7c 20 33 20 61 6e 64 20 7c 20 36 20 64 nd | 3 and | 6 d
1460: 5f 77 20 7c 20 34 20 68 65 5f 20 7c 20 35 20 6c _w | 4 he_ | 5 l
1470: 5f 74 20 7c 7d 0a 64 6f 5f 65 78 65 63 73 71 6c _t |}.do_execsql
1480: 5f 74 65 73 74 20 69 6e 64 65 78 65 78 70 72 31 _test indexexpr1
1490: 2d 32 34 31 20 7b 0a 20 20 43 52 45 41 54 45 20 -241 {. CREATE
14a0: 49 4e 44 45 58 20 74 31 61 62 78 20 4f 4e 20 74 INDEX t1abx ON t
14b0: 31 28 73 75 62 73 74 72 28 61 2c 62 2c 33 29 29 1(substr(a,b,3))
14c0: 3b 0a 20 20 53 45 4c 45 43 54 20 69 64 20 46 52 ;. SELECT id FR
14d0: 4f 4d 20 74 31 20 57 48 45 52 45 20 73 75 62 73 OM t1 WHERE subs
14e0: 74 72 28 61 2c 62 2c 33 29 3c 3d 27 61 6e 64 27 tr(a,b,3)<='and'
14f0: 20 4f 52 44 45 52 20 42 59 20 2b 69 64 3b 0a 7d ORDER BY +id;.}
1500: 20 7b 31 20 32 20 33 7d 0a 64 6f 5f 65 78 65 63 {1 2 3}.do_exec
1510: 73 71 6c 5f 74 65 73 74 20 69 6e 64 65 78 65 78 sql_test indexex
1520: 70 72 31 2d 32 34 31 65 71 70 20 7b 0a 20 20 45 pr1-241eqp {. E
1530: 58 50 4c 41 49 4e 20 51 55 45 52 59 20 50 4c 41 XPLAIN QUERY PLA
1540: 4e 0a 20 20 53 45 4c 45 43 54 20 69 64 20 46 52 N. SELECT id FR
1550: 4f 4d 20 74 31 20 57 48 45 52 45 20 73 75 62 73 OM t1 WHERE subs
1560: 74 72 28 61 2c 62 2c 33 29 3c 3d 27 61 6e 64 27 tr(a,b,3)<='and'
1570: 20 4f 52 44 45 52 20 42 59 20 2b 69 64 3b 0a 7d ORDER BY +id;.}
1580: 20 7b 2f 55 53 49 4e 47 20 49 4e 44 45 58 20 74 {/USING INDEX t
1590: 31 61 62 78 2f 7d 0a 64 6f 5f 65 78 65 63 73 71 1abx/}.do_execsq
15a0: 6c 5f 74 65 73 74 20 69 6e 64 65 78 65 78 70 72 l_test indexexpr
15b0: 31 2d 32 34 32 20 7b 0a 20 20 53 45 4c 45 43 54 1-242 {. SELECT
15c0: 20 69 64 20 46 52 4f 4d 20 74 31 20 57 48 45 52 id FROM t1 WHER
15d0: 45 20 2b 73 75 62 73 74 72 28 61 2c 62 2c 33 29 E +substr(a,b,3)
15e0: 3c 3d 27 61 6e 64 27 20 4f 52 44 45 52 20 42 59 <='and' ORDER BY
15f0: 20 2b 69 64 3b 0a 7d 20 7b 31 20 32 20 33 7d 0a +id;.} {1 2 3}.
1600: 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 do_execsql_test
1610: 69 6e 64 65 78 65 78 70 72 31 2d 32 35 30 20 7b indexexpr1-250 {
1620: 0a 20 20 53 45 4c 45 43 54 20 69 64 20 46 52 4f . SELECT id FRO
1630: 4d 20 74 31 20 57 48 45 52 45 20 73 75 62 73 74 M t1 WHERE subst
1640: 72 28 61 2c 62 2c 33 29 20 49 4e 20 28 27 61 6e r(a,b,3) IN ('an
1650: 64 27 2c 27 6c 5f 74 27 2c 27 78 79 7a 27 29 0a d','l_t','xyz').
1660: 20 20 20 4f 52 44 45 52 20 42 59 20 2b 69 64 3b ORDER BY +id;
1670: 0a 7d 20 7b 32 20 33 20 35 7d 0a 64 6f 5f 65 78 .} {2 3 5}.do_ex
1680: 65 63 73 71 6c 5f 74 65 73 74 20 69 6e 64 65 78 ecsql_test index
1690: 65 78 70 72 31 2d 32 35 30 65 71 70 20 7b 0a 20 expr1-250eqp {.
16a0: 20 45 58 50 4c 41 49 4e 20 51 55 45 52 59 20 50 EXPLAIN QUERY P
16b0: 4c 41 4e 0a 20 20 53 45 4c 45 43 54 20 69 64 20 LAN. SELECT id
16c0: 46 52 4f 4d 20 74 31 20 57 48 45 52 45 20 73 75 FROM t1 WHERE su
16d0: 62 73 74 72 28 61 2c 62 2c 33 29 20 49 4e 20 28 bstr(a,b,3) IN (
16e0: 27 61 6e 64 27 2c 27 6c 5f 74 27 2c 27 78 79 7a 'and','l_t','xyz
16f0: 27 29 0a 20 20 20 4f 52 44 45 52 20 42 59 20 2b '). ORDER BY +
1700: 69 64 3b 0a 7d 20 7b 2f 55 53 49 4e 47 20 49 4e id;.} {/USING IN
1710: 44 45 58 20 74 31 61 62 78 2f 7d 0a 0a 64 6f 5f DEX t1abx/}..do_
1720: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 69 6e 64 execsql_test ind
1730: 65 78 65 78 70 72 31 2d 32 36 30 20 7b 0a 20 20 exexpr1-260 {.
1740: 41 4c 54 45 52 20 54 41 42 4c 45 20 74 31 20 41 ALTER TABLE t1 A
1750: 44 44 20 43 4f 4c 55 4d 4e 20 64 3b 0a 20 20 55 DD COLUMN d;. U
1760: 50 44 41 54 45 20 74 31 20 53 45 54 20 64 3d 6c PDATE t1 SET d=l
1770: 65 6e 67 74 68 28 61 29 3b 0a 20 20 43 52 45 41 ength(a);. CREA
1780: 54 45 20 49 4e 44 45 58 20 74 31 61 32 20 4f 4e TE INDEX t1a2 ON
1790: 20 74 31 28 53 55 42 53 54 52 28 61 2c 20 32 37 t1(SUBSTR(a, 27
17a0: 2c 20 33 29 29 20 57 48 45 52 45 20 64 3e 3d 32 , 3)) WHERE d>=2
17b0: 39 3b 0a 20 20 53 45 4c 45 43 54 20 69 64 2c 20 9;. SELECT id,
17c0: 62 2c 20 63 20 46 52 4f 4d 20 74 31 0a 20 20 20 b, c FROM t1.
17d0: 57 48 45 52 45 20 73 75 62 73 74 72 28 61 2c 32 WHERE substr(a,2
17e0: 37 2c 33 29 3d 3d 27 6f 72 64 27 20 41 4e 44 20 7,3)=='ord' AND
17f0: 64 3e 3d 32 39 3b 0a 7d 20 7b 31 20 31 20 31 7d d>=29;.} {1 1 1}
1800: 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 .do_execsql_test
1810: 20 69 6e 64 65 78 65 78 70 72 31 2d 32 36 30 65 indexexpr1-260e
1820: 71 70 20 7b 0a 20 20 45 58 50 4c 41 49 4e 20 51 qp {. EXPLAIN Q
1830: 55 45 52 59 20 50 4c 41 4e 0a 20 20 53 45 4c 45 UERY PLAN. SELE
1840: 43 54 20 69 64 2c 20 62 2c 20 63 20 46 52 4f 4d CT id, b, c FROM
1850: 20 74 31 0a 20 20 20 57 48 45 52 45 20 73 75 62 t1. WHERE sub
1860: 73 74 72 28 61 2c 32 37 2c 33 29 3d 3d 27 6f 72 str(a,27,3)=='or
1870: 64 27 20 41 4e 44 20 64 3e 3d 32 39 3b 0a 7d 20 d' AND d>=29;.}
1880: 7b 2f 55 53 49 4e 47 20 49 4e 44 45 58 20 74 31 {/USING INDEX t1
1890: 61 32 2f 7d 0a 0a 0a 64 6f 5f 63 61 74 63 68 73 a2/}...do_catchs
18a0: 71 6c 5f 74 65 73 74 20 69 6e 64 65 78 65 78 70 ql_test indexexp
18b0: 72 31 2d 33 30 30 20 7b 0a 20 20 43 52 45 41 54 r1-300 {. CREAT
18c0: 45 20 54 41 42 4c 45 20 74 32 28 61 2c 62 2c 63 E TABLE t2(a,b,c
18d0: 29 3b 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 ); INSERT INTO t
18e0: 32 20 56 41 4c 55 45 53 28 31 2c 32 2c 33 29 3b 2 VALUES(1,2,3);
18f0: 0a 20 20 43 52 45 41 54 45 20 49 4e 44 45 58 20 . CREATE INDEX
1900: 74 32 78 31 20 4f 4e 20 74 32 28 61 2c 62 2b 72 t2x1 ON t2(a,b+r
1910: 61 6e 64 6f 6d 28 29 29 3b 0a 7d 20 7b 31 20 7b andom());.} {1 {
1920: 6e 6f 6e 2d 64 65 74 65 72 6d 69 6e 69 73 74 69 non-deterministi
1930: 63 20 66 75 6e 63 74 69 6f 6e 73 20 70 72 6f 68 c functions proh
1940: 69 62 69 74 65 64 20 69 6e 20 69 6e 64 65 78 20 ibited in index
1950: 65 78 70 72 65 73 73 69 6f 6e 73 7d 7d 0a 64 6f expressions}}.do
1960: 5f 63 61 74 63 68 73 71 6c 5f 74 65 73 74 20 69 _catchsql_test i
1970: 6e 64 65 78 65 78 70 72 31 2d 33 30 31 20 7b 0a ndexexpr1-301 {.
1980: 20 20 43 52 45 41 54 45 20 49 4e 44 45 58 20 74 CREATE INDEX t
1990: 32 78 31 20 4f 4e 20 74 32 28 6a 75 6c 69 61 6e 2x1 ON t2(julian
19a0: 64 61 79 28 27 6e 6f 77 27 2c 61 29 29 3b 0a 7d day('now',a));.}
19b0: 20 7b 31 20 7b 6e 6f 6e 2d 64 65 74 65 72 6d 69 {1 {non-determi
19c0: 6e 69 73 74 69 63 20 66 75 6e 63 74 69 6f 6e 20 nistic function
19d0: 69 6e 20 69 6e 64 65 78 20 65 78 70 72 65 73 73 in index express
19e0: 69 6f 6e 20 6f 72 20 43 48 45 43 4b 20 63 6f 6e ion or CHECK con
19f0: 73 74 72 61 69 6e 74 7d 7d 0a 64 6f 5f 63 61 74 straint}}.do_cat
1a00: 63 68 73 71 6c 5f 74 65 73 74 20 69 6e 64 65 78 chsql_test index
1a10: 65 78 70 72 31 2d 33 31 30 20 7b 0a 20 20 43 52 expr1-310 {. CR
1a20: 45 41 54 45 20 49 4e 44 45 58 20 74 32 78 32 20 EATE INDEX t2x2
1a30: 4f 4e 20 74 32 28 61 2c 62 2b 28 53 45 4c 45 43 ON t2(a,b+(SELEC
1a40: 54 20 31 35 29 29 3b 0a 7d 20 7b 31 20 7b 73 75 T 15));.} {1 {su
1a50: 62 71 75 65 72 69 65 73 20 70 72 6f 68 69 62 69 bqueries prohibi
1a60: 74 65 64 20 69 6e 20 69 6e 64 65 78 20 65 78 70 ted in index exp
1a70: 72 65 73 73 69 6f 6e 73 7d 7d 0a 64 6f 5f 63 61 ressions}}.do_ca
1a80: 74 63 68 73 71 6c 5f 74 65 73 74 20 69 6e 64 65 tchsql_test inde
1a90: 78 65 78 70 72 31 2d 33 32 30 20 7b 0a 20 20 43 xexpr1-320 {. C
1aa0: 52 45 41 54 45 20 54 41 42 4c 45 20 65 31 28 78 REATE TABLE e1(x
1ab0: 2c 79 2c 55 4e 49 51 55 45 28 79 2c 73 75 62 73 ,y,UNIQUE(y,subs
1ac0: 74 72 28 78 2c 31 2c 35 29 29 29 3b 0a 7d 20 7b tr(x,1,5)));.} {
1ad0: 31 20 7b 65 78 70 72 65 73 73 69 6f 6e 73 20 70 1 {expressions p
1ae0: 72 6f 68 69 62 69 74 65 64 20 69 6e 20 50 52 49 rohibited in PRI
1af0: 4d 41 52 59 20 4b 45 59 20 61 6e 64 20 55 4e 49 MARY KEY and UNI
1b00: 51 55 45 20 63 6f 6e 73 74 72 61 69 6e 74 73 7d QUE constraints}
1b10: 7d 0a 64 6f 5f 63 61 74 63 68 73 71 6c 5f 74 65 }.do_catchsql_te
1b20: 73 74 20 69 6e 64 65 78 65 78 70 72 31 2d 33 33 st indexexpr1-33
1b30: 30 20 7b 0a 20 20 43 52 45 41 54 45 20 54 41 42 0 {. CREATE TAB
1b40: 4c 45 20 65 31 28 78 2c 79 2c 50 52 49 4d 41 52 LE e1(x,y,PRIMAR
1b50: 59 20 4b 45 59 28 79 2c 73 75 62 73 74 72 28 78 Y KEY(y,substr(x
1b60: 2c 31 2c 35 29 29 29 3b 0a 7d 20 7b 31 20 7b 65 ,1,5)));.} {1 {e
1b70: 78 70 72 65 73 73 69 6f 6e 73 20 70 72 6f 68 69 xpressions prohi
1b80: 62 69 74 65 64 20 69 6e 20 50 52 49 4d 41 52 59 bited in PRIMARY
1b90: 20 4b 45 59 20 61 6e 64 20 55 4e 49 51 55 45 20 KEY and UNIQUE
1ba0: 63 6f 6e 73 74 72 61 69 6e 74 73 7d 7d 0a 64 6f constraints}}.do
1bb0: 5f 63 61 74 63 68 73 71 6c 5f 74 65 73 74 20 69 _catchsql_test i
1bc0: 6e 64 65 78 65 78 70 72 31 2d 33 33 31 20 7b 0a ndexexpr1-331 {.
1bd0: 20 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 65 CREATE TABLE e
1be0: 31 28 78 2c 79 2c 50 52 49 4d 41 52 59 20 4b 45 1(x,y,PRIMARY KE
1bf0: 59 28 79 2c 73 75 62 73 74 72 28 78 2c 31 2c 35 Y(y,substr(x,1,5
1c00: 29 29 29 20 57 49 54 48 4f 55 54 20 52 4f 57 49 ))) WITHOUT ROWI
1c10: 44 3b 0a 7d 20 7b 31 20 7b 65 78 70 72 65 73 73 D;.} {1 {express
1c20: 69 6f 6e 73 20 70 72 6f 68 69 62 69 74 65 64 20 ions prohibited
1c30: 69 6e 20 50 52 49 4d 41 52 59 20 4b 45 59 20 61 in PRIMARY KEY a
1c40: 6e 64 20 55 4e 49 51 55 45 20 63 6f 6e 73 74 72 nd UNIQUE constr
1c50: 61 69 6e 74 73 7d 7d 0a 64 6f 5f 63 61 74 63 68 aints}}.do_catch
1c60: 73 71 6c 5f 74 65 73 74 20 69 6e 64 65 78 65 78 sql_test indexex
1c70: 70 72 31 2d 33 34 30 20 7b 0a 20 20 43 52 45 41 pr1-340 {. CREA
1c80: 54 45 20 54 41 42 4c 45 20 65 31 28 78 2c 79 2c TE TABLE e1(x,y,
1c90: 46 4f 52 45 49 47 4e 20 4b 45 59 28 73 75 62 73 FOREIGN KEY(subs
1ca0: 74 72 28 79 2c 31 2c 35 29 29 20 52 45 46 45 52 tr(y,1,5)) REFER
1cb0: 45 4e 43 45 53 20 74 31 29 3b 0a 7d 20 7b 31 20 ENCES t1);.} {1
1cc0: 7b 6e 65 61 72 20 22 28 22 3a 20 73 79 6e 74 61 {near "(": synta
1cd0: 78 20 65 72 72 6f 72 7d 7d 0a 0a 64 6f 5f 65 78 x error}}..do_ex
1ce0: 65 63 73 71 6c 5f 74 65 73 74 20 69 6e 64 65 78 ecsql_test index
1cf0: 65 78 70 72 31 2d 34 30 30 20 7b 0a 20 20 43 52 expr1-400 {. CR
1d00: 45 41 54 45 20 54 41 42 4c 45 20 74 33 28 61 2c EATE TABLE t3(a,
1d10: 62 2c 63 29 3b 0a 20 20 57 49 54 48 20 52 45 43 b,c);. WITH REC
1d20: 55 52 53 49 56 45 20 63 28 78 29 20 41 53 20 28 URSIVE c(x) AS (
1d30: 56 41 4c 55 45 53 28 31 29 20 55 4e 49 4f 4e 20 VALUES(1) UNION
1d40: 53 45 4c 45 43 54 20 78 2b 31 20 46 52 4f 4d 20 SELECT x+1 FROM
1d50: 63 20 57 48 45 52 45 20 78 3c 33 30 29 0a 20 20 c WHERE x<30).
1d60: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 33 28 61 INSERT INTO t3(a
1d70: 2c 62 2c 63 29 0a 20 20 20 20 53 45 4c 45 43 54 ,b,c). SELECT
1d80: 20 78 2c 20 70 72 69 6e 74 66 28 27 61 62 25 30 x, printf('ab%0
1d90: 34 78 79 7a 27 2c 78 29 2c 20 72 61 6e 64 6f 6d 4xyz',x), random
1da0: 28 29 20 46 52 4f 4d 20 63 3b 0a 20 20 43 52 45 () FROM c;. CRE
1db0: 41 54 45 20 55 4e 49 51 55 45 20 49 4e 44 45 58 ATE UNIQUE INDEX
1dc0: 20 74 33 61 62 63 20 4f 4e 20 74 33 28 43 41 53 t3abc ON t3(CAS
1dd0: 54 28 61 20 41 53 20 74 65 78 74 29 2c 20 62 2c T(a AS text), b,
1de0: 20 73 75 62 73 74 72 28 63 2c 31 2c 33 29 29 3b substr(c,1,3));
1df0: 0a 20 20 53 45 4c 45 43 54 20 61 20 46 52 4f 4d . SELECT a FROM
1e00: 20 74 33 20 57 48 45 52 45 20 43 41 53 54 28 61 t3 WHERE CAST(a
1e10: 20 41 53 20 74 65 78 74 29 3c 3d 27 31 30 27 20 AS text)<='10'
1e20: 4f 52 44 45 52 20 42 59 20 2b 61 3b 0a 20 20 50 ORDER BY +a;. P
1e30: 52 41 47 4d 41 20 69 6e 74 65 67 72 69 74 79 5f RAGMA integrity_
1e40: 63 68 65 63 6b 3b 0a 7d 20 7b 31 20 31 30 20 6f check;.} {1 10 o
1e50: 6b 7d 0a 64 6f 5f 63 61 74 63 68 73 71 6c 5f 74 k}.do_catchsql_t
1e60: 65 73 74 20 69 6e 64 65 78 65 78 70 72 31 2d 34 est indexexpr1-4
1e70: 31 30 20 7b 0a 20 20 49 4e 53 45 52 54 20 49 4e 10 {. INSERT IN
1e80: 54 4f 20 74 33 20 53 45 4c 45 43 54 20 2a 20 46 TO t3 SELECT * F
1e90: 52 4f 4d 20 74 33 20 57 48 45 52 45 20 72 6f 77 ROM t3 WHERE row
1ea0: 69 64 3d 31 30 3b 0a 7d 20 7b 31 20 7b 55 4e 49 id=10;.} {1 {UNI
1eb0: 51 55 45 20 63 6f 6e 73 74 72 61 69 6e 74 20 66 QUE constraint f
1ec0: 61 69 6c 65 64 3a 20 69 6e 64 65 78 20 27 74 33 ailed: index 't3
1ed0: 61 62 63 27 7d 7d 0a 0a 64 6f 5f 65 78 65 63 73 abc'}}..do_execs
1ee0: 71 6c 5f 74 65 73 74 20 69 6e 64 65 78 65 78 70 ql_test indexexp
1ef0: 72 31 2d 35 30 30 20 7b 0a 20 20 43 52 45 41 54 r1-500 {. CREAT
1f00: 45 20 54 41 42 4c 45 20 74 35 28 61 29 3b 0a 20 E TABLE t5(a);.
1f10: 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 63 6e CREATE TABLE cn
1f20: 74 28 78 29 3b 0a 20 20 57 49 54 48 20 52 45 43 t(x);. WITH REC
1f30: 55 52 53 49 56 45 0a 20 20 20 20 63 28 78 29 20 URSIVE. c(x)
1f40: 41 53 20 28 56 41 4c 55 45 53 28 31 29 20 55 4e AS (VALUES(1) UN
1f50: 49 4f 4e 20 41 4c 4c 20 53 45 4c 45 43 54 20 78 ION ALL SELECT x
1f60: 2b 31 20 46 52 4f 4d 20 63 20 57 48 45 52 45 20 +1 FROM c WHERE
1f70: 78 3c 35 29 0a 20 20 49 4e 53 45 52 54 20 49 4e x<5). INSERT IN
1f80: 54 4f 20 63 6e 74 28 78 29 20 53 45 4c 45 43 54 TO cnt(x) SELECT
1f90: 20 78 20 46 52 4f 4d 20 63 3b 0a 20 20 49 4e 53 x FROM c;. INS
1fa0: 45 52 54 20 49 4e 54 4f 20 74 35 28 61 29 20 53 ERT INTO t5(a) S
1fb0: 45 4c 45 43 54 20 70 72 69 6e 74 66 28 27 61 62 ELECT printf('ab
1fc0: 63 25 30 33 64 78 79 7a 27 2c 78 29 20 46 52 4f c%03dxyz',x) FRO
1fd0: 4d 20 63 6e 74 3b 0a 20 20 43 52 45 41 54 45 20 M cnt;. CREATE
1fe0: 49 4e 44 45 58 20 74 35 61 78 20 4f 4e 20 74 35 INDEX t5ax ON t5
1ff0: 28 20 73 75 62 73 74 72 28 61 2c 34 2c 33 29 20 ( substr(a,4,3)
2000: 29 3b 0a 7d 20 7b 7d 0a 64 6f 5f 65 78 65 63 73 );.} {}.do_execs
2010: 71 6c 5f 74 65 73 74 20 69 6e 64 65 78 65 78 70 ql_test indexexp
2020: 72 31 2d 35 31 30 20 7b 0a 20 20 2d 2d 20 54 68 r1-510 {. -- Th
2030: 65 20 75 73 65 20 6f 66 20 74 68 65 20 22 6b 22 e use of the "k"
2040: 20 61 6c 69 61 73 20 69 6e 20 74 68 65 20 57 48 alias in the WH
2050: 45 52 45 20 63 6c 61 75 73 65 20 69 73 20 74 65 ERE clause is te
2060: 63 68 6e 69 63 61 6c 6c 79 0a 20 20 2d 2d 20 69 chnically. -- i
2070: 6c 6c 65 67 61 6c 2c 20 62 75 74 20 53 51 4c 69 llegal, but SQLi
2080: 74 65 20 61 6c 6c 6f 77 73 20 69 74 20 66 6f 72 te allows it for
2090: 20 68 69 73 74 6f 72 69 63 61 6c 20 72 65 61 73 historical reas
20a0: 6f 6e 73 2e 20 20 49 6e 20 74 68 69 73 0a 20 20 ons. In this.
20b0: 2d 2d 20 74 65 73 74 20 61 6e 64 20 74 68 65 20 -- test and the
20c0: 6e 65 78 74 2c 20 76 65 72 69 66 79 20 74 68 61 next, verify tha
20d0: 74 20 22 6b 22 20 63 61 6e 20 62 65 20 75 73 65 t "k" can be use
20e0: 64 20 62 79 20 74 68 65 20 74 35 61 78 20 69 6e d by the t5ax in
20f0: 64 65 78 0a 20 20 53 45 4c 45 43 54 20 73 75 62 dex. SELECT sub
2100: 73 74 72 28 61 2c 34 2c 33 29 20 41 53 20 6b 20 str(a,4,3) AS k
2110: 46 52 4f 4d 20 63 6e 74 2c 20 74 35 20 57 48 45 FROM cnt, t5 WHE
2120: 52 45 20 6b 3d 70 72 69 6e 74 66 28 27 25 30 33 RE k=printf('%03
2130: 64 27 2c 78 29 3b 0a 7d 20 7b 30 30 31 20 30 30 d',x);.} {001 00
2140: 32 20 30 30 33 20 30 30 34 20 30 30 35 7d 0a 64 2 003 004 005}.d
2150: 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 69 o_execsql_test i
2160: 6e 64 65 78 65 78 70 72 31 2d 35 31 30 65 71 70 ndexexpr1-510eqp
2170: 20 7b 0a 20 20 45 58 50 4c 41 49 4e 20 51 55 45 {. EXPLAIN QUE
2180: 52 59 20 50 4c 41 4e 0a 20 20 53 45 4c 45 43 54 RY PLAN. SELECT
2190: 20 73 75 62 73 74 72 28 61 2c 34 2c 33 29 20 41 substr(a,4,3) A
21a0: 53 20 6b 20 46 52 4f 4d 20 63 6e 74 2c 20 74 35 S k FROM cnt, t5
21b0: 20 57 48 45 52 45 20 6b 3d 70 72 69 6e 74 66 28 WHERE k=printf(
21c0: 27 25 30 33 64 27 2c 78 29 3b 0a 7d 20 7b 2f 55 '%03d',x);.} {/U
21d0: 53 49 4e 47 20 49 4e 44 45 58 20 74 35 61 78 2f SING INDEX t5ax/
21e0: 7d 0a 0a 23 20 53 6b 69 70 2d 73 63 61 6e 20 6f }..# Skip-scan o
21f0: 6e 20 61 6e 20 69 6e 64 65 78 65 64 20 65 78 70 n an indexed exp
2200: 72 65 73 73 69 6f 6e 0a 23 0a 64 6f 5f 65 78 65 ression.#.do_exe
2210: 63 73 71 6c 5f 74 65 73 74 20 69 6e 64 65 78 65 csql_test indexe
2220: 78 70 72 31 2d 36 30 30 20 7b 0a 20 20 44 52 4f xpr1-600 {. DRO
2230: 50 20 54 41 42 4c 45 20 49 46 20 45 58 49 53 54 P TABLE IF EXIST
2240: 53 20 74 34 3b 0a 20 20 43 52 45 41 54 45 20 54 S t4;. CREATE T
2250: 41 42 4c 45 20 74 34 28 61 2c 62 2c 63 2c 64 2c ABLE t4(a,b,c,d,
2260: 65 2c 66 2c 67 2c 68 2c 69 29 3b 0a 20 20 43 52 e,f,g,h,i);. CR
2270: 45 41 54 45 20 49 4e 44 45 58 20 74 34 61 6c 6c EATE INDEX t4all
2280: 20 4f 4e 20 74 34 28 61 2c 62 2c 63 3c 64 2c 65 ON t4(a,b,c<d,e
2290: 2c 66 2c 69 2c 68 29 3b 0a 20 20 49 4e 53 45 52 ,f,i,h);. INSER
22a0: 54 20 49 4e 54 4f 20 74 34 20 56 41 4c 55 45 53 T INTO t4 VALUES
22b0: 28 31 2c 32 2c 33 2c 34 2c 35 2c 36 2c 37 2c 38 (1,2,3,4,5,6,7,8
22c0: 2c 39 29 3b 0a 20 20 41 4e 41 4c 59 5a 45 3b 0a ,9);. ANALYZE;.
22d0: 20 20 44 45 4c 45 54 45 20 46 52 4f 4d 20 73 71 DELETE FROM sq
22e0: 6c 69 74 65 5f 73 74 61 74 31 3b 0a 20 20 49 4e lite_stat1;. IN
22f0: 53 45 52 54 20 49 4e 54 4f 20 73 71 6c 69 74 65 SERT INTO sqlite
2300: 5f 73 74 61 74 31 0a 20 20 20 20 56 41 4c 55 45 _stat1. VALUE
2310: 53 28 27 74 34 27 2c 27 74 34 61 6c 6c 27 2c 27 S('t4','t4all','
2320: 36 30 30 30 30 30 20 31 36 30 30 30 30 20 34 30 600000 160000 40
2330: 30 30 30 20 31 30 30 30 30 20 32 30 30 30 20 36 000 10000 2000 6
2340: 30 30 20 31 30 30 20 34 30 20 31 30 27 29 3b 0a 00 100 40 10');.
2350: 20 20 41 4e 41 4c 59 5a 45 20 73 71 6c 69 74 65 ANALYZE sqlite
2360: 5f 6d 61 73 74 65 72 3b 0a 20 20 53 45 4c 45 43 _master;. SELEC
2370: 54 20 69 20 46 52 4f 4d 20 74 34 20 57 48 45 52 T i FROM t4 WHER
2380: 45 20 65 3d 35 3b 0a 7d 20 7b 39 7d 0a 0a 23 20 E e=5;.} {9}..#
2390: 49 6e 64 65 78 65 64 20 65 78 70 72 65 73 73 69 Indexed expressi
23a0: 6f 6e 73 20 6f 6e 20 62 6f 74 68 20 73 69 64 65 ons on both side
23b0: 73 20 6f 66 20 61 6e 20 3d 3d 20 69 6e 20 61 20 s of an == in a
23c0: 57 48 45 52 45 20 63 6c 61 75 73 65 2e 0a 23 0a WHERE clause..#.
23d0: 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 do_execsql_test
23e0: 69 6e 64 65 78 65 78 70 72 31 2d 37 30 30 20 7b indexexpr1-700 {
23f0: 0a 20 20 44 52 4f 50 20 54 41 42 4c 45 20 49 46 . DROP TABLE IF
2400: 20 45 58 49 53 54 53 20 74 37 3b 0a 20 20 43 52 EXISTS t7;. CR
2410: 45 41 54 45 20 54 41 42 4c 45 20 74 37 28 61 2c EATE TABLE t7(a,
2420: 62 2c 63 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 b,c);. INSERT I
2430: 4e 54 4f 20 74 37 28 61 2c 62 2c 63 29 20 56 41 NTO t7(a,b,c) VA
2440: 4c 55 45 53 28 31 2c 32 2c 32 29 2c 28 27 61 62 LUES(1,2,2),('ab
2450: 63 27 2c 27 64 65 66 27 2c 27 64 65 66 27 29 2c c','def','def'),
2460: 28 34 2c 35 2c 36 29 3b 0a 20 20 43 52 45 41 54 (4,5,6);. CREAT
2470: 45 20 49 4e 44 45 58 20 74 37 62 20 4f 4e 20 74 E INDEX t7b ON t
2480: 37 28 2b 62 29 3b 0a 20 20 43 52 45 41 54 45 20 7(+b);. CREATE
2490: 49 4e 44 45 58 20 74 37 63 20 4f 4e 20 74 37 28 INDEX t7c ON t7(
24a0: 2b 63 29 3b 0a 20 20 53 45 4c 45 43 54 20 2a 2c +c);. SELECT *,
24b0: 20 27 7c 27 20 46 52 4f 4d 20 74 37 20 57 48 45 '|' FROM t7 WHE
24c0: 52 45 20 2b 62 3d 2b 63 20 4f 52 44 45 52 20 42 RE +b=+c ORDER B
24d0: 59 20 2b 61 3b 0a 7d 20 7b 31 20 32 20 32 20 7c Y +a;.} {1 2 2 |
24e0: 20 61 62 63 20 64 65 66 20 64 65 66 20 7c 7d 0a abc def def |}.
24f0: 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 do_execsql_test
2500: 69 6e 64 65 78 65 78 70 72 31 2d 37 31 30 20 7b indexexpr1-710 {
2510: 0a 20 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 . CREATE TABLE
2520: 74 37 31 28 61 2c 62 2c 63 29 3b 0a 20 20 43 52 t71(a,b,c);. CR
2530: 45 41 54 45 20 49 4e 44 45 58 20 74 37 31 62 63 EATE INDEX t71bc
2540: 20 4f 4e 20 74 37 31 28 62 2b 63 29 3b 0a 20 20 ON t71(b+c);.
2550: 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 37 32 CREATE TABLE t72
2560: 28 78 2c 79 2c 7a 29 3b 0a 20 20 43 52 45 41 54 (x,y,z);. CREAT
2570: 45 20 49 4e 44 45 58 20 74 37 32 79 7a 20 4f 4e E INDEX t72yz ON
2580: 20 74 37 32 28 79 2b 7a 29 3b 0a 20 20 49 4e 53 t72(y+z);. INS
2590: 45 52 54 20 49 4e 54 4f 20 74 37 31 28 61 2c 62 ERT INTO t71(a,b
25a0: 2c 63 29 20 56 41 4c 55 45 53 28 31 2c 31 31 2c ,c) VALUES(1,11,
25b0: 32 29 2c 28 32 2c 37 2c 31 35 29 2c 28 33 2c 35 2),(2,7,15),(3,5
25c0: 2c 34 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e ,4);. INSERT IN
25d0: 54 4f 20 74 37 32 28 78 2c 79 2c 7a 29 20 56 41 TO t72(x,y,z) VA
25e0: 4c 55 45 53 28 31 2c 31 30 2c 33 29 2c 28 32 2c LUES(1,10,3),(2,
25f0: 38 2c 31 34 29 2c 28 33 2c 39 2c 39 29 3b 0a 20 8,14),(3,9,9);.
2600: 20 53 45 4c 45 43 54 20 61 2c 20 78 2c 20 27 7c SELECT a, x, '|
2610: 27 20 46 52 4f 4d 20 74 37 31 2c 20 74 37 32 0a ' FROM t71, t72.
2620: 20 20 20 57 48 45 52 45 20 62 2b 63 3d 79 2b 7a WHERE b+c=y+z
2630: 0a 20 20 4f 52 44 45 52 20 42 59 20 2b 61 2c 20 . ORDER BY +a,
2640: 2b 78 3b 0a 7d 20 7b 31 20 31 20 7c 20 32 20 32 +x;.} {1 1 | 2 2
2650: 20 7c 7d 0a 0a 23 20 43 6f 6c 6c 61 74 69 6e 67 |}..# Collating
2660: 20 73 65 71 75 65 6e 63 65 73 20 6f 6e 20 69 6e sequences on in
2670: 64 65 78 65 73 20 6f 66 20 65 78 70 72 65 73 73 dexes of express
2680: 69 6f 6e 73 0a 23 0a 64 6f 5f 65 78 65 63 73 71 ions.#.do_execsq
2690: 6c 5f 74 65 73 74 20 69 6e 64 65 78 65 78 70 72 l_test indexexpr
26a0: 31 2d 38 30 30 20 7b 0a 20 20 44 52 4f 50 20 54 1-800 {. DROP T
26b0: 41 42 4c 45 20 49 46 20 45 58 49 53 54 53 20 74 ABLE IF EXISTS t
26c0: 38 3b 0a 20 20 43 52 45 41 54 45 20 54 41 42 4c 8;. CREATE TABL
26d0: 45 20 74 38 28 61 20 49 4e 54 45 47 45 52 20 50 E t8(a INTEGER P
26e0: 52 49 4d 41 52 59 20 4b 45 59 2c 20 62 20 54 45 RIMARY KEY, b TE
26f0: 58 54 29 3b 0a 20 20 43 52 45 41 54 45 20 55 4e XT);. CREATE UN
2700: 49 51 55 45 20 49 4e 44 45 58 20 74 38 62 78 20 IQUE INDEX t8bx
2710: 4f 4e 20 74 38 28 73 75 62 73 74 72 28 62 2c 32 ON t8(substr(b,2
2720: 2c 34 29 20 43 4f 4c 4c 41 54 45 20 6e 6f 63 61 ,4) COLLATE noca
2730: 73 65 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e se);. INSERT IN
2740: 54 4f 20 74 38 28 61 2c 62 29 20 56 41 4c 55 45 TO t8(a,b) VALUE
2750: 53 28 31 2c 27 41 6c 69 63 65 27 29 2c 28 32 2c S(1,'Alice'),(2,
2760: 27 42 61 72 74 68 6f 6c 65 6d 65 77 27 29 2c 28 'Bartholemew'),(
2770: 33 2c 27 43 79 6e 74 68 69 61 27 29 3b 0a 20 20 3,'Cynthia');.
2780: 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74 38 SELECT * FROM t8
2790: 20 57 48 45 52 45 20 73 75 62 73 74 72 28 62 2c WHERE substr(b,
27a0: 32 2c 34 29 3d 27 41 52 54 48 27 20 43 4f 4c 4c 2,4)='ARTH' COLL
27b0: 41 54 45 20 6e 6f 63 61 73 65 3b 0a 7d 20 7b 32 ATE nocase;.} {2
27c0: 20 42 61 72 74 68 6f 6c 65 6d 65 77 7d 0a 64 6f Bartholemew}.do
27d0: 5f 63 61 74 63 68 73 71 6c 5f 74 65 73 74 20 69 _catchsql_test i
27e0: 6e 64 65 78 65 78 70 72 31 2d 38 31 30 20 7b 0a ndexexpr1-810 {.
27f0: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 38 INSERT INTO t8
2800: 28 61 2c 62 29 20 56 41 4c 55 45 53 28 34 2c 27 (a,b) VALUES(4,'
2810: 42 41 52 54 48 4d 45 52 45 27 29 3b 0a 7d 20 7b BARTHMERE');.} {
2820: 31 20 7b 55 4e 49 51 55 45 20 63 6f 6e 73 74 72 1 {UNIQUE constr
2830: 61 69 6e 74 20 66 61 69 6c 65 64 3a 20 69 6e 64 aint failed: ind
2840: 65 78 20 27 74 38 62 78 27 7d 7d 0a 64 6f 5f 63 ex 't8bx'}}.do_c
2850: 61 74 63 68 73 71 6c 5f 74 65 73 74 20 69 6e 64 atchsql_test ind
2860: 65 78 65 78 70 72 31 2d 38 32 30 20 7b 0a 20 20 exexpr1-820 {.
2870: 44 52 4f 50 20 49 4e 44 45 58 20 74 38 62 78 3b DROP INDEX t8bx;
2880: 0a 20 20 43 52 45 41 54 45 20 55 4e 49 51 55 45 . CREATE UNIQUE
2890: 20 49 4e 44 45 58 20 74 38 62 78 20 4f 4e 20 74 INDEX t8bx ON t
28a0: 38 28 73 75 62 73 74 72 28 62 2c 32 2c 34 29 20 8(substr(b,2,4)
28b0: 43 4f 4c 4c 41 54 45 20 72 74 72 69 6d 29 3b 0a COLLATE rtrim);.
28c0: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 38 INSERT INTO t8
28d0: 28 61 2c 62 29 20 56 41 4c 55 45 53 28 34 2c 27 (a,b) VALUES(4,'
28e0: 42 41 52 54 48 4d 45 52 45 27 29 3b 0a 7d 20 7b BARTHMERE');.} {
28f0: 30 20 7b 7d 7d 0a 0a 23 20 43 68 65 63 6b 20 74 0 {}}..# Check t
2900: 68 61 74 20 50 52 41 47 4d 41 20 69 6e 74 65 67 hat PRAGMA integ
2910: 72 69 74 79 5f 63 68 65 63 6b 20 77 6f 72 6b 73 rity_check works
2920: 20 63 6f 72 72 65 63 74 6c 79 20 6f 6e 20 61 0a correctly on a.
2930: 23 20 55 4e 49 51 55 45 20 69 6e 64 65 78 20 74 # UNIQUE index t
2940: 68 61 74 20 69 6e 63 6c 75 64 65 73 20 72 6f 77 hat includes row
2950: 69 64 20 61 6e 64 20 65 78 70 72 65 73 73 69 6f id and expressio
2960: 6e 20 74 65 72 6d 73 2e 0a 23 0a 64 6f 5f 65 78 n terms..#.do_ex
2970: 65 63 73 71 6c 5f 74 65 73 74 20 69 6e 64 65 78 ecsql_test index
2980: 65 78 70 72 31 2d 39 30 30 20 7b 0a 20 20 43 52 expr1-900 {. CR
2990: 45 41 54 45 20 54 41 42 4c 45 20 74 39 28 61 2c EATE TABLE t9(a,
29a0: 62 2c 63 2c 64 29 3b 0a 20 20 43 52 45 41 54 45 b,c,d);. CREATE
29b0: 20 55 4e 49 51 55 45 20 49 4e 44 45 58 20 74 39 UNIQUE INDEX t9
29c0: 78 31 20 4f 4e 20 74 39 28 63 2c 61 62 73 28 64 x1 ON t9(c,abs(d
29d0: 29 2c 62 29 3b 0a 20 20 49 4e 53 45 52 54 20 49 ),b);. INSERT I
29e0: 4e 54 4f 20 74 39 28 72 6f 77 69 64 2c 61 2c 62 NTO t9(rowid,a,b
29f0: 2c 63 2c 64 29 20 56 41 4c 55 45 53 28 31 2c 32 ,c,d) VALUES(1,2
2a00: 2c 33 2c 34 2c 35 29 3b 0a 20 20 49 4e 53 45 52 ,3,4,5);. INSER
2a10: 54 20 49 4e 54 4f 20 74 39 28 72 6f 77 69 64 2c T INTO t9(rowid,
2a20: 61 2c 62 2c 63 2c 64 29 20 56 41 4c 55 45 53 28 a,b,c,d) VALUES(
2a30: 32 2c 4e 55 4c 4c 2c 4e 55 4c 4c 2c 4e 55 4c 4c 2,NULL,NULL,NULL
2a40: 2c 4e 55 4c 4c 29 3b 0a 20 20 49 4e 53 45 52 54 ,NULL);. INSERT
2a50: 20 49 4e 54 4f 20 74 39 28 72 6f 77 69 64 2c 61 INTO t9(rowid,a
2a60: 2c 62 2c 63 2c 64 29 20 56 41 4c 55 45 53 28 33 ,b,c,d) VALUES(3
2a70: 2c 4e 55 4c 4c 2c 4e 55 4c 4c 2c 4e 55 4c 4c 2c ,NULL,NULL,NULL,
2a80: 4e 55 4c 4c 29 3b 0a 20 20 49 4e 53 45 52 54 20 NULL);. INSERT
2a90: 49 4e 54 4f 20 74 39 28 72 6f 77 69 64 2c 61 2c INTO t9(rowid,a,
2aa0: 62 2c 63 2c 64 29 20 56 41 4c 55 45 53 28 34 2c b,c,d) VALUES(4,
2ab0: 35 2c 36 2c 37 2c 38 29 3b 0a 20 20 50 52 41 47 5,6,7,8);. PRAG
2ac0: 4d 41 20 69 6e 74 65 67 72 69 74 79 5f 63 68 65 MA integrity_che
2ad0: 63 6b 3b 0a 7d 20 7b 6f 6b 7d 0a 64 6f 5f 63 61 ck;.} {ok}.do_ca
2ae0: 74 63 68 73 71 6c 5f 74 65 73 74 20 69 6e 64 65 tchsql_test inde
2af0: 78 65 78 70 72 31 2d 39 31 30 20 7b 0a 20 20 49 xexpr1-910 {. I
2b00: 4e 53 45 52 54 20 49 4e 54 4f 20 74 39 28 61 2c NSERT INTO t9(a,
2b10: 62 2c 63 2c 64 29 20 56 41 4c 55 45 53 28 35 2c b,c,d) VALUES(5,
2b20: 36 2c 37 2c 2d 38 29 3b 0a 7d 20 7b 31 20 7b 55 6,7,-8);.} {1 {U
2b30: 4e 49 51 55 45 20 63 6f 6e 73 74 72 61 69 6e 74 NIQUE constraint
2b40: 20 66 61 69 6c 65 64 3a 20 69 6e 64 65 78 20 27 failed: index '
2b50: 74 39 78 31 27 7d 7d 0a 0a 23 20 54 65 73 74 20 t9x1'}}..# Test
2b60: 63 61 73 65 73 20 64 65 72 69 76 65 64 20 66 72 cases derived fr
2b70: 6f 6d 20 61 20 4e 45 56 45 52 28 29 20 6d 61 72 om a NEVER() mar
2b80: 6f 20 66 61 69 6c 75 72 65 20 64 69 73 63 6f 76 o failure discov
2b90: 65 72 65 64 20 62 79 0a 23 20 4a 6f 6e 61 74 68 ered by.# Jonath
2ba0: 61 6e 20 4d 65 74 7a 6d 61 6e 20 75 73 69 6e 67 an Metzman using
2bb0: 20 41 46 4c 0a 23 0a 64 6f 5f 65 78 65 63 73 71 AFL.#.do_execsq
2bc0: 6c 5f 74 65 73 74 20 69 6e 64 65 78 65 78 70 72 l_test indexexpr
2bd0: 31 2d 31 30 30 30 20 7b 0a 20 20 44 52 4f 50 20 1-1000 {. DROP
2be0: 54 41 42 4c 45 20 49 46 20 45 58 49 53 54 53 20 TABLE IF EXISTS
2bf0: 74 30 3b 0a 20 20 43 52 45 41 54 45 20 54 41 42 t0;. CREATE TAB
2c00: 4c 45 20 74 30 28 61 2c 62 2c 74 29 3b 0a 20 20 LE t0(a,b,t);.
2c10: 43 52 45 41 54 45 20 49 4e 44 45 58 20 69 20 4f CREATE INDEX i O
2c20: 4e 20 74 30 28 61 20 69 6e 28 30 2c 31 29 29 3b N t0(a in(0,1));
2c30: 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 . INSERT INTO t
2c40: 30 20 56 41 4c 55 45 53 28 30 2c 31 2c 32 29 2c 0 VALUES(0,1,2),
2c50: 28 32 2c 33 2c 34 29 2c 28 35 2c 36 2c 37 29 3b (2,3,4),(5,6,7);
2c60: 0a 20 20 55 50 44 41 54 45 20 74 30 20 53 45 54 . UPDATE t0 SET
2c70: 20 62 3d 39 39 20 57 48 45 52 45 20 28 61 20 69 b=99 WHERE (a i
2c80: 6e 28 30 2c 31 29 29 3d 30 3b 0a 20 20 53 45 4c n(0,1))=0;. SEL
2c90: 45 43 54 20 2a 2c 20 27 7c 27 20 46 52 4f 4d 20 ECT *, '|' FROM
2ca0: 74 30 20 4f 52 44 45 52 20 42 59 20 2b 61 3b 0a t0 ORDER BY +a;.
2cb0: 7d 20 7b 30 20 31 20 32 20 7c 20 32 20 39 39 20 } {0 1 2 | 2 99
2cc0: 34 20 7c 20 35 20 39 39 20 37 20 7c 7d 0a 64 6f 4 | 5 99 7 |}.do
2cd0: 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 69 6e _execsql_test in
2ce0: 64 65 78 65 78 70 72 31 2d 31 30 31 30 20 7b 0a dexexpr1-1010 {.
2cf0: 20 20 55 50 44 41 54 45 20 74 30 20 53 45 54 20 UPDATE t0 SET
2d00: 62 3d 38 38 20 57 48 45 52 45 20 28 61 20 69 6e b=88 WHERE (a in
2d10: 28 30 2c 31 29 29 3d 31 3b 0a 20 20 53 45 4c 45 (0,1))=1;. SELE
2d20: 43 54 20 2a 2c 20 27 7c 27 20 46 52 4f 4d 20 74 CT *, '|' FROM t
2d30: 30 20 4f 52 44 45 52 20 42 59 20 2b 61 3b 0a 7d 0 ORDER BY +a;.}
2d40: 20 7b 30 20 38 38 20 32 20 7c 20 32 20 39 39 20 {0 88 2 | 2 99
2d50: 34 20 7c 20 35 20 39 39 20 37 20 7c 7d 0a 0a 23 4 | 5 99 7 |}..#
2d60: 20 32 30 31 36 2d 31 30 2d 31 30 0a 23 20 4d 61 2016-10-10.# Ma
2d70: 6b 65 20 73 75 72 65 20 69 6e 64 65 78 65 73 20 ke sure indexes
2d80: 6f 6e 20 65 78 70 72 65 73 73 69 6f 6e 73 20 73 on expressions s
2d90: 6b 69 70 20 6f 76 65 72 20 69 6e 69 74 69 61 6c kip over initial
2da0: 20 4e 55 4c 4c 20 76 61 6c 75 65 73 20 69 6e 20 NULL values in
2db0: 74 68 65 0a 23 20 69 6e 64 65 78 20 61 73 20 74 the.# index as t
2dc0: 68 65 79 20 61 72 65 20 73 75 70 70 6f 73 65 20 hey are suppose
2dd0: 74 6f 20 64 6f 2e 0a 23 20 54 69 63 6b 65 74 20 to do..# Ticket
2de0: 68 74 74 70 73 3a 2f 2f 77 77 77 2e 73 71 6c 69 https://www.sqli
2df0: 74 65 2e 6f 72 67 2f 73 72 63 2f 74 6b 74 76 69 te.org/src/tktvi
2e00: 65 77 2f 34 62 61 61 34 36 34 39 31 32 31 32 39 ew/4baa464912129
2e10: 34 37 0a 23 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 47.#.do_execsql_
2e20: 74 65 73 74 20 69 6e 64 65 78 65 78 70 72 31 2d test indexexpr1-
2e30: 31 31 30 30 20 7b 0a 20 20 44 52 4f 50 20 54 41 1100 {. DROP TA
2e40: 42 4c 45 20 49 46 20 45 58 49 53 54 53 20 74 31 BLE IF EXISTS t1
2e50: 3b 0a 20 20 43 52 45 41 54 45 20 54 41 42 4c 45 ;. CREATE TABLE
2e60: 20 74 31 28 61 29 3b 0a 20 20 49 4e 53 45 52 54 t1(a);. INSERT
2e70: 20 49 4e 54 4f 20 74 31 20 56 41 4c 55 45 53 28 INTO t1 VALUES(
2e80: 4e 55 4c 4c 29 2c 28 31 29 3b 0a 20 20 53 45 4c NULL),(1);. SEL
2e90: 45 43 54 20 27 31 3a 27 2c 20 74 79 70 65 6f 66 ECT '1:', typeof
2ea0: 28 61 29 2c 20 61 20 46 52 4f 4d 20 74 31 20 57 (a), a FROM t1 W
2eb0: 48 45 52 45 20 61 3c 31 30 3b 0a 20 20 53 45 4c HERE a<10;. SEL
2ec0: 45 43 54 20 27 32 3a 27 2c 20 74 79 70 65 6f 66 ECT '2:', typeof
2ed0: 28 61 29 2c 20 61 20 46 52 4f 4d 20 74 31 20 57 (a), a FROM t1 W
2ee0: 48 45 52 45 20 61 2b 30 3c 31 30 3b 0a 20 20 43 HERE a+0<10;. C
2ef0: 52 45 41 54 45 20 49 4e 44 45 58 20 74 31 78 31 REATE INDEX t1x1
2f00: 20 4f 4e 20 74 31 28 61 29 3b 0a 20 20 43 52 45 ON t1(a);. CRE
2f10: 41 54 45 20 49 4e 44 45 58 20 74 31 78 32 20 4f ATE INDEX t1x2 O
2f20: 4e 20 74 31 28 61 2b 30 29 3b 0a 20 20 53 45 4c N t1(a+0);. SEL
2f30: 45 43 54 20 27 33 3a 27 2c 20 74 79 70 65 6f 66 ECT '3:', typeof
2f40: 28 61 29 2c 20 61 20 46 52 4f 4d 20 74 31 20 57 (a), a FROM t1 W
2f50: 48 45 52 45 20 61 3c 31 30 3b 0a 20 20 53 45 4c HERE a<10;. SEL
2f60: 45 43 54 20 27 34 3a 27 2c 20 74 79 70 65 6f 66 ECT '4:', typeof
2f70: 28 61 29 2c 20 61 20 46 52 4f 4d 20 74 31 20 57 (a), a FROM t1 W
2f80: 48 45 52 45 20 61 2b 30 3c 31 30 3b 0a 7d 20 7b HERE a+0<10;.} {
2f90: 31 3a 20 69 6e 74 65 67 65 72 20 31 20 32 3a 20 1: integer 1 2:
2fa0: 69 6e 74 65 67 65 72 20 31 20 33 3a 20 69 6e 74 integer 1 3: int
2fb0: 65 67 65 72 20 31 20 34 3a 20 69 6e 74 65 67 65 eger 1 4: intege
2fc0: 72 20 31 7d 0a 0a 64 6f 5f 65 78 65 63 73 71 6c r 1}..do_execsql
2fd0: 5f 74 65 73 74 20 69 6e 64 65 78 65 78 70 72 31 _test indexexpr1
2fe0: 2d 31 32 30 30 20 7b 0a 20 20 43 52 45 41 54 45 -1200 {. CREATE
2ff0: 20 54 41 42 4c 45 20 74 31 30 28 61 20 69 6e 74 TABLE t10(a int
3000: 2c 20 62 20 69 6e 74 2c 20 63 20 69 6e 74 2c 20 , b int, c int,
3010: 64 20 69 6e 74 29 3b 0a 20 20 49 4e 53 45 52 54 d int);. INSERT
3020: 20 49 4e 54 4f 20 74 31 30 28 61 2c 20 62 2c 20 INTO t10(a, b,
3030: 63 2c 20 64 29 20 56 41 4c 55 45 53 28 30 2c 20 c, d) VALUES(0,
3040: 30 2c 20 32 2c 20 32 29 3b 0a 20 20 49 4e 53 45 0, 2, 2);. INSE
3050: 52 54 20 49 4e 54 4f 20 74 31 30 28 61 2c 20 62 RT INTO t10(a, b
3060: 2c 20 63 2c 20 64 29 20 56 41 4c 55 45 53 28 30 , c, d) VALUES(0
3070: 2c 20 30 2c 20 30 2c 20 30 29 3b 0a 20 20 49 4e , 0, 0, 0);. IN
3080: 53 45 52 54 20 49 4e 54 4f 20 74 31 30 28 61 2c SERT INTO t10(a,
3090: 20 62 2c 20 63 2c 20 64 29 20 56 41 4c 55 45 53 b, c, d) VALUES
30a0: 28 30 2c 20 30 2c 20 31 2c 20 31 29 3b 0a 20 20 (0, 0, 1, 1);.
30b0: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 30 28 INSERT INTO t10(
30c0: 61 2c 20 62 2c 20 63 2c 20 64 29 20 56 41 4c 55 a, b, c, d) VALU
30d0: 45 53 28 31 2c 20 31 2c 20 31 2c 20 31 29 3b 0a ES(1, 1, 1, 1);.
30e0: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 INSERT INTO t1
30f0: 30 28 61 2c 20 62 2c 20 63 2c 20 64 29 20 56 41 0(a, b, c, d) VA
3100: 4c 55 45 53 28 31 2c 20 31 2c 20 30 2c 20 30 29 LUES(1, 1, 0, 0)
3110: 3b 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 ;. INSERT INTO
3120: 74 31 30 28 61 2c 20 62 2c 20 63 2c 20 64 29 20 t10(a, b, c, d)
3130: 56 41 4c 55 45 53 28 32 2c 20 32 2c 20 30 2c 20 VALUES(2, 2, 0,
3140: 30 29 3b 0a 0a 20 20 53 45 4c 45 43 54 20 61 2b 0);.. SELECT a+
3150: 62 2c 20 63 2b 64 20 46 52 4f 4d 20 74 31 30 20 b, c+d FROM t10
3160: 4f 52 44 45 52 20 42 59 20 61 2b 62 2c 20 63 2b ORDER BY a+b, c+
3170: 64 3b 0a 7d 20 7b 0a 20 20 30 20 30 20 30 20 32 d;.} {. 0 0 0 2
3180: 20 30 20 34 20 32 20 30 20 32 20 32 20 34 20 30 0 4 2 0 2 2 4 0
3190: 0a 7d 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 .}.do_execsql_te
31a0: 73 74 20 69 6e 64 65 78 65 78 70 72 31 2d 31 32 st indexexpr1-12
31b0: 30 30 2e 31 20 7b 0a 20 20 43 52 45 41 54 45 20 00.1 {. CREATE
31c0: 49 4e 44 45 58 20 74 31 30 5f 61 62 20 4f 4e 20 INDEX t10_ab ON
31d0: 74 31 30 28 61 2b 62 29 3b 0a 7d 0a 64 6f 5f 65 t10(a+b);.}.do_e
31e0: 78 65 63 73 71 6c 5f 74 65 73 74 20 69 6e 64 65 xecsql_test inde
31f0: 78 65 78 70 72 31 2d 31 32 30 30 2e 32 20 7b 0a xexpr1-1200.2 {.
3200: 20 20 53 45 4c 45 43 54 20 61 2b 62 2c 20 63 2b SELECT a+b, c+
3210: 64 20 46 52 4f 4d 20 74 31 30 20 4f 52 44 45 52 d FROM t10 ORDER
3220: 20 42 59 20 61 2b 62 2c 20 63 2b 64 3b 0a 7d 20 BY a+b, c+d;.}
3230: 7b 0a 20 20 30 20 30 20 30 20 32 20 30 20 34 20 {. 0 0 0 2 0 4
3240: 32 20 30 20 32 20 32 20 34 20 30 0a 7d 0a 64 6f 2 0 2 2 4 0.}.do
3250: 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 69 6e _execsql_test in
3260: 64 65 78 65 78 70 72 31 2d 31 32 30 30 2e 33 20 dexexpr1-1200.3
3270: 7b 0a 20 20 43 52 45 41 54 45 20 49 4e 44 45 58 {. CREATE INDEX
3280: 20 74 31 30 5f 61 62 63 64 20 4f 4e 20 74 31 30 t10_abcd ON t10
3290: 28 61 2b 62 2c 63 2b 64 29 3b 0a 7d 0a 64 6f 5f (a+b,c+d);.}.do_
32a0: 65 78 65 63 73 71 6c 5f 74 65 73 74 20 69 6e 64 execsql_test ind
32b0: 65 78 65 78 70 72 31 2d 31 32 30 30 2e 34 20 7b exexpr1-1200.4 {
32c0: 0a 20 20 53 45 4c 45 43 54 20 61 2b 62 2c 20 63 . SELECT a+b, c
32d0: 2b 64 20 46 52 4f 4d 20 74 31 30 20 4f 52 44 45 +d FROM t10 ORDE
32e0: 52 20 42 59 20 61 2b 62 2c 20 63 2b 64 3b 0a 7d R BY a+b, c+d;.}
32f0: 20 7b 0a 20 20 30 20 30 20 30 20 32 20 30 20 34 {. 0 0 0 2 0 4
3300: 20 32 20 30 20 32 20 32 20 34 20 30 0a 7d 0a 0a 2 0 2 2 4 0.}..
3310: 23 20 54 69 63 6b 65 74 20 68 74 74 70 73 3a 2f # Ticket https:/
3320: 2f 77 77 77 2e 73 71 6c 69 74 65 2e 6f 72 67 2f /www.sqlite.org/
3330: 73 72 63 2f 74 6b 74 76 69 65 77 2f 65 62 37 30 src/tktview/eb70
3340: 33 62 61 37 62 35 30 63 31 61 0a 23 20 49 6e 63 3ba7b50c1a.# Inc
3350: 6f 72 72 65 63 74 20 72 65 73 75 6c 74 20 75 73 orrect result us
3360: 69 6e 67 20 61 6e 20 69 6e 64 65 78 20 6f 6e 20 ing an index on
3370: 61 6e 20 65 78 70 72 65 73 73 69 6f 6e 20 77 69 an expression wi
3380: 74 68 20 61 20 63 6f 6c 6c 61 74 69 6e 67 20 66 th a collating f
3390: 75 6e 63 74 69 6f 6e 0a 23 0a 64 6f 5f 65 78 65 unction.#.do_exe
33a0: 63 73 71 6c 5f 74 65 73 74 20 69 6e 64 65 78 65 csql_test indexe
33b0: 78 70 72 31 2d 31 33 30 30 2e 31 20 7b 0a 20 20 xpr1-1300.1 {.
33c0: 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 31 33 CREATE TABLE t13
33d0: 30 30 28 61 20 49 4e 54 45 47 45 52 20 50 52 49 00(a INTEGER PRI
33e0: 4d 41 52 59 20 4b 45 59 2c 20 62 29 3b 0a 20 20 MARY KEY, b);.
33f0: 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 33 30 INSERT INTO t130
3400: 30 20 56 41 4c 55 45 53 28 31 2c 27 63 6f 66 66 0 VALUES(1,'coff
3410: 65 65 27 29 2c 28 32 2c 27 43 4f 46 46 45 45 27 ee'),(2,'COFFEE'
3420: 29 2c 28 33 2c 27 73 74 72 65 73 73 27 29 2c 28 ),(3,'stress'),(
3430: 34 2c 27 53 54 52 45 53 53 27 29 3b 0a 20 20 43 4,'STRESS');. C
3440: 52 45 41 54 45 20 49 4e 44 45 58 20 74 31 33 30 REATE INDEX t130
3450: 30 62 65 78 70 72 20 4f 4e 20 74 31 33 30 30 28 0bexpr ON t1300(
3460: 20 73 75 62 73 74 72 28 62 2c 34 29 20 29 3b 0a substr(b,4) );.
3470: 20 20 53 45 4c 45 43 54 20 61 20 46 52 4f 4d 20 SELECT a FROM
3480: 74 31 33 30 30 20 57 48 45 52 45 20 73 75 62 73 t1300 WHERE subs
3490: 74 72 28 62 2c 34 29 3d 27 65 73 73 27 20 43 4f tr(b,4)='ess' CO
34a0: 4c 4c 41 54 45 20 6e 6f 63 61 73 65 20 4f 52 44 LLATE nocase ORD
34b0: 45 52 20 42 59 20 2b 61 3b 0a 7d 20 7b 33 20 34 ER BY +a;.} {3 4
34c0: 7d 0a 0a 23 20 54 69 63 6b 65 74 20 68 74 74 70 }..# Ticket http
34d0: 73 3a 2f 2f 73 71 6c 69 74 65 2e 6f 72 67 2f 73 s://sqlite.org/s
34e0: 72 63 2f 74 6b 74 76 69 65 77 2f 61 61 39 38 36 rc/tktview/aa986
34f0: 31 39 61 0a 23 20 41 73 73 65 72 74 69 6f 6e 20 19a.# Assertion
3500: 66 61 75 6c 74 20 75 73 69 6e 67 20 61 6e 20 69 fault using an i
3510: 6e 64 65 78 20 6f 6e 20 61 20 63 6f 6e 73 74 61 ndex on a consta
3520: 6e 74 0a 23 0a 64 6f 5f 65 78 65 63 73 71 6c 5f nt.#.do_execsql_
3530: 74 65 73 74 20 69 6e 64 65 78 65 78 70 72 31 2d test indexexpr1-
3540: 31 34 30 30 20 7b 0a 20 20 43 52 45 41 54 45 20 1400 {. CREATE
3550: 54 41 42 4c 45 20 74 31 34 30 30 28 78 20 54 45 TABLE t1400(x TE
3560: 58 54 29 3b 0a 20 20 43 52 45 41 54 45 20 49 4e XT);. CREATE IN
3570: 44 45 58 20 74 31 34 30 30 78 20 4f 4e 20 74 31 DEX t1400x ON t1
3580: 34 30 30 28 31 29 3b 20 20 2d 2d 20 49 6e 64 65 400(1); -- Inde
3590: 78 20 6f 6e 20 61 20 63 6f 6e 73 74 61 6e 74 0a x on a constant.
35a0: 20 20 53 45 4c 45 43 54 20 31 20 49 4e 20 28 53 SELECT 1 IN (S
35b0: 45 4c 45 43 54 20 32 29 20 46 52 4f 4d 20 74 31 ELECT 2) FROM t1
35c0: 34 30 30 3b 0a 7d 20 7b 7d 0a 64 6f 5f 65 78 65 400;.} {}.do_exe
35d0: 63 73 71 6c 5f 74 65 73 74 20 69 6e 64 65 78 65 csql_test indexe
35e0: 78 70 72 31 2d 31 34 31 30 20 7b 0a 20 20 49 4e xpr1-1410 {. IN
35f0: 53 45 52 54 20 49 4e 54 4f 20 74 31 34 30 30 20 SERT INTO t1400
3600: 56 41 4c 55 45 53 28 27 61 27 29 2c 28 27 62 27 VALUES('a'),('b'
3610: 29 3b 0a 20 20 53 45 4c 45 43 54 20 31 20 49 4e );. SELECT 1 IN
3620: 20 28 53 45 4c 45 43 54 20 32 29 20 46 52 4f 4d (SELECT 2) FROM
3630: 20 74 31 34 30 30 3b 0a 7d 20 7b 30 20 30 7d 0a t1400;.} {0 0}.
3640: 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 do_execsql_test
3650: 69 6e 64 65 78 65 78 70 72 31 2d 31 34 32 30 20 indexexpr1-1420
3660: 7b 0a 20 20 53 45 4c 45 43 54 20 31 20 49 4e 20 {. SELECT 1 IN
3670: 28 53 45 4c 45 43 54 20 32 20 55 4e 49 4f 4e 20 (SELECT 2 UNION
3680: 41 4c 4c 20 53 45 4c 45 43 54 20 31 29 20 46 52 ALL SELECT 1) FR
3690: 4f 4d 20 74 31 34 30 30 3b 0a 7d 20 7b 31 20 31 OM t1400;.} {1 1
36a0: 7d 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 65 73 }.do_execsql_tes
36b0: 74 20 69 6e 64 65 78 65 78 70 72 31 2d 31 34 33 t indexexpr1-143
36c0: 30 20 7b 0a 20 20 44 52 4f 50 20 49 4e 44 45 58 0 {. DROP INDEX
36d0: 20 74 31 34 30 30 78 3b 0a 20 20 43 52 45 41 54 t1400x;. CREAT
36e0: 45 20 49 4e 44 45 58 20 74 31 34 30 30 78 20 4f E INDEX t1400x O
36f0: 4e 20 74 31 34 30 30 28 61 62 73 28 31 35 2b 33 N t1400(abs(15+3
3700: 29 29 3b 0a 20 20 53 45 4c 45 43 54 20 61 62 73 ));. SELECT abs
3710: 28 31 35 2b 33 29 20 49 4e 20 28 53 45 4c 45 43 (15+3) IN (SELEC
3720: 54 20 31 37 20 55 4e 49 4f 4e 20 41 4c 4c 20 53 T 17 UNION ALL S
3730: 45 4c 45 43 54 20 31 38 29 20 46 52 4f 4d 20 74 ELECT 18) FROM t
3740: 31 3b 0a 7d 20 7b 31 20 31 7d 0a 0a 23 20 32 30 1;.} {1 1}..# 20
3750: 31 38 2d 30 31 2d 30 32 20 74 69 63 6b 65 74 20 18-01-02 ticket
3760: 68 74 74 70 73 3a 2f 2f 73 71 6c 69 74 65 2e 6f https://sqlite.o
3770: 72 67 2f 73 72 63 2f 69 6e 66 6f 2f 64 63 33 66 rg/src/info/dc3f
3780: 39 33 32 66 35 61 31 34 37 37 37 31 0a 23 20 41 932f5a147771.# A
3790: 20 52 45 50 4c 41 43 45 20 69 6e 74 6f 20 61 20 REPLACE into a
37a0: 74 61 62 6c 65 20 74 68 61 74 20 75 73 65 73 20 table that uses
37b0: 61 6e 20 69 6e 64 65 78 20 6f 6e 20 61 6e 20 65 an index on an e
37c0: 78 70 72 65 73 73 69 6f 6e 20 63 61 75 73 65 73 xpression causes
37d0: 0a 23 20 61 6e 20 61 73 73 65 72 74 69 6f 6e 20 .# an assertion
37e0: 66 61 75 6c 74 2e 20 20 50 72 6f 62 6c 65 6d 20 fault. Problem
37f0: 64 69 73 63 6f 76 65 72 65 64 20 62 79 20 4f 53 discovered by OS
3800: 53 46 75 7a 7a 2e 0a 23 0a 64 6f 5f 65 78 65 63 SFuzz..#.do_exec
3810: 73 71 6c 5f 74 65 73 74 20 69 6e 64 65 78 65 78 sql_test indexex
3820: 70 72 31 2d 31 35 30 30 20 7b 0a 20 20 43 52 45 pr1-1500 {. CRE
3830: 41 54 45 20 54 41 42 4c 45 20 74 31 35 30 30 28 ATE TABLE t1500(
3840: 61 20 49 4e 54 20 50 52 49 4d 41 52 59 20 4b 45 a INT PRIMARY KE
3850: 59 2c 20 62 20 49 4e 54 20 55 4e 49 51 55 45 29 Y, b INT UNIQUE)
3860: 3b 0a 20 20 43 52 45 41 54 45 20 49 4e 44 45 58 ;. CREATE INDEX
3870: 20 74 31 35 30 30 61 62 20 4f 4e 20 74 31 35 30 t1500ab ON t150
3880: 30 28 61 2a 62 29 3b 0a 20 20 49 4e 53 45 52 54 0(a*b);. INSERT
3890: 20 49 4e 54 4f 20 74 31 35 30 30 28 61 2c 62 29 INTO t1500(a,b)
38a0: 20 56 41 4c 55 45 53 28 31 2c 32 29 3b 0a 20 20 VALUES(1,2);.
38b0: 52 45 50 4c 41 43 45 20 49 4e 54 4f 20 74 31 35 REPLACE INTO t15
38c0: 30 30 28 61 2c 62 29 20 56 41 4c 55 45 53 28 31 00(a,b) VALUES(1
38d0: 2c 33 29 3b 20 20 2d 2d 20 66 6f 72 6d 65 72 6c ,3); -- formerl
38e0: 79 20 63 61 75 73 65 64 20 61 73 73 65 72 74 69 y caused asserti
38f0: 6f 6e 20 66 61 75 6c 74 0a 20 20 53 45 4c 45 43 on fault. SELEC
3900: 54 20 2a 20 46 52 4f 4d 20 74 31 35 30 30 3b 0a T * FROM t1500;.
3910: 7d 20 7b 31 20 33 7d 0a 0a 23 20 32 30 31 38 2d } {1 3}..# 2018-
3920: 30 31 2d 30 33 20 4f 53 53 46 75 7a 7a 20 64 69 01-03 OSSFuzz di
3930: 73 63 6f 76 65 72 73 20 61 6e 6f 74 68 65 72 20 scovers another
3940: 74 65 73 74 20 63 61 73 65 20 66 6f 72 20 74 68 test case for th
3950: 65 20 73 61 6d 65 20 70 72 6f 62 6c 65 6d 0a 23 e same problem.#
3960: 20 61 62 6f 76 65 2e 0a 23 0a 64 6f 5f 65 78 65 above..#.do_exe
3970: 63 73 71 6c 5f 74 65 73 74 20 69 6e 64 65 78 65 csql_test indexe
3980: 78 70 72 2d 31 35 31 30 20 7b 0a 20 20 44 52 4f xpr-1510 {. DRO
3990: 50 20 54 41 42 4c 45 20 49 46 20 45 58 49 53 54 P TABLE IF EXIST
39a0: 53 20 74 31 3b 0a 20 20 43 52 45 41 54 45 20 54 S t1;. CREATE T
39b0: 41 42 4c 45 20 74 31 28 61 20 50 52 49 4d 41 52 ABLE t1(a PRIMAR
39c0: 59 20 4b 45 59 2c 62 20 55 4e 49 51 55 45 29 3b Y KEY,b UNIQUE);
39d0: 0a 20 20 52 45 50 4c 41 43 45 20 49 4e 54 4f 20 . REPLACE INTO
39e0: 74 31 20 56 41 4c 55 45 53 28 32 2c 20 31 29 3b t1 VALUES(2, 1);
39f0: 0a 20 20 52 45 50 4c 41 43 45 20 49 4e 54 4f 20 . REPLACE INTO
3a00: 74 31 20 53 45 4c 45 43 54 20 36 2c 31 3b 0a 20 t1 SELECT 6,1;.
3a10: 20 43 52 45 41 54 45 20 49 4e 44 45 58 20 74 31 CREATE INDEX t1
3a20: 61 61 20 4f 4e 20 74 31 28 61 2d 61 29 3b 0a 20 aa ON t1(a-a);.
3a30: 20 52 45 50 4c 41 43 45 20 49 4e 54 4f 20 74 31 REPLACE INTO t1
3a40: 20 53 45 4c 45 43 54 20 61 2c 20 72 61 6e 64 6f SELECT a, rando
3a50: 6d 62 6c 6f 62 28 61 29 20 46 52 4f 4d 20 74 31 mblob(a) FROM t1
3a60: 0a 7d 20 7b 7d 0a 0a 23 20 32 30 31 38 2d 30 31 .} {}..# 2018-01
3a70: 2d 33 31 20 68 74 74 70 73 3a 2f 2f 77 77 77 2e -31 https://www.
3a80: 73 71 6c 69 74 65 2e 6f 72 67 2f 73 72 63 2f 74 sqlite.org/src/t
3a90: 6b 74 76 69 65 77 2f 33 34 33 36 33 34 39 34 32 ktview/343634942
3aa0: 64 64 35 34 61 62 35 37 62 37 30 32 34 31 31 0a dd54ab57b702411.
3ab0: 23 20 57 68 65 6e 20 61 6e 20 69 6e 64 65 78 20 # When an index
3ac0: 6f 6e 20 61 6e 20 65 78 70 72 65 73 73 69 6f 6e on an expression
3ad0: 20 64 65 70 65 6e 64 73 20 6f 6e 20 74 68 65 20 depends on the
3ae0: 73 74 72 69 6e 67 20 72 65 70 72 65 73 65 6e 74 string represent
3af0: 61 74 69 6f 6e 20 6f 66 0a 23 20 61 20 6e 75 6d ation of.# a num
3b00: 65 72 69 63 20 74 61 62 6c 65 20 63 6f 6c 75 6d eric table colum
3b10: 6e 2c 20 74 72 6f 75 62 6c 65 20 63 61 6e 20 61 n, trouble can a
3b20: 72 69 73 65 20 73 69 6e 63 65 20 74 68 65 72 65 rise since there
3b30: 20 61 72 65 20 6d 75 6c 74 69 70 6c 65 0a 23 20 are multiple.#
3b40: 73 74 72 69 6e 67 20 74 68 61 74 20 63 61 6e 20 string that can
3b50: 6d 61 70 20 74 6f 20 74 68 65 20 73 61 6d 65 20 map to the same
3b60: 6e 75 6d 65 72 69 63 20 76 61 6c 75 65 2e 20 20 numeric value.
3b70: 28 45 78 3a 20 31 32 33 2c 20 30 31 32 33 2c 20 (Ex: 123, 0123,
3b80: 30 30 30 31 32 33 29 2e 0a 23 0a 64 6f 5f 65 78 000123)..#.do_ex
3b90: 65 63 73 71 6c 5f 74 65 73 74 20 69 6e 64 65 78 ecsql_test index
3ba0: 65 78 70 72 2d 31 36 30 30 20 7b 0a 20 20 44 52 expr-1600 {. DR
3bb0: 4f 50 20 54 41 42 4c 45 20 49 46 20 45 58 49 53 OP TABLE IF EXIS
3bc0: 54 53 20 74 31 3b 0a 20 20 43 52 45 41 54 45 20 TS t1;. CREATE
3bd0: 54 41 42 4c 45 20 74 31 20 28 61 20 49 4e 54 45 TABLE t1 (a INTE
3be0: 47 45 52 2c 20 62 29 3b 0a 20 20 43 52 45 41 54 GER, b);. CREAT
3bf0: 45 20 49 4e 44 45 58 20 69 64 78 31 20 4f 4e 20 E INDEX idx1 ON
3c00: 74 31 20 28 6c 6f 77 65 72 28 61 29 29 3b 0a 20 t1 (lower(a));.
3c10: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20 INSERT INTO t1
3c20: 56 41 4c 55 45 53 28 27 30 30 30 31 32 33 34 27 VALUES('0001234'
3c30: 2c 33 29 3b 0a 20 20 50 52 41 47 4d 41 20 69 6e ,3);. PRAGMA in
3c40: 74 65 67 72 69 74 79 5f 63 68 65 63 6b 3b 0a 7d tegrity_check;.}
3c50: 20 7b 6f 6b 7d 0a 64 6f 5f 65 78 65 63 73 71 6c {ok}.do_execsql
3c60: 5f 74 65 73 74 20 69 6e 64 65 78 65 78 70 72 2d _test indexexpr-
3c70: 31 36 31 30 20 7b 0a 20 20 49 4e 53 45 52 54 20 1610 {. INSERT
3c80: 49 4e 54 4f 20 74 31 20 56 41 4c 55 45 53 28 27 INTO t1 VALUES('
3c90: 31 32 33 34 27 2c 30 29 2c 28 27 30 30 31 32 33 1234',0),('00123
3ca0: 34 27 2c 32 29 2c 28 27 30 31 32 33 34 27 2c 31 4',2),('01234',1
3cb0: 29 3b 0a 20 20 53 45 4c 45 43 54 20 62 20 46 52 );. SELECT b FR
3cc0: 4f 4d 20 74 31 20 57 48 45 52 45 20 6c 6f 77 65 OM t1 WHERE lowe
3cd0: 72 28 61 29 3d 27 31 32 33 34 27 20 4f 52 44 45 r(a)='1234' ORDE
3ce0: 52 20 42 59 20 2b 62 3b 0a 7d 20 7b 30 20 31 20 R BY +b;.} {0 1
3cf0: 32 20 33 7d 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 2 3}.do_execsql_
3d00: 74 65 73 74 20 69 6e 64 65 78 65 78 70 72 2d 31 test indexexpr-1
3d10: 36 32 30 20 7b 0a 20 20 53 45 4c 45 43 54 20 62 620 {. SELECT b
3d20: 20 46 52 4f 4d 20 74 31 20 57 48 45 52 45 20 6c FROM t1 WHERE l
3d30: 6f 77 65 72 28 61 29 3d 27 30 31 32 33 34 27 20 ower(a)='01234'
3d40: 4f 52 44 45 52 20 42 59 20 2b 62 3b 0a 7d 20 7b ORDER BY +b;.} {
3d50: 7d 0a 0a 23 20 32 30 31 39 2d 30 38 2d 30 39 20 }..# 2019-08-09
3d60: 68 74 74 70 73 3a 2f 2f 77 77 77 2e 73 71 6c 69 https://www.sqli
3d70: 74 65 2e 6f 72 67 2f 73 72 63 2f 69 6e 66 6f 2f te.org/src/info/
3d80: 39 30 38 30 62 36 32 32 37 66 61 62 62 34 36 36 9080b6227fabb466
3d90: 0a 23 20 45 78 70 72 49 6d 70 6c 69 65 73 45 78 .# ExprImpliesEx
3da0: 70 72 20 74 68 65 6f 72 65 6d 20 70 72 6f 76 65 pr theorem prove
3db0: 72 20 62 75 67 3a 0a 23 20 22 28 4e 55 4c 4c 20 r bug:.# "(NULL
3dc0: 49 53 20 46 41 4c 53 45 29 20 49 53 20 46 41 4c IS FALSE) IS FAL
3dd0: 53 45 22 20 64 6f 65 73 20 6e 6f 74 20 69 6d 70 SE" does not imp
3de0: 6c 79 20 22 4e 55 4c 4c 20 49 53 20 4e 55 4c 4c ly "NULL IS NULL
3df0: 22 0a 23 0a 64 6f 5f 65 78 65 63 73 71 6c 5f 74 ".#.do_execsql_t
3e00: 65 73 74 20 69 6e 64 65 78 65 78 70 72 2d 31 37 est indexexpr-17
3e10: 30 30 20 7b 0a 20 20 44 52 4f 50 20 54 41 42 4c 00 {. DROP TABL
3e20: 45 20 49 46 20 45 58 49 53 54 53 20 74 30 3b 0a E IF EXISTS t0;.
3e30: 20 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 74 CREATE TABLE t
3e40: 30 28 63 30 29 3b 0a 20 20 49 4e 53 45 52 54 20 0(c0);. INSERT
3e50: 49 4e 54 4f 20 74 30 28 63 30 29 20 56 41 4c 55 INTO t0(c0) VALU
3e60: 45 53 20 28 30 29 3b 0a 20 20 43 52 45 41 54 45 ES (0);. CREATE
3e70: 20 49 4e 44 45 58 20 69 30 20 4f 4e 20 74 30 28 INDEX i0 ON t0(
3e80: 4e 55 4c 4c 20 3e 20 63 30 29 20 57 48 45 52 45 NULL > c0) WHERE
3e90: 20 28 4e 55 4c 4c 20 4e 4f 54 20 4e 55 4c 4c 29 (NULL NOT NULL)
3ea0: 3b 0a 20 20 53 45 4c 45 43 54 20 2a 20 46 52 4f ;. SELECT * FRO
3eb0: 4d 20 74 30 20 57 48 45 52 45 20 28 28 4e 55 4c M t0 WHERE ((NUL
3ec0: 4c 20 49 53 20 46 41 4c 53 45 29 20 49 53 20 46 L IS FALSE) IS F
3ed0: 41 4c 53 45 29 3b 0a 7d 20 7b 30 7d 0a 0a 23 20 ALSE);.} {0}..#
3ee0: 32 30 31 39 2d 30 39 2d 30 32 20 68 74 74 70 73 2019-09-02 https
3ef0: 3a 2f 2f 77 77 77 2e 73 71 6c 69 74 65 2e 6f 72 ://www.sqlite.or
3f00: 67 2f 73 72 63 2f 74 6b 74 76 69 65 77 2f 35 37 g/src/tktview/57
3f10: 61 66 30 30 62 36 36 34 32 65 63 64 36 38 34 38 af00b6642ecd6848
3f20: 0a 23 20 57 68 65 6e 20 74 68 65 20 65 78 70 72 .# When the expr
3f30: 65 73 73 69 6f 6e 20 6f 66 20 61 6e 20 61 6e 20 ession of an an
3f40: 69 6e 64 65 78 2d 6f 6e 2d 65 78 70 72 65 73 73 index-on-express
3f50: 69 6f 6e 20 72 65 66 65 72 65 6e 63 65 73 20 61 ion references a
3f60: 0a 23 20 74 61 62 6c 65 20 63 6f 6c 75 6d 6e 20 .# table column
3f70: 6f 66 20 74 79 70 65 20 52 45 41 4c 20 74 68 61 of type REAL tha
3f80: 74 20 69 73 20 61 63 74 75 61 6c 6c 79 20 68 6f t is actually ho
3f90: 6c 64 69 6e 67 20 61 6e 20 4d 45 4d 5f 49 6e 74 lding an MEM_Int
3fa0: 52 65 61 6c 0a 23 20 76 61 6c 75 65 2c 20 62 65 Real.# value, be
3fb0: 20 73 75 72 65 20 74 6f 20 75 73 65 20 74 68 65 sure to use the
3fc0: 20 52 45 41 4c 20 76 61 6c 75 65 20 61 6e 64 20 REAL value and
3fd0: 6e 6f 74 20 74 68 65 20 49 4e 54 20 76 61 6c 75 not the INT valu
3fe0: 65 20 77 68 65 6e 0a 23 20 63 6f 6d 70 75 74 69 e when.# computi
3ff0: 6e 67 20 74 68 65 20 65 78 70 72 65 73 73 69 6f ng the expressio
4000: 6e 2e 0a 23 0a 64 6f 5f 65 78 65 63 73 71 6c 5f n..#.do_execsql_
4010: 74 65 73 74 20 69 6e 64 65 78 65 78 70 72 2d 31 test indexexpr-1
4020: 38 30 30 20 7b 0a 20 20 44 52 4f 50 20 54 41 42 800 {. DROP TAB
4030: 4c 45 20 49 46 20 45 58 49 53 54 53 20 74 30 3b LE IF EXISTS t0;
4040: 0a 20 20 43 52 45 41 54 45 20 54 41 42 4c 45 20 . CREATE TABLE
4050: 74 30 28 63 30 20 52 45 41 4c 2c 20 63 31 20 54 t0(c0 REAL, c1 T
4060: 45 58 54 29 3b 0a 20 20 43 52 45 41 54 45 20 49 EXT);. CREATE I
4070: 4e 44 45 58 20 69 30 20 4f 4e 20 74 30 28 2b 63 NDEX i0 ON t0(+c
4080: 30 2c 20 63 30 29 3b 0a 20 20 49 4e 53 45 52 54 0, c0);. INSERT
4090: 20 49 4e 54 4f 20 74 30 28 63 30 29 20 56 41 4c INTO t0(c0) VAL
40a0: 55 45 53 28 30 29 3b 0a 20 20 53 45 4c 45 43 54 UES(0);. SELECT
40b0: 20 43 41 53 54 28 2b 20 74 30 2e 63 30 20 41 53 CAST(+ t0.c0 AS
40c0: 20 42 4c 4f 42 29 20 4c 49 4b 45 20 30 20 46 52 BLOB) LIKE 0 FR
40d0: 4f 4d 20 74 30 3b 20 0a 7d 20 7b 30 7d 0a 64 6f OM t0; .} {0}.do
40e0: 5f 65 78 65 63 73 71 6c 5f 74 65 73 74 20 69 6e _execsql_test in
40f0: 64 65 78 65 78 70 72 2d 31 38 31 30 20 7b 0a 20 dexexpr-1810 {.
4100: 20 53 45 4c 45 43 54 20 43 41 53 54 28 2b 20 74 SELECT CAST(+ t
4110: 30 2e 63 30 20 41 53 20 42 4c 4f 42 29 20 4c 49 0.c0 AS BLOB) LI
4120: 4b 45 20 27 30 2e 30 27 20 46 52 4f 4d 20 74 30 KE '0.0' FROM t0
4130: 3b 20 0a 7d 20 7b 31 7d 0a 64 6f 5f 65 78 65 63 ; .} {1}.do_exec
4140: 73 71 6c 5f 74 65 73 74 20 69 6e 64 65 78 65 78 sql_test indexex
4150: 70 72 2d 31 38 32 30 20 7b 0a 20 20 44 52 4f 50 pr-1820 {. DROP
4160: 20 54 41 42 4c 45 20 49 46 20 45 58 49 53 54 53 TABLE IF EXISTS
4170: 20 74 31 3b 0a 20 20 43 52 45 41 54 45 20 54 41 t1;. CREATE TA
4180: 42 4c 45 20 74 31 28 78 20 52 45 41 4c 29 3b 0a BLE t1(x REAL);.
4190: 20 20 43 52 45 41 54 45 20 49 4e 44 45 58 20 74 CREATE INDEX t
41a0: 31 78 20 4f 4e 20 74 31 28 78 2c 20 2b 78 29 3b 1x ON t1(x, +x);
41b0: 0a 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 . INSERT INTO t
41c0: 31 28 78 29 20 56 41 4c 55 45 53 28 32 29 3b 0a 1(x) VALUES(2);.
41d0: 20 20 53 45 4c 45 43 54 20 2b 78 20 46 52 4f 4d SELECT +x FROM
41e0: 20 74 31 20 57 48 45 52 45 20 78 3d 32 3b 0a 7d t1 WHERE x=2;.}
41f0: 20 7b 32 2e 30 7d 0a 0a 66 69 6e 69 73 68 5f 74 {2.0}..finish_t
4200: 65 73 74 0a est.