summaryrefslogtreecommitdiff
path: root/mysql-test
diff options
context:
space:
mode:
authorunknown <dlenev@mysql.com>2006-04-22 11:54:25 +0400
committerunknown <dlenev@mysql.com>2006-04-22 11:54:25 +0400
commitdc526db887e3ab68020d7d010f45fb9ce5d3ad14 (patch)
treeecf3a34a7ac46e3bb6a852899de62880d2156f2f /mysql-test
parentbf8f30b532ef217dac2a168124706d28e19a320f (diff)
downloadmariadb-git-dc526db887e3ab68020d7d010f45fb9ce5d3ad14.tar.gz
Fix for bug#15153 "CONVERT_TZ() is not allowed in all places in VIEWs".
Error was emitted when one tried to select information from view which used merge algorithm and which also had CONVERT_TZ() function in its select list. This bug was caused by wrong assumption that global table list for view which is handled using merge algorithm begins from tables belonging to the main select of this view. Nowadays the above assumption is not true only when one uses convert_tz() function in view's select list, but in future other cases may be added (for example we may support merging of views with subqueries in select list one day). Relying on this false assumption led to the usage of wrong table list for field lookups and therefor errors. With this fix we explicitly use pointer to the beginning of main select's table list. mysql-test/r/timezone_grant.result: Added additional test case for bug#15153 "CONVERT_TZ() is not allowed in all places in VIEWs" that checks that usage of CONVERT_TZ() function in view does not require additional privileges. mysql-test/r/view.result: Added test case for bug#15153 "CONVERT_TZ() is not allowed in all places in VIEWs". mysql-test/t/timezone_grant.test: Added additional test case for bug#15153 "CONVERT_TZ() is not allowed in all places in VIEWs" that checks that usage of CONVERT_TZ() function in view does not require additional privileges. mysql-test/t/view.test: Added test case for bug#15153 "CONVERT_TZ() is not allowed in all places in VIEWs". sql/sql_view.cc: mysql_make_view(): We should not assume that global table list for view which is handled using merge algorithm begins from tables belonging to the main select of this view. Nowadays the above assumption is not true only when one uses convert_tz() function in view's select list, but in future other cases may be added (for example we may support merging of views with subqueries in select list one day). So let us instead explicitly use pointer to the beginning of main select's table list.
Diffstat (limited to 'mysql-test')
-rw-r--r--mysql-test/r/timezone_grant.result17
-rw-r--r--mysql-test/r/view.result26
-rw-r--r--mysql-test/t/timezone_grant.test31
-rw-r--r--mysql-test/t/view.test27
4 files changed, 101 insertions, 0 deletions
diff --git a/mysql-test/r/timezone_grant.result b/mysql-test/r/timezone_grant.result
index 3758f3c2645..2f4d46dfdc0 100644
--- a/mysql-test/r/timezone_grant.result
+++ b/mysql-test/r/timezone_grant.result
@@ -1,3 +1,5 @@
+drop tables if exists t1, t2;
+drop view if exists v1;
delete from mysql.user where user like 'mysqltest\_%';
delete from mysql.db where user like 'mysqltest\_%';
delete from mysql.tables_priv where user like 'mysqltest\_%';
@@ -59,3 +61,18 @@ delete from mysql.db where user like 'mysqltest\_%';
delete from mysql.tables_priv where user like 'mysqltest\_%';
flush privileges;
drop table t1, t2;
+create table t1 (a int, b datetime);
+insert into t1 values (1, 20010101000000), (2, 20020101000000);
+grant all privileges on test.* to mysqltest_1@localhost;
+create view v1 as select a, convert_tz(b, 'UTC', 'Europe/Moscow') as lb from t1;
+select * from v1;
+a lb
+1 2001-01-01 03:00:00
+2 2002-01-01 03:00:00
+select * from v1, mysql.time_zone;
+ERROR 42000: SELECT command denied to user 'mysqltest_1'@'localhost' for table 'time_zone'
+drop view v1;
+create view v1 as select a, convert_tz(b, 'UTC', 'Europe/Moscow') as lb from t1, mysql.time_zone;
+ERROR 42000: ANY command denied to user 'mysqltest_1'@'localhost' for table 'time_zone'
+drop table t1;
+drop user mysqltest_1@localhost;
diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result
index b52e6b58c0e..890e5be66c6 100644
--- a/mysql-test/r/view.result
+++ b/mysql-test/r/view.result
@@ -2623,3 +2623,29 @@ select * from v1;
ERROR HY000: Recursive stored functions and triggers are not allowed.
drop function f1;
drop view t1, v1;
+create table t1 (dt datetime);
+insert into t1 values (20040101000000), (20050101000000), (20060101000000);
+create view v1 as select convert_tz(dt, 'UTC', 'Europe/Moscow') as ldt from t1;
+select * from v1;
+ldt
+2004-01-01 03:00:00
+2005-01-01 03:00:00
+2006-01-01 03:00:00
+drop view v1;
+create view v1 as select * from t1 where convert_tz(dt, 'UTC', 'Europe/Moscow') >= 20050101000000;
+select * from v1;
+dt
+2005-01-01 00:00:00
+2006-01-01 00:00:00
+create view v2 as select * from v1 where dt < 20060101000000;
+select * from v2;
+dt
+2005-01-01 00:00:00
+drop view v2;
+create view v2 as select convert_tz(dt, 'UTC', 'Europe/Moscow') as ldt from v1;
+select * from v2;
+ldt
+2005-01-01 03:00:00
+2006-01-01 03:00:00
+drop view v1, v2;
+drop table t1;
diff --git a/mysql-test/t/timezone_grant.test b/mysql-test/t/timezone_grant.test
index f94d86eb266..450c1edc47e 100644
--- a/mysql-test/t/timezone_grant.test
+++ b/mysql-test/t/timezone_grant.test
@@ -1,6 +1,11 @@
# Embedded server testing does not support grants
-- source include/not_embedded.inc
+--disable_warnings
+drop tables if exists t1, t2;
+drop view if exists v1;
+--enable_warnings
+
#
# Test for bug #6116 "SET time_zone := ... requires access to mysql.time_zone
# tables". We should allow implicit access to time zone description tables
@@ -82,3 +87,29 @@ flush privileges;
drop table t1, t2;
# End of 4.1 tests
+
+#
+# Additional test for bug #15153: CONVERT_TZ() is not allowed in all
+# places in views.
+#
+# Let us check that usage of CONVERT_TZ() function in view does not
+# require additional privileges.
+
+# Let us rely on that previous tests done proper cleanups
+create table t1 (a int, b datetime);
+insert into t1 values (1, 20010101000000), (2, 20020101000000);
+grant all privileges on test.* to mysqltest_1@localhost;
+connect (tzuser3, localhost, mysqltest_1,,);
+create view v1 as select a, convert_tz(b, 'UTC', 'Europe/Moscow') as lb from t1;
+select * from v1;
+# Of course we should not be able select from mysql.time_zone tables
+--error ER_TABLEACCESS_DENIED_ERROR
+select * from v1, mysql.time_zone;
+drop view v1;
+--error ER_TABLEACCESS_DENIED_ERROR
+create view v1 as select a, convert_tz(b, 'UTC', 'Europe/Moscow') as lb from t1, mysql.time_zone;
+connection default;
+drop table t1;
+drop user mysqltest_1@localhost;
+
+# End of 5.0 tests
diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test
index 81fb161b69a..8f759c2d43e 100644
--- a/mysql-test/t/view.test
+++ b/mysql-test/t/view.test
@@ -2485,3 +2485,30 @@ rename table v2 to t1;
select * from v1;
drop function f1;
drop view t1, v1;
+
+#
+# Bug #15153: CONVERT_TZ() is not allowed in all places in VIEWs
+#
+# Error was reported when one tried to use CONVERT_TZ() function
+# select list of view which was processed using MERGE algorithm.
+# (Also see additional test in timezone_grant.test)
+create table t1 (dt datetime);
+insert into t1 values (20040101000000), (20050101000000), (20060101000000);
+# Let us test that convert_tz() can be used in view's select list
+create view v1 as select convert_tz(dt, 'UTC', 'Europe/Moscow') as ldt from t1;
+select * from v1;
+drop view v1;
+# And in its where part
+create view v1 as select * from t1 where convert_tz(dt, 'UTC', 'Europe/Moscow') >= 20050101000000;
+select * from v1;
+# Other interesting case - a view which uses convert_tz() function
+# through other view.
+create view v2 as select * from v1 where dt < 20060101000000;
+select * from v2;
+drop view v2;
+# And even more interesting case when view uses convert_tz() both
+# directly and indirectly
+create view v2 as select convert_tz(dt, 'UTC', 'Europe/Moscow') as ldt from v1;
+select * from v2;
+drop view v1, v2;
+drop table t1;