Hello Sergey,
Please see my review below.
* gluh@stripped <gluh@stripped> [07/08/21 13:06]:
> ChangeSet@stripped, 2007-08-21 14:00:16+05:00, gluh@stripped +4 -0
> Bug#29408 Cannot find view in columns table if the selection contains a function
> we should use view db name as thread db name when
> connection is performed without db name
>
> mysql-test/r/sp.result@stripped, 2007-08-21 14:00:14+05:00, gluh@stripped +22 -0
> test result
>
> mysql-test/t/sp.test@stripped, 2007-08-21 14:00:14+05:00, gluh@stripped +32 -0
> test case
>
> sql/sql_parse.cc@stripped, 2007-08-21 14:00:15+05:00, gluh@stripped +1 -1
> copy thd->db_length to table_list->db_length
>
> sql/sql_view.cc@stripped, 2007-08-21 14:00:15+05:00, gluh@stripped +14 -0
> we should use view db name as thread db name when
> connection is performed without db name
>
> diff -Nrup a/mysql-test/r/sp.result b/mysql-test/r/sp.result
> --- a/mysql-test/r/sp.result 2007-07-30 04:33:31 +05:00
> +++ b/mysql-test/r/sp.result 2007-08-21 14:00:14 +05:00
> @@ -6314,4 +6314,26 @@ CALL p1();
> NULL
> SET NAMES default;
> DROP PROCEDURE p1;
> +create function f1()
> +returns int(11)
> +not deterministic
> +contains sql
> +sql security definer
> +comment ''
> +begin
> +declare x int(11);
> +set x=-1;
> +return x;
> +end|
> +create view v1 as select 1 as one, f1() as days;
> +show create view test.v1;
> +View Create View
> +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW
> `test`.`v1` AS select 1 AS `one`,`f1`() AS `days`
> +select column_name from information_schema.columns
> +where table_name='v1' and table_schema='test';
> +column_name
> +one
> +days
> +drop view v1;
> +drop function f1;
> End of 5.0 tests
> diff -Nrup a/mysql-test/t/sp.test b/mysql-test/t/sp.test
> --- a/mysql-test/t/sp.test 2007-07-30 04:33:10 +05:00
> +++ b/mysql-test/t/sp.test 2007-08-21 14:00:14 +05:00
> @@ -7299,4 +7299,36 @@ CALL p1();
> SET NAMES default;
> DROP PROCEDURE p1;
>
> +#
> +# Bug#29408 Cannot find view in columns table if the selection contains a function
> +#
> +delimiter |;
> +
> +create function f1()
> + returns int(11)
> +not deterministic
> +contains sql
> +sql security definer
> +comment ''
> +begin
> + declare x int(11);
> + set x=-1;
> + return x;
> +end|
> +
> +delimiter ;|
> +
> +create view v1 as select 1 as one, f1() as days;
> +
> +connect (bug29408, localhost, root,,*NO-ONE*);
> +connection bug29408;
> +
> +show create view test.v1;
> +select column_name from information_schema.columns
> +where table_name='v1' and table_schema='test';
> +
> +connection default;
> +drop view v1;
> +drop function f1;
Disconnect connection bug29408.
> diff -Nrup a/sql/sql_view.cc b/sql/sql_view.cc
> --- a/sql/sql_view.cc 2007-07-12 23:26:39 +05:00
> +++ b/sql/sql_view.cc 2007-08-21 14:00:15 +05:00
> @@ -1002,8 +1002,19 @@ bool mysql_make_view(THD *thd, File_pars
> table->view= lex= thd->lex= (LEX*) new(thd->mem_root) st_lex_local;
>
> {
> + char old_db_buf[NAME_LEN+1];
> + LEX_STRING old_db= { old_db_buf, sizeof(old_db_buf) };
> + bool dbchanged;
> Lex_input_stream lip(thd, table->query.str, table->query.length);
> thd->m_lip= &lip;
> +
> + /*
> + use view db name as thread db name when
> + connection is performed without db name
> + */
Since now we always change the db name, the comment is incorrect.
Should be:
Use view db name as thread default database, in order to ensure
that the view is parsed and prepared correctly.
> + if ((result= sp_use_new_db(thd, table->view_db, &old_db, 1,
> &dbchanged)))
> + goto end;
> +
> lex_start(thd);
> view_select= &lex->select_lex;
> view_select->select_number= ++thd->select_number;
> @@ -1045,6 +1056,9 @@ bool mysql_make_view(THD *thd, File_pars
>
> thd->variables.character_set_client= save_cs;
> thd->variables.sql_mode= save_mode;
> +
> + if (dbchanged && mysql_change_db(thd, &old_db, TRUE))
> + goto err;
> }
> if (!res && !thd->is_fatal_error)
> {
The patch is OK to push after these minor changes.
--
-- Konstantin Osipov Software Developer, Moscow, Russia
-- MySQL AB, www.mysql.com The best DATABASE COMPANY in the GALAXY