More tests for SQLITE_OMIT_UNIQUE_ENFORCEMENT and minor change to implementation.

FossilOrigin-Name: b86999436ec2414c990ba720441fe316f647eef6
This commit is contained in:
shaneh 2011-03-12 04:58:55 +00:00
parent ca6b9d5bbe
commit 11c58f7d8e
6 changed files with 72 additions and 88 deletions

View File

@ -1,8 +1,5 @@
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
C Remove\san\sunused\sfield\sfrom\sthe\sunix\ssqlite3_file\sobject.
D 2011-03-11T16:15:48.132
C More\stests\sfor\sSQLITE_OMIT_UNIQUE_ENFORCEMENT\sand\sminor\schange\sto\simplementation.
D 2011-03-12T04:58:55.547
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 27701a1653595a1f2187dc61c8117e00a6c1d50f
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -130,7 +127,7 @@ F src/btreeInt.h 20f73dc93b1eeb83afd7259fbc6bd7dcf2df7fe4
F src/build.c 00a327120d81ace6267e714ae8010c997d55de5d
F src/callback.c a1d1b1c9c85415dff013af033e2fed9c8382d33b
F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac
F src/ctime.c 7deec4534f3b5a0c3b4a4cbadf809d321f64f9c4
F src/ctime.c 52ff72f966cee3087e0138a3ec69371c22be3c01
F src/date.c 1548fdac51377e4e7833251de878b4058c148e1b
F src/delete.c 7ed8a8c8b5f748ece92df173d7e0f7810c899ebd
F src/expr.c 00817c672af554321fd67c44325afd7cef0e4648
@ -141,7 +138,7 @@ F src/global.c 02335177cf6946fe5525c6f0755cf181140debf3
F src/hash.c 458488dcc159c301b8e7686280ab209f1fb915af
F src/hash.h 2894c932d84d9f892d4b4023a75e501f83050970
F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08
F src/insert.c 06133d9ea3c17d9adf98a40c87da31dc028759f0
F src/insert.c 8ffb544ff516669aa84a6f13d05dbf5c93bdb1ea
F src/journal.c 552839e54d1bf76fb8f7abe51868b66acacf6a0e
F src/legacy.c a199d7683d60cef73089e892409113e69c23a99f
F src/lempar.c 7f026423f4d71d989e719a743f98a1cbd4e6d99e
@ -587,7 +584,7 @@ F test/notify2.test 195a467e021f74197be2c4fb02d6dee644b8d8db
F test/notify3.test d60923e186e0900f4812a845fcdfd8eea096e33a
F test/notnull.test cc7c78340328e6112a13c3e311a9ab3127114347
F test/null.test a8b09b8ed87852742343b33441a9240022108993
F test/omitunique.test 03747013c870bb4c14c3fbaeb13dae8c6efad9f2
F test/omitunique.test bbb2ec4345d9125d9ee21cd9488d97a163020d5f
F test/openv2.test af02ed0a9cbc0d2a61b8f35171d4d117e588e4ec
F test/oserror.test d1f085bdbac20456fccdf5877f52016453654fc3
F test/pager1.test d8672fd0af5f4f9b99b06283d00f01547809bebe
@ -896,7 +893,7 @@ F tool/mkspeedsql.tcl a1a334d288f7adfe6e996f2e712becf076745c97
F tool/mksqlite3c.tcl cf44512a48112b1ba09590548660a5a6877afdb3
F tool/mksqlite3h.tcl d76c226a5e8e1f3b5f6593bcabe5e98b3b1ec9ff
F tool/mksqlite3internalh.tcl 7b43894e21bcb1bb39e11547ce7e38a063357e87
F tool/omittest.tcl 71c6f21afa2df91dd299ed317d5751fb628795fe
F tool/omittest.tcl 4f4cc66bb7ca6a5b8f61ee37b6333f60fb8a746a
F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c
F tool/restore_jrnl.tcl 6957a34f8f1f0f8285e07536225ec3b292a9024a
F tool/shell1.test f608a009b04c490fd360c5ded458a6f98b4e7ec4
@ -916,14 +913,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
P 75a38411a89bd2969ec5cecca13c13a390b3d478
R 7f2984260ffacb3dffcb8dcb5c4023c8
U drh
Z d9c90b8af5c4c55409cdd40572c1521c
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFNekq3oxKgR168RlERAnw2AJwJjXruLGtJKxCByVRypbB2NPpZ+ACfTrqn
vTIXWbkq8AxcjkytK9CY6es=
=V2tY
-----END PGP SIGNATURE-----
P f957f23a8a392bb1720720960bda2c7b24de9663
R 9809ca6e3f2473669b6771844893033b
U shaneh
Z 165de3d9f760ec4796ef397e07022985

View File

@ -1 +1 @@
f957f23a8a392bb1720720960bda2c7b24de9663
b86999436ec2414c990ba720441fe316f647eef6

