From 6a88fa48ae2568aadf8513060a88c88b65c3f7cc Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 17 Jul 2005 09:46:14 -0700 Subject: [PATCH] select.result, select.test: Added a test case for bug #11745. sql_select.cc: Fixed bug # 11745. Added support of where clause for queries with FROM DUAL. sql_yacc.yy: Fixed bug # 11745. Added optional where clause for queries with FROM DUAL. sql/sql_yacc.yy: Fixed bug # 11745. Added optional where clause for queries with FROM DUAL. sql/sql_select.cc: Fixed bug # 11745. Added support of where clause for queries with FROM DUAL. mysql-test/t/select.test: Added a test case for bug #11745. mysql-test/r/select.result: Added a test case for bug #11745. --- mysql-test/r/select.result | 16 ++++++++++++++++ mysql-test/t/select.test | 18 ++++++++++++++++++ sql/sql_select.cc | 2 +- sql/sql_yacc.yy | 2 +- 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index 6c9ec9d8297..2df60944999 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -2582,3 +2582,19 @@ a 254 255 drop table t2; +CREATE TABLE t1 (a int, b int, c int); +INSERT INTO t1 +SELECT 50, 3, 3 FROM DUAL +WHERE NOT EXISTS +(SELECT * FROM t1 WHERE a = 50 AND b = 3); +SELECT * FROM t1; +a b c +50 3 3 +INSERT INTO t1 +SELECT 50, 3, 3 FROM DUAL +WHERE NOT EXISTS +(SELECT * FROM t1 WHERE a = 50 AND b = 3); +SELECT * FROM t1; +a b c +50 3 3 +DROP TABLE t1; diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index caa9e332e57..893b9ba9267 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -2138,3 +2138,21 @@ insert into t2 values (0), (254), (255); explain select * from t2 where a > -1; select * from t2 where a > -1; drop table t2; + +# +# Bug #11745: SELECT ... FROM DUAL with WHERE condition +# + +CREATE TABLE t1 (a int, b int, c int); +INSERT INTO t1 + SELECT 50, 3, 3 FROM DUAL + WHERE NOT EXISTS + (SELECT * FROM t1 WHERE a = 50 AND b = 3); +SELECT * FROM t1; +INSERT INTO t1 + SELECT 50, 3, 3 FROM DUAL + WHERE NOT EXISTS + (SELECT * FROM t1 WHERE a = 50 AND b = 3); +SELECT * FROM t1; + +DROP TABLE t1; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index a70fa1c8d5e..5b4eab36dd2 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1072,7 +1072,7 @@ JOIN::exec() else { result->send_fields(fields_list,1); - if (!having || having->val_int()) + if (cond_value != Item::COND_FALSE && (!having || having->val_int())) { if (do_send_rows && (procedure ? (procedure->send_row(fields_list) || procedure->end_of_records()) diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 2587ce7e1a5..be8ead8e157 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -2459,7 +2459,7 @@ select_into: select_from: FROM join_table_list where_clause group_clause having_clause opt_order_clause opt_limit_clause procedure_clause - | FROM DUAL_SYM opt_limit_clause + | FROM DUAL_SYM where_clause opt_limit_clause /* oracle compatibility: oracle always requires FROM clause, and DUAL is system table without fields. Is "SELECT 1 FROM DUAL" any better than "SELECT 1" ?