mirror of
https://github.com/MariaDB/server.git
synced 2025-01-18 04:53:01 +01:00
Bug#40825: Error 1356 while selecting from a view
with a "HAVING" clause though query works SELECT from views defined like: CREATE VIEW v1 (view_column) AS SELECT c AS alias FROM t1 HAVING alias fails with an error 1356: View '...' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them CREATE VIEW form with a (column list) substitutes SELECT column names/aliases with names from a view column list. However, alias references in HAVING clause was not substituted. The Item_ref::print function has been modified to write correct aliased names of underlying items into VIEW definition generation/.frm file.
This commit is contained in:
parent
edc19ca252
commit
8a39147a6a
3 changed files with 44 additions and 1 deletions
|
@ -3704,6 +3704,25 @@ SELECT * FROM v1 IGNORE INDEX (c2) WHERE c2=2;
|
||||||
ERROR HY000: Key 'c2' doesn't exist in table 'v1'
|
ERROR HY000: Key 'c2' doesn't exist in table 'v1'
|
||||||
DROP VIEW v1;
|
DROP VIEW v1;
|
||||||
DROP TABLE t1;
|
DROP TABLE t1;
|
||||||
|
# -----------------------------------------------------------------
|
||||||
|
# -- Bug#40825: Error 1356 while selecting from a view
|
||||||
|
# -- with a "HAVING" clause though query works
|
||||||
|
# -----------------------------------------------------------------
|
||||||
|
|
||||||
|
CREATE TABLE t1 (c INT);
|
||||||
|
|
||||||
|
CREATE VIEW v1 (view_column) AS SELECT c AS alias FROM t1 HAVING alias;
|
||||||
|
SHOW CREATE VIEW v1;
|
||||||
|
View Create View
|
||||||
|
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`c` AS `view_column` from `t1` having `view_column`
|
||||||
|
SELECT * FROM v1;
|
||||||
|
view_column
|
||||||
|
|
||||||
|
DROP VIEW v1;
|
||||||
|
DROP TABLE t1;
|
||||||
|
|
||||||
|
# -- End of test case for Bug#40825
|
||||||
|
|
||||||
# -----------------------------------------------------------------
|
# -----------------------------------------------------------------
|
||||||
# -- End of 5.0 tests.
|
# -- End of 5.0 tests.
|
||||||
# -----------------------------------------------------------------
|
# -----------------------------------------------------------------
|
||||||
|
|
|
@ -3680,6 +3680,29 @@ SELECT * FROM v1 IGNORE INDEX (c2) WHERE c2=2;
|
||||||
DROP VIEW v1;
|
DROP VIEW v1;
|
||||||
DROP TABLE t1;
|
DROP TABLE t1;
|
||||||
|
|
||||||
|
--echo # -----------------------------------------------------------------
|
||||||
|
--echo # -- Bug#40825: Error 1356 while selecting from a view
|
||||||
|
--echo # -- with a "HAVING" clause though query works
|
||||||
|
--echo # -----------------------------------------------------------------
|
||||||
|
--echo
|
||||||
|
|
||||||
|
CREATE TABLE t1 (c INT);
|
||||||
|
|
||||||
|
--echo
|
||||||
|
|
||||||
|
CREATE VIEW v1 (view_column) AS SELECT c AS alias FROM t1 HAVING alias;
|
||||||
|
SHOW CREATE VIEW v1;
|
||||||
|
SELECT * FROM v1;
|
||||||
|
|
||||||
|
--echo
|
||||||
|
|
||||||
|
DROP VIEW v1;
|
||||||
|
DROP TABLE t1;
|
||||||
|
|
||||||
|
--echo
|
||||||
|
--echo # -- End of test case for Bug#40825
|
||||||
|
--echo
|
||||||
|
|
||||||
--echo # -----------------------------------------------------------------
|
--echo # -----------------------------------------------------------------
|
||||||
--echo # -- End of 5.0 tests.
|
--echo # -- End of 5.0 tests.
|
||||||
--echo # -----------------------------------------------------------------
|
--echo # -----------------------------------------------------------------
|
||||||
|
|
|
@ -5648,7 +5648,8 @@ void Item_ref::print(String *str)
|
||||||
!table_name && name && alias_name_used)
|
!table_name && name && alias_name_used)
|
||||||
{
|
{
|
||||||
THD *thd= current_thd;
|
THD *thd= current_thd;
|
||||||
append_identifier(thd, str, name, (uint) strlen(name));
|
append_identifier(thd, str, (*ref)->real_item()->name,
|
||||||
|
(*ref)->real_item()->name_length);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
(*ref)->print(str);
|
(*ref)->print(str);
|
||||||
|
|
Loading…
Reference in a new issue