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

Do not automatically remove the DISTINCT keyword from "a IN (SELECT DISTINCT ...)" expressions. Fix for [db87229497].

FossilOrigin-Name: 55e453aadbb676dda07f0fa537d39ce184ef636c
This commit is contained in:
dan
2014-11-14 15:28:33 +00:00
parent 8ac1a67eff
commit dd715f7c57
4 changed files with 56 additions and 9 deletions

View File

@ -12,6 +12,7 @@
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix in5
do_test in5-1.1 {
execsql {
@ -135,4 +136,51 @@ do_test in5-5.3 {
}]
} {0}
#-------------------------------------------------------------------------
# At one point SQLite was removing the DISTINCT keyword from expressions
# similar to:
#
# <expr1> IN (SELECT DISTINCT <expr2> FROM...)
#
# However, there are a few obscure cases where this is incorrect. For
# example, if the SELECT features a LIMIT clause, or if the collation
# sequence or affinity used by the DISTINCT does not match the one used
# by the IN(...) expression.
#
do_execsql_test 6.1.1 {
CREATE TABLE t1(a COLLATE nocase);
INSERT INTO t1 VALUES('one');
INSERT INTO t1 VALUES('ONE');
}
do_execsql_test 6.1.2 {
SELECT count(*) FROM t1 WHERE a COLLATE BINARY IN (SELECT DISTINCT a FROM t1)
} {1}
do_execsql_test 6.2.1 {
CREATE TABLE t3(a, b);
INSERT INTO t3 VALUES(1, 1);
INSERT INTO t3 VALUES(1, 2);
INSERT INTO t3 VALUES(1, 3);
INSERT INTO t3 VALUES(2, 4);
INSERT INTO t3 VALUES(2, 5);
INSERT INTO t3 VALUES(2, 6);
INSERT INTO t3 VALUES(3, 7);
INSERT INTO t3 VALUES(3, 8);
INSERT INTO t3 VALUES(3, 9);
}
do_execsql_test 6.2.2 {
SELECT count(*) FROM t3 WHERE b IN (SELECT DISTINCT a FROM t3 LIMIT 5);
} {3}
do_execsql_test 6.2.3 {
SELECT count(*) FROM t3 WHERE b IN (SELECT a FROM t3 LIMIT 5);
} {2}
do_execsql_test 6.3.1 {
CREATE TABLE x1(a);
CREATE TABLE x2(b);
INSERT INTO x1 VALUES(1), (1), (2);
INSERT INTO x2 VALUES(1), (2);
SELECT count(*) FROM x2 WHERE b IN (SELECT DISTINCT a FROM x1 LIMIT 2);
} {2}
finish_test