View File

@ -302,6 +302,9 @@ static const char * const azCompileOpt[] = {
#ifdef SQLITE_OMIT_TRUNCATE_OPTIMIZATION
"OMIT_TRUNCATE_OPTIMIZATION",
#endif
#ifdef SQLITE_OMIT_UNIQUE_ENFORCEMENT
"OMIT_UNIQUE_ENFORCEMENT",
#endif
#ifdef SQLITE_OMIT_UTF16
"OMIT_UTF16",
#endif

View File

@ -1331,7 +1331,6 @@ void sqlite3GenerateConstraintChecks(
sqlite3ExprCacheAffinityChange(pParse, regIdx, pIdx->nColumn+1);
#ifdef SQLITE_OMIT_UNIQUE_ENFORCEMENT
pIdx->onError = OE_None;
sqlite3ReleaseTempRange(pParse, regIdx, pIdx->nColumn+1);
continue; /* Treat pIdx as if it is not a UNIQUE index */
#else

View File

@ -22,65 +22,52 @@ ifcapable !unique_enforcement {
}
# table with UNIQUE keyword on column
do_test omitunique-1.1.1 {
catchsql {CREATE TABLE t1(a TEXT UNIQUE); }
do_test omitunique-1.1 {
catchsql { CREATE TABLE t1(a TEXT UNIQUE); }
} {0 {}}
do_test omitunique-1.1.2 {
catchsql {INSERT INTO t1(a) VALUES('abc'); }
} {0 {}}
do_test omitunique-1.1.3 {
catchsql {INSERT INTO t1(a) VALUES('123'); }
# table with UNIQUE clause on column
do_test omitunique-1.2 {
catchsql { CREATE TABLE t2(a TEXT, UNIQUE(a)); }
} {0 {}}
# table with UNIQUE index on column
do_test omitunique-1.2.1 {
do_test omitunique-1.3 {
catchsql {
CREATE TABLE t2(a TEXT);
CREATE UNIQUE INDEX t2a ON t2(a);
CREATE TABLE t3(a TEXT);
CREATE UNIQUE INDEX t3a ON t3(a);
}
} {0 {}}
do_test omitunique-1.2.2 {
catchsql {INSERT INTO t2(a) VALUES('abc'); }
} {0 {}}
do_test omitunique-1.2.3 {
catchsql {INSERT INTO t2(a) VALUES('123'); }
} {0 {}}
# table with regular index on column
do_test omitunique-1.3.1 {
do_test omitunique-1.4 {
catchsql {
CREATE TABLE t3(a TEXT);
CREATE INDEX t3a ON t3(a);
CREATE TABLE t4(a TEXT);
CREATE INDEX t4a ON t4(a);
}
} {0 {}}
do_test omitunique-1.3.2 {
catchsql {INSERT INTO t3(a) VALUES('abc'); }
} {0 {}}
do_test omitunique-1.3.3 {
catchsql {INSERT INTO t3(a) VALUES('123'); }
} {0 {}}
# table with no index on column
do_test omitunique-1.4.1 {
catchsql {
CREATE TABLE t4(a TEXT);
}
} {0 {}}
do_test omitunique-1.4.2 {
catchsql {INSERT INTO t4(a) VALUES('abc'); }
} {0 {}}
do_test omitunique-1.4.3 {
catchsql {INSERT INTO t4(a) VALUES('123'); }
do_test omitunique-1.5 {
catchsql { CREATE TABLE t5(a TEXT); }
} {0 {}}
# run our tests using several table/index forms
foreach {j tbl uniq cnt_enforce cnt_omit qp_est} {
1 {t1} 1 1 9 1
2 {t2} 1 1 9 1
3 {t3} 0 9 9 10
4 {t4} 0 9 9 100000
foreach {j tbl uniq cnt qp_est stat_enforce stat_omit } {
1 {t1} 1 1 1 {2 1} {9 9}
2 {t2} 1 1 1 {2 1} {9 9}
3 {t3} 1 1 1 {2 1} {9 9}
4 {t4} 0 9 10 {9 9} {9 9}
5 {t5} 0 9 100000 9 9
} {
do_test omitunique-2.0.$j.1 {
catchsql [ subst {INSERT INTO $tbl (a) VALUES('abc'); }]
} {0 {}}
do_test omitunique-2.0.$j.2 {
catchsql [ subst {INSERT INTO $tbl (a) VALUES('123'); }]
} {0 {}}
# check various INSERT commands
foreach {i cmd err} {
1 {INSERT} 1
@ -93,22 +80,17 @@ foreach {j tbl uniq cnt_enforce cnt_omit qp_est} {
} {
ifcapable explain {
set x [execsql [ subst { EXPLAIN $cmd INTO $tbl (a) VALUES('abc'); }]]
ifcapable unique_enforcement {
do_test omitunique-2.1.$j.$i.1 {
set x [execsql [ subst {EXPLAIN $cmd INTO $tbl (a) VALUES('abc')}]]
regexp { IsUnique } $x
} $uniq
}
ifcapable !unique_enforcement {
do_test omitunique-2.1.$j.$i.1 {
set x [execsql [ subst {EXPLAIN $cmd INTO $tbl (a) VALUES('abc')}]]
regexp { IsUnique } $x
} {0}
}
do_test omitunique-2.1.$j.2 {
set x [execsql [ subst {EXPLAIN $cmd INTO $tbl (a) VALUES('abc')}]]
regexp { Next } $x
} {0}
}
if { $uniq_enforced==0 || $uniq==0 || $err==0 } {
@ -117,7 +99,7 @@ foreach {j tbl uniq cnt_enforce cnt_omit qp_est} {
set msg {1 {column a is not unique}}
}
do_test omitunique-2.1.$j.$i.3 {
catchsql [ subst {$cmd INTO $tbl (a) VALUES('abc')}]
catchsql [ subst {$cmd INTO $tbl (a) VALUES('abc'); }]
} $msg
}
@ -125,23 +107,17 @@ foreach {j tbl uniq cnt_enforce cnt_omit qp_est} {
# check UPDATE command
ifcapable explain {
set x [execsql [ subst { EXPLAIN UPDATE $tbl SET a='abc'; }]]
ifcapable unique_enforcement {
do_test omitunique-2.2.$j.1 {
set x [execsql [ subst {EXPLAIN UPDATE $tbl SET a='abc'}]]
regexp { IsUnique } $x
} $uniq
}
ifcapable !unique_enforcement {
do_test omitunique-2.2.$j.1 {
set x [execsql [ subst {EXPLAIN UPDATE $tbl SET a='abc'}]]
regexp { IsUnique } $x
} {0}
}
# comment out for now
# do_test omitunique-2.2.$j.2 {
# set x [execsql [ subst {EXPLAIN UPDATE $tbl SET a='abc' WHERE a<>'abc'}]]
# regexp { Next } $x
# } {0}
}
if { $uniq_enforced==0 || $uniq==0 } {
set msg {0 {}}
@ -149,30 +125,45 @@ foreach {j tbl uniq cnt_enforce cnt_omit qp_est} {
set msg {1 {column a is not unique}}
}
do_test omitunique-2.2.$j.3 {
catchsql [ subst {UPDATE $tbl SET a='abc'}]
catchsql [ subst { UPDATE $tbl SET a='abc'; }]
} $msg
# check record counts
ifcapable unique_enforcement {
do_test omitunique-2.3.$j {
execsql [ subst {SELECT count(*) FROM $tbl WHERE a='abc' }]
} $cnt_enforce
}
ifcapable !unique_enforcement {
do_test omitunique-2.3.$j {
execsql [ subst {SELECT count(*) FROM $tbl WHERE a='abc' }]
} $cnt_omit
}
execsql [ subst { SELECT count(*) FROM $tbl WHERE a='abc'; }]
} $cnt
# make sure the query planner row estimate not affected because of omit enforcement
ifcapable explain {
do_test omitunique-2.4.$j {
set x [ execsql [ subst {EXPLAIN QUERY PLAN SELECT count(*) FROM $tbl WHERE a='abc' }]]
set x [ execsql [ subst { EXPLAIN QUERY PLAN SELECT count(*) FROM $tbl WHERE a='abc'; }]]
set y [ subst {~$qp_est row} ]
regexp $y $x
} {1}
}
# make sure we omit extra OP_Next opcodes when the UNIQUE constraints
# mean there will only be a single pass through the code
ifcapable explain {
set x [execsql [ subst { EXPLAIN SELECT * FROM $tbl WHERE a='abc'; }]]
do_test omitunique-2.5.$j {
if { [ regexp { Next } $x ] } { expr { 0 } } { expr { 1 } }
} $uniq
}
# make sure analyze index stats correct
ifcapable analyze {
if { $uniq_enforced==0 } {
set msg [ list $stat_omit ]
} {
set msg [ list $stat_enforce ]
}
do_test omitunique-2.6.$j {
execsql [ subst { ANALYZE $tbl; } ]
execsql [ subst { SELECT stat FROM sqlite_stat1 WHERE tbl='$tbl'; } ]
} $msg
}
}
# end foreach tbl

View File

@ -202,6 +202,7 @@ proc main {argv} {
SQLITE_OMIT_TRACE \
SQLITE_OMIT_TRIGGER \
SQLITE_OMIT_TRUNCATE_OPTIMIZATION \
SQLITE_OMIT_UNIQUE_ENFORCEMENT \
SQLITE_OMIT_UTF16 \
SQLITE_OMIT_VACUUM \
SQLITE_OMIT_VIEW \