1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Additional tests and some improvements to the INSERT transfer

optimization.  More testing is needed. (CVS 3661)

FossilOrigin-Name: 830985814345f71ba2def3c206e36aabe9e1ee7c
This commit is contained in:
drh
2007-02-24 13:53:05 +00:00
parent 8103b7d2b7
commit dd73521bc2
6 changed files with 87 additions and 22 deletions

View File

@ -9,17 +9,28 @@
#
#***********************************************************************
# This file implements regression tests for SQLite library. The
# focus of this file is testing corner cases of the INSERT statement.
# focus of this file is testing the INSERT transfer optimization.
#
# $Id: insert4.test,v 1.1 2007/02/24 13:23:53 drh Exp $
# $Id: insert4.test,v 1.2 2007/02/24 13:53:05 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# The sqlite3_xferopt_count variable is incremented whenever the
# insert transfer optimization applies.
#
# This procedure runs a test to see if the sqlite3_xferopt_count is
# set to N.
#
proc xferopt_test {testname N} {
do_test $testname {set ::sqlite3_xferopt_count} $N
}
# Ticket #2252. Make sure the an INSERT from identical tables
# does not violate constraints.
#
do_test insert4-1.1 {
set sqlite3_xferopt_count 0
execsql {
CREATE TABLE t1(a int, b int, check(b>a));
CREATE TABLE t2(x int, y int);
@ -29,21 +40,37 @@ do_test insert4-1.1 {
INSERT INTO t1 SELECT * FROM t2;
}
} {1 {constraint failed}}
do_test insert4-1.2 {
xferopt_test insert4-1.2 0
do_test insert4-1.3 {
execsql {
SELECT * FROM t1;
}
} {}
# Other coverage tests for the INSERT transfer optimization.
# Tests to make sure that the transfer optimization is not occurring
# when it is not a valid optimization.
#
do_test insert4-2.1 {
# The SELECT must be against a real table.
do_test insert4-2.1.1 {
execsql {
INSERT INTO t1 SELECT 4, 8;
SELECT * FROM t1;
}
} {4 8}
xferopt_test insert4-2.1.2 0
do_test insert4-2.2.1 {
catchsql {
DELETE FROM t1;
CREATE VIEW v1 AS SELECT y, x FROM t2;
INSERT INTO t1 SELECT * FROM v1;
SELECT * FROM t1;
}
} {0 {1 9}}
xferopt_test insert4-2.2.2 0
# Do not run the transfer optimization if there is a LIMIT clause
#
do_test insert4-2.3.1 {
execsql {
CREATE TABLE t3(a int, b int);
INSERT INTO t2 SELECT y, x FROM t2;
@ -51,25 +78,47 @@ do_test insert4-2.2.1 {
SELECT * FROM t3;
}
} {9 1}
do_test insert4-2.2.2 {
xferopt_test insert4-2.3.2 0
do_test insert4-2.3.3 {
catchsql {
DELETE FROM t1;
INSERT INTO t1 SELECT * FROM t2 LIMIT 1;
SELECT * FROM t1;
}
} {1 {constraint failed}}
do_test insert4-2.3.1 {
xferopt_test insert4-2.3.4 0
# Do not run the transfer optimization if there is a DISTINCT
#
do_test insert4-2.4.1 {
execsql {
DELETE FROM t3;
INSERT INTO t3 SELECT DISTINCT * FROM t2;
SELECT * FROM t3;
}
} {9 1 1 9}
do_test insert4-2.3.2 {
xferopt_test insert4-2.4.2 0
do_test insert4-2.4.3 {
catchsql {
DELETE FROM t1;
INSERT INTO t1 SELECT DISTINCT * FROM t2;
}
} {1 {constraint failed}}
xferopt_test insert4-2.4.4 0
# Do run the transfer optimization if tables have identical
# CHECK constraints.
#
do_test insert4-3.1.1 {
set sqlite3_xferopt_count 0
execsql {
DELETE FROM t1;
INSERT INTO t1 VALUES(1,9);
CREATE TABLE t4(m int, n int, CHECK(n>m));
INSERT INTO t4 SELECT * FROM t1;
SELECT * FROM t4;
}
} {1 9}
xferopt_test insert4-3.1.2 1
finish_test