Commit 20a2e1d0 authored by unknown's avatar unknown

Fix of LP BUG#777809

There are 2 volatile condition constructions AND/OR constructions and fields(references) when first
good supported to be top elements of conditions because it is normal practice
(see copy_andor_structure for example) fields without any expression in the condition is really rare
and mostly useless case however it could lead to problems when optimiser changes/moves them unaware
of other variables referring to them. An easy solution of this problem is just to replace single field
in a condition with equivalent expression well supported by the server (<field> -> <field> != 0).

mysql-test/r/view.result:
  New test added.
mysql-test/t/view.test:
  New test added.
sql/sql_parse.cc:
  <field> -> <field> != 0
sql/sql_yacc.yy:
  <field> -> <field> != 0
parent 541469f7
......@@ -3906,6 +3906,23 @@ SELECT * FROM v1;
a
DROP VIEW v1;
DROP TABLE t1;
#
# LP BUG#777809 (a retrograded condition for view ON)
#
CREATE TABLE t1 ( f1 int NOT NULL , f6 int NOT NULL ) ;
INSERT IGNORE INTO t1 VALUES (20, 2);
CREATE TABLE t2 ( f3 int NOT NULL ) ;
INSERT IGNORE INTO t2 VALUES (7);
CREATE OR REPLACE VIEW v2 AS SELECT * FROM t2;
PREPARE prep_stmt FROM 'SELECT t1.f6 FROM t1 RIGHT JOIN v2 ON v2.f3 WHERE t1.f1 != 0';
EXECUTE prep_stmt;
f6
2
EXECUTE prep_stmt;
f6
2
drop view v2;
drop table t1,t2;
# -----------------------------------------------------------------
# -- End of 5.1 tests.
# -----------------------------------------------------------------
......@@ -3953,6 +3953,26 @@ SELECT * FROM v1;
DROP VIEW v1;
DROP TABLE t1;
--echo #
--echo # LP BUG#777809 (a retrograded condition for view ON)
--echo #
CREATE TABLE t1 ( f1 int NOT NULL , f6 int NOT NULL ) ;
INSERT IGNORE INTO t1 VALUES (20, 2);
CREATE TABLE t2 ( f3 int NOT NULL ) ;
INSERT IGNORE INTO t2 VALUES (7);
CREATE OR REPLACE VIEW v2 AS SELECT * FROM t2;
PREPARE prep_stmt FROM 'SELECT t1.f6 FROM t1 RIGHT JOIN v2 ON v2.f3 WHERE t1.f1 != 0';
EXECUTE prep_stmt;
EXECUTE prep_stmt;
drop view v2;
drop table t1,t2;
--echo # -----------------------------------------------------------------
--echo # -- End of 5.1 tests.
--echo # -----------------------------------------------------------------
......@@ -6890,6 +6890,28 @@ push_new_name_resolution_context(THD *thd,
}
/**
Fix condition which contains only field (f turns to f <> 0 )
@param cond The condition to fix
@return fixed condition
*/
Item *normalize_cond(Item *cond)
{
if (cond)
{
Item::Type type= cond->type();
if (type == Item::FIELD_ITEM || type == Item::REF_ITEM)
{
cond= new Item_func_ne(cond, new Item_int(0));
}
}
return cond;
}
/**
Add an ON condition to the second operand of a JOIN ... ON.
......@@ -6908,6 +6930,7 @@ void add_join_on(TABLE_LIST *b, Item *expr)
{
if (expr)
{
expr= normalize_cond(expr);
if (!b->on_expr)
b->on_expr= expr;
else
......
......@@ -9029,7 +9029,7 @@ where_clause:
expr
{
SELECT_LEX *select= Select;
select->where= $3;
select->where= normalize_cond($3);
select->parsing_place= NO_MATTER;
if ($3)
$3->top_level_item();
......@@ -9045,7 +9045,7 @@ having_clause:
expr
{
SELECT_LEX *sel= Select;
sel->having= $3;
sel->having= normalize_cond($3);
sel->parsing_place= NO_MATTER;
if ($3)
$3->top_level_item();
......@@ -10483,7 +10483,7 @@ wild_and_where:
}
| WHERE expr
{
Select->where= $2;
Select->where= normalize_cond($2);
if ($2)
$2->top_level_item();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment