From a77bc59896ee3cd89a8f1d391a65722b443f1841 Mon Sep 17 00:00:00 2001 From: Gleb Shchepa Date: Fri, 8 Apr 2011 12:05:20 +0400 Subject: [PATCH] Bug #11829681 - 60295: ERROR 1356 ON VIEW THAT EXECUTES FINE AS A QUERY Select from a view with the underlying HAVING clause failed with a message: "1356: View '...' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them" The bug is a regression of the fix for bug 11750328 - 40825 (similar case, but the HAVING cause references an aliased field). In the old fix for bug 40825 the Item_field::name_length value has been used in place of the real length of Item_field::name. However, in some cases Item_field::name_length is not in sync with the actual name length (TODO: combine name and name_length into a solid String field). The Item_ref::print() method has been modified to calculate actual name length every time. mysql-test/r/view.result: Test case for bug #11829681 mysql-test/t/view.test: Test case for bug #11829681 sql/item.cc: Bug #11829681 - 60295: ERROR 1356 ON VIEW THAT EXECUTES FINE AS A QUERY The Item_ref::print() method has been modified to calculate actual name length every time. sql/item.h: Minor commentary. --- mysql-test/r/view.result | 9 +++++++++ mysql-test/t/view.test | 12 ++++++++++++ sql/item.cc | 2 +- sql/item.h | 4 ++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 6b0a2103afa..2ca81f20cbb 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -3897,6 +3897,15 @@ DROP TABLE t1; # CREATE VIEW v1 AS SELECT 1 IN (1 LIKE 2,0) AS f; DROP VIEW v1; +# +# Bug 11829681 - 60295: ERROR 1356 ON VIEW THAT EXECUTES FINE AS A QUERY +# +CREATE TABLE t1 (a INT); +CREATE VIEW v1 AS SELECT s.* FROM t1 s, t1 b HAVING a; +SELECT * FROM v1; +a +DROP VIEW v1; +DROP TABLE t1; # ----------------------------------------------------------------- # -- End of 5.1 tests. # ----------------------------------------------------------------- diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index b1b3b5f2a83..1543924a7ad 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -3941,6 +3941,18 @@ DROP TABLE t1; CREATE VIEW v1 AS SELECT 1 IN (1 LIKE 2,0) AS f; DROP VIEW v1; +--echo # +--echo # Bug 11829681 - 60295: ERROR 1356 ON VIEW THAT EXECUTES FINE AS A QUERY +--echo # + +CREATE TABLE t1 (a INT); +CREATE VIEW v1 AS SELECT s.* FROM t1 s, t1 b HAVING a; + +SELECT * FROM v1; + +DROP VIEW v1; +DROP TABLE t1; + --echo # ----------------------------------------------------------------- --echo # -- End of 5.1 tests. --echo # ----------------------------------------------------------------- diff --git a/sql/item.cc b/sql/item.cc index 24c3107ece9..40be8b205bd 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -6121,7 +6121,7 @@ void Item_ref::print(String *str, enum_query_type query_type) { THD *thd= current_thd; append_identifier(thd, str, (*ref)->real_item()->name, - (*ref)->real_item()->name_length); + strlen((*ref)->real_item()->name)); } else (*ref)->print(str, query_type); diff --git a/sql/item.h b/sql/item.h index 8568e89542e..8d7ad3c41d3 100644 --- a/sql/item.h +++ b/sql/item.h @@ -515,6 +515,10 @@ public: */ Item *next; uint32 max_length; + /* + TODO: convert name and name_length fields into String to keep them in sync + (see bug #11829681/60295 etc). + */ uint name_length; /* Length of name */ int8 marker; uint8 decimals;