diff options
author | Alexander Barkov <bar@mariadb.com> | 2019-12-16 12:57:08 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.com> | 2019-12-16 12:57:08 +0400 |
commit | fc860d3fa3bc854fbe6aab9179d7a4aaf6eb9edf (patch) | |
tree | 0d7a45f7faa9748af710ede26d04aa27da2c2d5a | |
parent | 794911a27a14ea83eda054cf34d94b43191aa19e (diff) | |
download | mariadb-git-fc860d3fa3bc854fbe6aab9179d7a4aaf6eb9edf.tar.gz |
MDEV-21065 UNIQUE constraint causes a query with string comparison to omit a row in the result set
-rw-r--r-- | mysql-test/r/type_int.result | 13 | ||||
-rw-r--r-- | mysql-test/t/type_int.test | 12 | ||||
-rw-r--r-- | strings/ctype-simple.c | 3 | ||||
-rw-r--r-- | strings/my_strtoll10.c | 17 |
4 files changed, 39 insertions, 6 deletions
diff --git a/mysql-test/r/type_int.result b/mysql-test/r/type_int.result index aaf35690306..c8b77490102 100644 --- a/mysql-test/r/type_int.result +++ b/mysql-test/r/type_int.result @@ -20,5 +20,18 @@ COALESCE(@a) 1 DROP TABLE t1; # +# MDEV-21065 UNIQUE constraint causes a query with string comparison to omit a row in the result set +# +CREATE TABLE t1 (c0 INT UNIQUE); +INSERT INTO t1 VALUES (NULL), (NULL), (NULL), (NULL), (1), (0); +SELECT * FROM t1 WHERE c0 < '\n2'; +c0 +0 +1 +DROP TABLE t1; +SELECT CAST('\n2' AS INT); +CAST('\n2' AS INT) +2 +# # End of 5.5 tests # diff --git a/mysql-test/t/type_int.test b/mysql-test/t/type_int.test index 52be12bf494..cc8b386aebe 100644 --- a/mysql-test/t/type_int.test +++ b/mysql-test/t/type_int.test @@ -15,5 +15,17 @@ SELECT COALESCE(@a) FROM t1 ORDER BY STRCMP(STDDEV_SAMP(a), 'bar'); DROP TABLE t1; --echo # +--echo # MDEV-21065 UNIQUE constraint causes a query with string comparison to omit a row in the result set +--echo # + +CREATE TABLE t1 (c0 INT UNIQUE); +INSERT INTO t1 VALUES (NULL), (NULL), (NULL), (NULL), (1), (0); +SELECT * FROM t1 WHERE c0 < '\n2'; +DROP TABLE t1; + +SELECT CAST('\n2' AS INT); + + +--echo # --echo # End of 5.5 tests --echo # diff --git a/strings/ctype-simple.c b/strings/ctype-simple.c index ba446a7df54..e5a1471cf63 100644 --- a/strings/ctype-simple.c +++ b/strings/ctype-simple.c @@ -1399,7 +1399,8 @@ my_strntoull10rnd_8bit(CHARSET_INFO *cs __attribute__((unused)), int shift= 0, digits= 0, negative, addon; /* Skip leading spaces and tabs */ - for ( ; str < end && (*str == ' ' || *str == '\t') ; str++); + for ( ; str < end && my_isspace(&my_charset_latin1, *str) ; ) + str++; if (str >= end) goto ret_edom; diff --git a/strings/my_strtoll10.c b/strings/my_strtoll10.c index 89450f15c9f..01c3697dcdf 100644 --- a/strings/my_strtoll10.c +++ b/strings/my_strtoll10.c @@ -98,18 +98,25 @@ longlong my_strtoll10(const char *nptr, char **endptr, int *error) if (endptr) { end= *endptr; - while (s != end && (*s == ' ' || *s == '\t')) + /* Skip leading spaces */ + for ( ; s < end && my_isspace(&my_charset_latin1, *s) ; ) s++; + if (s == end) goto no_conv; } else { endptr= &dummy; /* Easier end test */ - while (*s == ' ' || *s == '\t') - s++; - if (!*s) - goto no_conv; + /* Skip leading spaces */ + for ( ; ; s++) + { + if (!*s) + goto no_conv; + if (!my_isspace(&my_charset_latin1, *s)) + break; + } + /* This number must be big to guard against a lot of pre-zeros */ end= s+65535; /* Can't be longer than this */ } |