Backport the query planner enhancement of [952f5e8c69904] to the

3.7.2 branch.

FossilOrigin-Name: 440d995661c961257ca15833ab94c7ec7a5892c8
This commit is contained in:
drh
2011-03-04 01:23:26 +00:00
parent 2dfea2f020
commit ac92abf2d0
4 changed files with 88 additions and 12 deletions
+10 -9
View File
@@ -1,8 +1,8 @@
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
C Fix\sthe\sexpected\soutput\son\stests\sso\sthat\sit\scorresponds\sto\sthe\snew\squery\nplanner\sresults.\s\sAll\sof\sveryquick.test\sis\snow\spassing\swith\nSQLITE_ENABLE_STAT2.
D 2011-02-12T14:23:48.545
C Backport\sthe\squery\splanner\senhancement\sof\s[952f5e8c69904]\sto\sthe\n3.7.2\sbranch.
D 2011-03-04T01:23:26.302
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 543f91f24cd7fee774ecc0a61c19704c0c3e78fd
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -233,7 +233,7 @@ F src/vtab.c 0e8e0cb30dffb078367e843e84e37ef99236c7e4
F src/wal.c 5ac2119e23ee4424599d4275b66dc88d612a0543
F src/wal.h 96669b645e27cd5a111ba59f0cae7743a207bc3c
F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f
F src/where.c 9c140acd52f4526983cba7203e6a5bb0ccadb5fb
F src/where.c 4d5918de315298d37919614c5e28ea1df1189ce2
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
F test/alias.test 4529fbc152f190268a15f9384a5651bbbabc9d87
F test/all.test 6745008c144bd2956d58864d21f7b304689c1cce
@@ -245,6 +245,7 @@ F test/altermalloc.test e81ac9657ed25c6c5bb09bebfa5a047cd8e4acfc
F test/analyze.test d21f2143664912a20d04b67baf4bed935e7b1b48
F test/analyze2.test ea3df826879dd672031b27c6a845afc3a39f27d9
F test/analyze3.test d61f55d8b472fc6e713160b1e577f7a68e63f38b
F test/analyze6.test 1ba1aea8fad25a77ffd71f24522d1bb9ecc949fc
F test/async.test ad4ba51b77cd118911a3fe1356b0809da9c108c3
F test/async2.test bf5e2ca2c96763b4cba3d016249ad7259a5603b6
F test/async3.test 93edaa9122f498e56ea98c36c72abc407f4fb11e
@@ -849,14 +850,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
P 9d2b0af266b85f10823e54ca6417e76950c1d531
R 716c2554879c451567b11e004ed21569
P f2a8b5ccfb46b6be5c8857bc495de14e55851bf4
R 29aa41f4eb47cc16c6f41f19db3d3c2a
U drh
Z 4e672fc5ece21ffbe27c23d71389ecc8
Z d9fbeee93e96963d1ad274f804dd71a0
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFNVpf4oxKgR168RlERAnPNAJ47O1yXsq/ligOqmKbDGqny6c5lqgCeMySd
2rRQeonIpwLNbwL34HKdnYA=
=9LcO
iD8DBQFNcD8RoxKgR168RlERAvEBAJ96NOTOeQfSdiUNyWHFey2MVEkE4gCeLMBe
PM1svomrOJj0JmTwxjR3w0w=
=ags1
-----END PGP SIGNATURE-----
+1 -1
View File
@@ -1 +1 @@
f2a8b5ccfb46b6be5c8857bc495de14e55851bf4
440d995661c961257ca15833ab94c7ec7a5892c8
+3 -2
View File
@@ -4611,8 +4611,8 @@ WhereInfo *sqlite3WhereBegin(
** (1) The table must not depend on other tables that have not
** yet run.
**
** (2) A full-table-scan plan cannot supercede another plan unless
** it is an "optimal" plan as defined above.
** (2) A full-table-scan plan cannot supercede indexed plan unless
** the full-table-scan is an "optimal" plan as defined above.
**
** (3) All tables have an INDEXED BY clause or this table lacks an
** INDEXED BY clause or this table uses the specific
@@ -4628,6 +4628,7 @@ WhereInfo *sqlite3WhereBegin(
*/
if( (sCost.used&notReady)==0 /* (1) */
&& (bestJ<0 || (notIndexed&m)!=0 /* (2) */
|| (bestPlan.plan.wsFlags & WHERE_NOT_FULLSCAN)==0
|| (sCost.plan.wsFlags & WHERE_NOT_FULLSCAN)!=0)
&& (nUnconstrained==0 || pTabItem->pIndex==0 /* (3) */
|| NEVER((sCost.plan.wsFlags & WHERE_NOT_FULLSCAN)!=0))
+74
View File
@@ -0,0 +1,74 @@
# 2011 March 3
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
#
# This file implements tests for SQLite library. The focus of the tests
# in this file a corner-case query planner optimization involving the
# join order of two tables of different sizes.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
ifcapable !stat2 {
finish_test
return
}
set testprefix analyze6
proc eqp {sql {db db}} {
uplevel execsql [list "EXPLAIN QUERY PLAN $sql"] $db
}
do_test analyze6-1.0 {
db eval {
CREATE TABLE cat(x INT);
CREATE UNIQUE INDEX catx ON cat(x);
/* Give cat 16 unique integers */
INSERT INTO cat VALUES(1);
INSERT INTO cat VALUES(2);
INSERT INTO cat SELECT x+2 FROM cat;
INSERT INTO cat SELECT x+4 FROM cat;
INSERT INTO cat SELECT x+8 FROM cat;
CREATE TABLE ev(y INT);
CREATE INDEX evy ON ev(y);
/* ev will hold 32 copies of 16 integers found in cat */
INSERT INTO ev SELECT x FROM cat;
INSERT INTO ev SELECT x FROM cat;
INSERT INTO ev SELECT y FROM ev;
INSERT INTO ev SELECT y FROM ev;
INSERT INTO ev SELECT y FROM ev;
INSERT INTO ev SELECT y FROM ev;
ANALYZE;
SELECT count(*) FROM cat;
SELECT count(*) FROM ev;
}
} {16 512}
# The lowest cost plan is to scan CAT and for each integer there, do a single
# lookup of the first corresponding entry in EV then read off the equal values
# in EV. (Prior to the 2011-03-04 enhancement to where.c, this query would
# have used EV for the outer loop instead of CAT - which was about 3x slower.)
#
do_test analyze6-1.1 {
eqp {SELECT count(*) FROM ev, cat WHERE x=y}
} {0 0 1 {SCAN TABLE cat (~16 rows)} 0 1 0 {SEARCH TABLE ev USING COVERING INDEX evy (y=?) (~32 rows)}}
# The same plan is chosen regardless of the order of the tables in the
# FROM clause.
#
do_test analyze6-1.2 {
eqp {SELECT count(*) FROM cat, ev WHERE x=y}
} {0 0 0 {SCAN TABLE cat (~16 rows)} 0 1 1 {SEARCH TABLE ev USING COVERING INDEX evy (y=?) (~32 rows)}}
finish_test