summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <ramil/ram@mysql.com/myoffice.izhnet.ru>2006-07-23 15:25:30 +0500
committerunknown <ramil/ram@mysql.com/myoffice.izhnet.ru>2006-07-23 15:25:30 +0500
commit16878843e0b824f5c02c3455dc16546fd0f5ef7e (patch)
tree1158b461e8bcac0bb106efcb14a9f5b0a8d739df
parent7c7949b05b8e5482bae6967f5bf2de78934dbbef (diff)
downloadmariadb-git-16878843e0b824f5c02c3455dc16546fd0f5ef7e.tar.gz
Fix for bug #8143: A date with value 0 is treated as a NULL value
mysql-test/r/delete.result: Fix for bug #8143: A date with value 0 is treated as a NULL value - test result mysql-test/t/delete.test: Fix for bug #8143: A date with value 0 is treated as a NULL value - test case sql/sql_delete.cc: Fix for bug #8143: A date with value 0 is treated as a NULL value - during SELECT queries processing we convert 'date[time]_field is null' conditions into 'date[time]_field = 0000-00-00[ 00:00:00]' for not null DATE and DATETIME fields. To be consistent, we have to do the same for DELETE queries. So we should call remove_eq_conds() in the mysql_delete() as well. Also it may simplify and speed up DELETE queries execution.
-rw-r--r--mysql-test/r/delete.result10
-rw-r--r--mysql-test/t/delete.test11
-rw-r--r--sql/sql_delete.cc8
3 files changed, 29 insertions, 0 deletions
diff --git a/mysql-test/r/delete.result b/mysql-test/r/delete.result
index 05f1c967e77..0946dc8f809 100644
--- a/mysql-test/r/delete.result
+++ b/mysql-test/r/delete.result
@@ -192,3 +192,13 @@ delete t2.*,t3.* from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;
select * from t3;
a b
drop table t1,t2,t3;
+create table t1(a date not null);
+insert into t1 values (0);
+select * from t1 where a is null;
+a
+0000-00-00
+delete from t1 where a is null;
+select count(*) from t1;
+count(*)
+0
+drop table t1;
diff --git a/mysql-test/t/delete.test b/mysql-test/t/delete.test
index 4284bd2a06d..677ffaa2860 100644
--- a/mysql-test/t/delete.test
+++ b/mysql-test/t/delete.test
@@ -171,3 +171,14 @@ delete t2.*,t3.* from t1,t2,t3 where t1.a=t2.a AND t2.b=t3.a and t1.b=t3.b;
# This should be empty
select * from t3;
drop table t1,t2,t3;
+
+#
+# Bug #8143: deleting '0000-00-00' values using IS NULL
+#
+
+create table t1(a date not null);
+insert into t1 values (0);
+select * from t1 where a is null;
+delete from t1 where a is null;
+select count(*) from t1;
+drop table t1;
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index 381d1a71e31..b608773bf6e 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -91,6 +91,14 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
/* Handler didn't support fast delete; Delete rows one by one */
}
+ if (conds)
+ {
+ Item::cond_result result;
+ conds= remove_eq_conds(thd, conds, &result);
+ if (result == Item::COND_FALSE) // Impossible where
+ limit= 0;
+ }
+
table->used_keys.clear_all();
table->quick_keys.clear_all(); // Can't use 'only index'
select=make_select(table, 0, 0, conds, 0, &error);