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

Query optimizer enhancement: In "FROM a,b,c left join d" allow the C table

to be reordered with A and B.  This used to be the case but the capability
was removed by (3203) and (3052) in response to ticket #1652.  This change
restores the capability. (CVS 3529)

FossilOrigin-Name: 7393c81b8cb9d4344ae744de9eabcb3af64f1db8
This commit is contained in:
drh
2006-12-16 16:25:15 +00:00
parent f0fa1c1b9f
commit 61dfc31d80
9 changed files with 212 additions and 86 deletions

View File

@ -12,7 +12,7 @@
# focus of this file is testing the join reordering optimization
# in cases that include a LEFT JOIN.
#
# $Id: where3.test,v 1.2 2006/06/06 11:45:55 drh Exp $
# $Id: where3.test,v 1.3 2006/12/16 16:25:17 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -78,4 +78,85 @@ do_test where3-1.2 {
}
} {1 {Value for C1.1} {Value for C2.1} 2 {} {Value for C2.2} 3 {Value for C1.3} {Value for C2.3}}
# This procedure executes the SQL. Then it appends
# the ::sqlite_query_plan variable.
#
proc queryplan {sql} {
set ::sqlite_sort_count 0
set data [execsql $sql]
return [concat $data $::sqlite_query_plan]
}
# If you have a from clause of the form: A B C left join D
# then make sure the query optimizer is able to reorder the
# A B C part anyway it wants.
#
# Following the fix to ticket #1652, there was a time when
# the C table would not reorder. So the following reorderings
# were possible:
#
# A B C left join D
# B A C left join D
#
# But these reorders were not allowed
#
# C A B left join D
# A C B left join D
# C B A left join D
# B C A left join D
#
# The following tests are here to verify that the latter four
# reorderings are allowed again.
#
do_test where3-2.1 {
execsql {
CREATE TABLE tA(apk integer primary key, ax);
CREATE TABLE tB(bpk integer primary key, bx);
CREATE TABLE tC(cpk integer primary key, cx);
CREATE TABLE tD(dpk integer primary key, dx);
}
queryplan {
SELECT * FROM tA, tB, tC LEFT JOIN tD ON dpk=cx
WHERE cpk=bx AND bpk=ax
}
} {tA {} tB * tC * tD *}
do_test where3-2.2 {
queryplan {
SELECT * FROM tA, tB, tC LEFT JOIN tD ON dpk=cx
WHERE cpk=bx AND apk=bx
}
} {tB {} tA * tC * tD *}
do_test where3-2.3 {
queryplan {
SELECT * FROM tA, tB, tC LEFT JOIN tD ON dpk=cx
WHERE cpk=bx AND apk=bx
}
} {tB {} tA * tC * tD *}
do_test where3-2.4 {
queryplan {
SELECT * FROM tA, tB, tC LEFT JOIN tD ON dpk=cx
WHERE apk=cx AND bpk=ax
}
} {tC {} tA * tB * tD *}
do_test where3-2.5 {
queryplan {
SELECT * FROM tA, tB, tC LEFT JOIN tD ON dpk=cx
WHERE cpk=ax AND bpk=cx
}
} {tA {} tC * tB * tD *}
do_test where3-2.5 {
queryplan {
SELECT * FROM tA, tB, tC LEFT JOIN tD ON dpk=cx
WHERE bpk=cx AND apk=bx
}
} {tC {} tB * tA * tD *}
do_test where3-2.6 {
queryplan {
SELECT * FROM tA, tB, tC LEFT JOIN tD ON dpk=cx
WHERE cpk=bx AND apk=cx
}
} {tB {} tC * tA * tD *}
finish_test