Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: third_party/sqlite/src/test/analyze5.test

Issue 949043002: Add //third_party/sqlite to dirs_to_snapshot, remove net_sql.patch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/sqlite/src/test/analyze4.test ('k') | third_party/sqlite/src/test/analyze6.test » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # 2011 January 19 1 # 2011 January 19
2 # 2 #
3 # The author disclaims copyright to this source code. In place of 3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing: 4 # a legal notice, here is a blessing:
5 # 5 #
6 # May you do good and not evil. 6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others. 7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give. 8 # May you share freely, never taking more than you give.
9 # 9 #
10 #*********************************************************************** 10 #***********************************************************************
11 # 11 #
12 # This file implements tests for SQLite library. The focus of the tests 12 # This file implements tests for SQLite library. The focus of the tests
13 # in this file is the use of the sqlite_stat2 histogram data on tables 13 # in this file is the use of the sqlite_stat4 histogram data on tables
14 # with many repeated values and only a few distinct values. 14 # with many repeated values and only a few distinct values.
15 # 15 #
16 16
17 set testdir [file dirname $argv0] 17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl 18 source $testdir/tester.tcl
19 19
20 ifcapable !stat2 { 20 ifcapable !stat4&&!stat3 {
21 finish_test 21 finish_test
22 return 22 return
23 } 23 }
24 24
25 set testprefix analyze5 25 set testprefix analyze5
26 26
27 proc eqp {sql {db db}} { 27 proc eqp {sql {db db}} {
28 uplevel execsql [list "EXPLAIN QUERY PLAN $sql"] $db 28 uplevel execsql [list "EXPLAIN QUERY PLAN $sql"] $db
29 } 29 }
30 30
31 proc alpha {blob} {
32 set ret ""
33 foreach c [split $blob {}] {
34 if {[string is alpha $c]} {append ret $c}
35 }
36 return $ret
37 }
38 db func alpha alpha
39
40 db func lindex lindex
41
31 unset -nocomplain i t u v w x y z 42 unset -nocomplain i t u v w x y z
32 do_test analyze5-1.0 { 43 do_test analyze5-1.0 {
33 db eval {CREATE TABLE t1(t,u,v TEXT COLLATE nocase,w,x,y,z)} 44 db eval {CREATE TABLE t1(t,u,v TEXT COLLATE nocase,w,x,y,z)}
34 for {set i 0} {$i < 1000} {incr i} { 45 for {set i 0} {$i < 1000} {incr i} {
35 set y [expr {$i>=25 && $i<=50}] 46 set y [expr {$i>=25 && $i<=50}]
36 set z [expr {($i>=400) + ($i>=700) + ($i>=875)}] 47 set z [expr {($i>=400) + ($i>=700) + ($i>=875)}]
37 set x $z 48 set x $z
38 set w $z 49 set w $z
39 set t [expr {$z+0.5}] 50 set t [expr {$z+0.5}]
40 switch $z { 51 switch $z {
41 0 {set u "alpha"; unset x} 52 0 {set u "alpha"; unset x}
42 1 {set u "bravo"} 53 1 {set u "bravo"}
43 2 {set u "charlie"} 54 2 {set u "charlie"}
44 3 {set u "delta"; unset w} 55 3 {set u "delta"; unset w}
45 } 56 }
46 if {$i%2} {set v $u} {set v [string toupper $u]} 57 if {$i%2} {set v $u} {set v [string toupper $u]}
47 db eval {INSERT INTO t1 VALUES($t,$u,$v,$w,$x,$y,$z)} 58 db eval {INSERT INTO t1 VALUES($t,$u,$v,$w,$x,$y,$z)}
48 } 59 }
49 db eval { 60 db eval {
50 CREATE INDEX t1t ON t1(t); -- 0.5, 1.5, 2.5, and 3.5 61 CREATE INDEX t1t ON t1(t); -- 0.5, 1.5, 2.5, and 3.5
51 CREATE INDEX t1u ON t1(u); -- text 62 CREATE INDEX t1u ON t1(u); -- text
52 CREATE INDEX t1v ON t1(v); -- mixed case text 63 CREATE INDEX t1v ON t1(v); -- mixed case text
53 CREATE INDEX t1w ON t1(w); -- integers 0, 1, 2 and a few NULLs 64 CREATE INDEX t1w ON t1(w); -- integers 0, 1, 2 and a few NULLs
54 CREATE INDEX t1x ON t1(x); -- integers 1, 2, 3 and many NULLs 65 CREATE INDEX t1x ON t1(x); -- integers 1, 2, 3 and many NULLs
55 CREATE INDEX t1y ON t1(y); -- integers 0 and very few 1s 66 CREATE INDEX t1y ON t1(y); -- integers 0 and very few 1s
56 CREATE INDEX t1z ON t1(z); -- integers 0, 1, 2, and 3 67 CREATE INDEX t1z ON t1(z); -- integers 0, 1, 2, and 3
57 ANALYZE; 68 ANALYZE;
58 SELECT sample FROM sqlite_stat2 WHERE idx='t1u' ORDER BY sampleno;
59 } 69 }
60 } {alpha alpha alpha alpha bravo bravo bravo charlie charlie delta} 70 ifcapable stat4 {
71 db eval {
72 SELECT DISTINCT lindex(test_decode(sample),0)
73 FROM sqlite_stat4 WHERE idx='t1u' ORDER BY nlt;
74 }
75 } else {
76 db eval {
77 SELECT sample FROM sqlite_stat3 WHERE idx='t1u' ORDER BY nlt;
78 }
79 }
80 } {alpha bravo charlie delta}
81
61 do_test analyze5-1.1 { 82 do_test analyze5-1.1 {
62 string tolower \ 83 ifcapable stat4 {
63 [db eval {SELECT sample from sqlite_stat2 WHERE idx='t1v' ORDER BY sampleno}] 84 db eval {
64 } {alpha alpha alpha alpha bravo bravo bravo charlie charlie delta} 85 SELECT DISTINCT lower(lindex(test_decode(sample), 0))
65 do_test analyze5-1.2 { 86 FROM sqlite_stat4 WHERE idx='t1v' ORDER BY 1
66 db eval {SELECT sample from sqlite_stat2 WHERE idx='t1w' ORDER BY sampleno} 87 }
67 } {{} 0 0 0 0 1 1 1 2 2} 88 } else {
68 do_test analyze5-1.3 { 89 db eval {
69 db eval {SELECT sample from sqlite_stat2 WHERE idx='t1x' ORDER BY sampleno} 90 SELECT lower(sample) FROM sqlite_stat3 WHERE idx='t1v' ORDER BY 1
70 } {{} {} {} {} 1 1 1 2 2 3} 91 }
71 do_test analyze5-1.4 { 92 }
72 db eval {SELECT sample from sqlite_stat2 WHERE idx='t1y' ORDER BY sampleno} 93 } {alpha bravo charlie delta}
73 } {0 0 0 0 0 0 0 0 0 0} 94 ifcapable stat4 {
74 do_test analyze5-1.5 { 95 do_test analyze5-1.2 {
75 db eval {SELECT sample from sqlite_stat2 WHERE idx='t1z' ORDER BY sampleno} 96 db eval {SELECT idx, count(*) FROM sqlite_stat4 GROUP BY 1 ORDER BY 1}
76 } {0 0 0 0 1 1 1 2 2 3} 97 } {t1t 8 t1u 8 t1v 8 t1w 8 t1x 8 t1y 9 t1z 8}
77 do_test analyze5-1.6 { 98 } else {
78 db eval {SELECT sample from sqlite_stat2 WHERE idx='t1t' ORDER BY sampleno} 99 do_test analyze5-1.2 {
79 } {0.5 0.5 0.5 0.5 1.5 1.5 1.5 2.5 2.5 3.5} 100 db eval {SELECT idx, count(*) FROM sqlite_stat3 GROUP BY 1 ORDER BY 1}
80 101 } {t1t 4 t1u 4 t1v 4 t1w 4 t1x 4 t1y 2 t1z 4}
102 }
81 103
82 # Verify that range queries generate the correct row count estimates 104 # Verify that range queries generate the correct row count estimates
83 # 105 #
84 foreach {testid where index rows} { 106 foreach {testid where index rows} {
85 1 {z>=0 AND z<=0} t1z 400 107 1 {z>=0 AND z<=0} t1z 400
86 2 {z>=1 AND z<=1} t1z 300 108 2 {z>=1 AND z<=1} t1z 300
87 3 {z>=2 AND z<=2} t1z 200 109 3 {z>=2 AND z<=2} t1z 175
88 4 {z>=3 AND z<=3} t1z 100 110 4 {z>=3 AND z<=3} t1z 125
89 5 {z>=4 AND z<=4} t1z 50 111 5 {z>=4 AND z<=4} t1z 1
90 6 {z>=-1 AND z<=-1} t1z 50 112 6 {z>=-1 AND z<=-1} t1z 1
91 7 {z>1 AND z<3} t1z 200 113 7 {z>1 AND z<3} t1z 175
92 8 {z>0 AND z<100} t1z 600 114 8 {z>0 AND z<100} t1z 600
93 9 {z>=1 AND z<100} t1z 600 115 9 {z>=1 AND z<100} t1z 600
94 10 {z>1 AND z<100} t1z 300 116 10 {z>1 AND z<100} t1z 300
95 11 {z>=2 AND z<100} t1z 300 117 11 {z>=2 AND z<100} t1z 300
96 12 {z>2 AND z<100} t1z 100 118 12 {z>2 AND z<100} t1z 125
97 13 {z>=3 AND z<100} t1z 100 119 13 {z>=3 AND z<100} t1z 125
98 14 {z>3 AND z<100} t1z 50 120 14 {z>3 AND z<100} t1z 1
99 15 {z>=4 AND z<100} t1z 50 121 15 {z>=4 AND z<100} t1z 1
100 16 {z>=-100 AND z<=-1} t1z 50 122 16 {z>=-100 AND z<=-1} t1z 1
101 17 {z>=-100 AND z<=0} t1z 400 123 17 {z>=-100 AND z<=0} t1z 400
102 18 {z>=-100 AND z<0} t1z 50 124 18 {z>=-100 AND z<0} t1z 1
103 19 {z>=-100 AND z<=1} t1z 700 125 19 {z>=-100 AND z<=1} t1z 700
104 20 {z>=-100 AND z<2} t1z 700 126 20 {z>=-100 AND z<2} t1z 700
105 21 {z>=-100 AND z<=2} t1z 900 127 21 {z>=-100 AND z<=2} t1z 875
106 22 {z>=-100 AND z<3} t1z 900 128 22 {z>=-100 AND z<3} t1z 875
107 129
108 31 {z>=0.0 AND z<=0.0} t1z 400 130 31 {z>=0.0 AND z<=0.0} t1z 400
109 32 {z>=1.0 AND z<=1.0} t1z 300 131 32 {z>=1.0 AND z<=1.0} t1z 300
110 33 {z>=2.0 AND z<=2.0} t1z 200 132 33 {z>=2.0 AND z<=2.0} t1z 175
111 34 {z>=3.0 AND z<=3.0} t1z 100 133 34 {z>=3.0 AND z<=3.0} t1z 125
112 35 {z>=4.0 AND z<=4.0} t1z 50 134 35 {z>=4.0 AND z<=4.0} t1z 1
113 36 {z>=-1.0 AND z<=-1.0} t1z 50 135 36 {z>=-1.0 AND z<=-1.0} t1z 1
114 37 {z>1.5 AND z<3.0} t1z 200 136 37 {z>1.5 AND z<3.0} t1z 174
115 38 {z>0.5 AND z<100} t1z 600 137 38 {z>0.5 AND z<100} t1z 599
116 39 {z>=1.0 AND z<100} t1z 600 138 39 {z>=1.0 AND z<100} t1z 600
117 40 {z>1.5 AND z<100} t1z 300 139 40 {z>1.5 AND z<100} t1z 299
118 41 {z>=2.0 AND z<100} t1z 300 140 41 {z>=2.0 AND z<100} t1z 300
119 42 {z>2.1 AND z<100} t1z 100 141 42 {z>2.1 AND z<100} t1z 124
120 43 {z>=3.0 AND z<100} t1z 100 142 43 {z>=3.0 AND z<100} t1z 125
121 44 {z>3.2 AND z<100} t1z 50 143 44 {z>3.2 AND z<100} t1z 1
122 45 {z>=4.0 AND z<100} t1z 50 144 45 {z>=4.0 AND z<100} t1z 1
123 46 {z>=-100 AND z<=-1.0} t1z 50 145 46 {z>=-100 AND z<=-1.0} t1z 1
124 47 {z>=-100 AND z<=0.0} t1z 400 146 47 {z>=-100 AND z<=0.0} t1z 400
125 48 {z>=-100 AND z<0.0} t1z 50 147 48 {z>=-100 AND z<0.0} t1z 1
126 49 {z>=-100 AND z<=1.0} t1z 700 148 49 {z>=-100 AND z<=1.0} t1z 700
127 50 {z>=-100 AND z<2.0} t1z 700 149 50 {z>=-100 AND z<2.0} t1z 700
128 51 {z>=-100 AND z<=2.0} t1z 900 150 51 {z>=-100 AND z<=2.0} t1z 875
129 52 {z>=-100 AND z<3.0} t1z 900 151 52 {z>=-100 AND z<3.0} t1z 875
130 152
131 101 {z=-1} t1z 50 153 101 {z=-1} t1z 1
132 102 {z=0} t1z 400 154 102 {z=0} t1z 400
133 103 {z=1} t1z 300 155 103 {z=1} t1z 300
134 104 {z=2} t1z 200 156 104 {z=2} t1z 175
135 105 {z=3} t1z 100 157 105 {z=3} t1z 125
136 106 {z=4} t1z 50 158 106 {z=4} t1z 1
137 107 {z=-10.0} t1z 50 159 107 {z=-10.0} t1z 1
138 108 {z=0.0} t1z 400 160 108 {z=0.0} t1z 400
139 109 {z=1.0} t1z 300 161 109 {z=1.0} t1z 300
140 110 {z=2.0} t1z 200 162 110 {z=2.0} t1z 175
141 111 {z=3.0} t1z 100 163 111 {z=3.0} t1z 125
142 112 {z=4.0} t1z 50 164 112 {z=4.0} t1z 1
143 113 {z=1.5} t1z 50 165 113 {z=1.5} t1z 1
144 114 {z=2.5} t1z 50 166 114 {z=2.5} t1z 1
145 167
146 201 {z IN (-1)} t1z 50 168 201 {z IN (-1)} t1z 1
147 202 {z IN (0)} t1z 400 169 202 {z IN (0)} t1z 400
148 203 {z IN (1)} t1z 300 170 203 {z IN (1)} t1z 300
149 204 {z IN (2)} t1z 200 171 204 {z IN (2)} t1z 175
150 205 {z IN (3)} t1z 100 172 205 {z IN (3)} t1z 125
151 206 {z IN (4)} t1z 50 173 206 {z IN (4)} t1z 1
152 207 {z IN (0.5)} t1z 50 174 207 {z IN (0.5)} t1z 1
153 208 {z IN (0,1)} t1z 700 175 208 {z IN (0,1)} t1z 700
154 209 {z IN (0,1,2)} t1z 900 176 209 {z IN (0,1,2)} t1z 875
155 210 {z IN (0,1,2,3)} {} 100 177 210 {z IN (0,1,2,3)} {} 100
156 211 {z IN (0,1,2,3,4,5)} {} 100 178 211 {z IN (0,1,2,3,4,5)} {} 100
157 212 {z IN (1,2)} t1z 500 179 212 {z IN (1,2)} t1z 475
158 213 {z IN (2,3)} t1z 300 180 213 {z IN (2,3)} t1z 300
159 214 {z=3 OR z=2} t1z 300 181 214 {z=3 OR z=2} t1z 300
160 215 {z IN (-1,3)} t1z 150 182 215 {z IN (-1,3)} t1z 126
161 216 {z=-1 OR z=3} t1z 150 183 216 {z=-1 OR z=3} t1z 126
162 184
163 300 {y=0} {} 100 185 300 {y=0} t1y 974
164 301 {y=1} t1y 50 186 301 {y=1} t1y 26
165 302 {y=0.1} t1y 50 187 302 {y=0.1} t1y 1
166 188
167 400 {x IS NULL} t1x 400 189 400 {x IS NULL} t1x 400
168 190
169 } { 191 } {
170 # Verify that the expected index is used with the expected row count 192 # Verify that the expected index is used with the expected row count
171 do_test analyze5-1.${testid}a { 193 # No longer valid due to an EXPLAIN QUERY PLAN output format change
172 set x [lindex [eqp "SELECT * FROM t1 WHERE $where"] 3] 194 # do_test analyze5-1.${testid}a {
173 set idx {} 195 # set x [lindex [eqp "SELECT * FROM t1 WHERE $where"] 3]
174 regexp {INDEX (t1.) } $x all idx 196 # set idx {}
175 regexp {~([0-9]+) rows} $x all nrow 197 # regexp {INDEX (t1.) } $x all idx
176 list $idx $nrow 198 # regexp {~([0-9]+) rows} $x all nrow
177 } [list $index $rows] 199 # list $idx $nrow
200 # } [list $index $rows]
178 201
179 # Verify that the same result is achieved regardless of whether or not 202 # Verify that the same result is achieved regardless of whether or not
180 # the index is used 203 # the index is used
181 do_test analyze5-1.${testid}b { 204 do_test analyze5-1.${testid}b {
182 set w2 [string map {y +y z +z} $where] 205 set w2 [string map {y +y z +z} $where]
183 set a1 [db eval "SELECT rowid FROM t1 NOT INDEXED WHERE $w2\ 206 set a1 [db eval "SELECT rowid FROM t1 NOT INDEXED WHERE $w2\
184 ORDER BY +rowid"] 207 ORDER BY +rowid"]
185 set a2 [db eval "SELECT rowid FROM t1 WHERE $where ORDER BY +rowid"] 208 set a2 [db eval "SELECT rowid FROM t1 WHERE $where ORDER BY +rowid"]
186 if {$a1==$a2} { 209 if {$a1==$a2} {
187 set res ok 210 set res ok
188 } else { 211 } else {
189 set res "a1=\[$a1\] a2=\[$a2\]" 212 set res "a1=\[$a1\] a2=\[$a2\]"
190 } 213 }
191 set res 214 set res
192 } {ok} 215 } {ok}
193 } 216 }
194 217
195 # Increase the number of NULLs in column x 218 # Increase the number of NULLs in column x
196 # 219 #
197 db eval { 220 db eval {
198 UPDATE t1 SET x=NULL; 221 UPDATE t1 SET x=NULL;
199 UPDATE t1 SET x=rowid 222 UPDATE t1 SET x=rowid
200 WHERE rowid IN (SELECT rowid FROM t1 ORDER BY random() LIMIT 5); 223 WHERE rowid IN (SELECT rowid FROM t1 ORDER BY random() LIMIT 5);
201 ANALYZE; 224 ANALYZE;
202 } 225 }
203 226
204 # Verify that range queries generate the correct row count estimates 227 # Verify that range queries generate the correct row count estimates
205 # 228 #
206 foreach {testid where index rows} { 229 foreach {testid where index rows} {
207 500 {x IS NULL AND u='charlie'} t1u 20 230 500 {x IS NULL AND u='charlie'} t1u 17
208 501 {x=1 AND u='charlie'} t1x 5 231 501 {x=1 AND u='charlie'} t1x 1
209 502 {x IS NULL} {} 100 232 502 {x IS NULL} t1x 995
210 503 {x=1} t1x 50 233 503 {x=1} t1x 1
211 504 {x IS NOT NULL} t1x 25 234 504 {x IS NOT NULL} t1x 2
212 505 {+x IS NOT NULL} {} 500 235 505 {+x IS NOT NULL} {} 500
213 506 {upper(x) IS NOT NULL} {} 500 236 506 {upper(x) IS NOT NULL} {} 500
214 237
215 } { 238 } {
216 # Verify that the expected index is used with the expected row count 239 # Verify that the expected index is used with the expected row count
217 do_test analyze5-1.${testid}a { 240 # No longer valid due to an EXPLAIN QUERY PLAN format change
218 set x [lindex [eqp "SELECT * FROM t1 WHERE $where"] 3] 241 # do_test analyze5-1.${testid}a {
219 set idx {} 242 # set x [lindex [eqp "SELECT * FROM t1 WHERE $where"] 3]
220 regexp {INDEX (t1.) } $x all idx 243 # set idx {}
221 regexp {~([0-9]+) rows} $x all nrow 244 # regexp {INDEX (t1.) } $x all idx
222 list $idx $nrow 245 # regexp {~([0-9]+) rows} $x all nrow
223 } [list $index $rows] 246 # list $idx $nrow
247 # } [list $index $rows]
224 248
225 # Verify that the same result is achieved regardless of whether or not 249 # Verify that the same result is achieved regardless of whether or not
226 # the index is used 250 # the index is used
227 do_test analyze5-1.${testid}b { 251 do_test analyze5-1.${testid}b {
228 set w2 [string map {y +y z +z} $where] 252 set w2 [string map {y +y z +z} $where]
229 set a1 [db eval "SELECT rowid FROM t1 NOT INDEXED WHERE $w2\ 253 set a1 [db eval "SELECT rowid FROM t1 NOT INDEXED WHERE $w2\
230 ORDER BY +rowid"] 254 ORDER BY +rowid"]
231 set a2 [db eval "SELECT rowid FROM t1 WHERE $where ORDER BY +rowid"] 255 set a2 [db eval "SELECT rowid FROM t1 WHERE $where ORDER BY +rowid"]
232 if {$a1==$a2} { 256 if {$a1==$a2} {
233 set res ok 257 set res ok
234 } else { 258 } else {
235 set res "a1=\[$a1\] a2=\[$a2\]" 259 set res "a1=\[$a1\] a2=\[$a2\]"
236 } 260 }
237 set res 261 set res
238 } {ok} 262 } {ok}
239 } 263 }
240 264
241 finish_test 265 finish_test
OLDNEW
« no previous file with comments | « third_party/sqlite/src/test/analyze4.test ('k') | third_party/sqlite/src/test/analyze6.test » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698