1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

Fix the query planner so that when it has a choice of full-scan tables to

move to the outer loop, it chooses the one that is likely to give the fewest
output rows.

FossilOrigin-Name: 309bbedf9648c750d7b8aedbc15d4fd68f846824
This commit is contained in:
drh
2010-08-05 02:52:32 +00:00
parent 5e377d90ed
commit aa0ba4345d
4 changed files with 65 additions and 22 deletions

View File

@ -235,4 +235,30 @@ do_test where3-3.1 {
}
} {0 1 {TABLE t302} 1 0 {TABLE t301 USING PRIMARY KEY}}
# Verify that when there are multiple tables in a join which must be
# full table scans that the query planner attempts put the table with
# the fewest number of output rows as the outer loop.
#
do_test where3-4.0 {
execsql {
CREATE TABLE t400(a INTEGER PRIMARY KEY, b, c);
CREATE TABLE t401(p INTEGER PRIMARY KEY, q, r);
CREATE TABLE t402(x INTEGER PRIMARY KEY, y, z);
EXPLAIN QUERY PLAN
SELECT * FROM t400, t401, t402 WHERE t402.z GLOB 'abc*';
}
} {0 2 {TABLE t402} 1 0 {TABLE t400} 2 1 {TABLE t401}}
do_test where3-4.1 {
execsql {
EXPLAIN QUERY PLAN
SELECT * FROM t400, t401, t402 WHERE t401.r GLOB 'abc*';
}
} {0 1 {TABLE t401} 1 0 {TABLE t400} 2 2 {TABLE t402}}
do_test where3-4.2 {
execsql {
EXPLAIN QUERY PLAN
SELECT * FROM t400, t401, t402 WHERE t400.c GLOB 'abc*';
}
} {0 0 {TABLE t400} 1 1 {TABLE t401} 2 2 {TABLE t402}}
finish_test