create view under a schema can not be selected normally in another schema
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
Please answer these questions before submitting your issue. Thanks!
### 1. Minimal reproduce step (Required)
```
MySQL [test]> show create table t1;
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t1 | CREATE TABLE `t1` (
`id` int NOT NULL,
`name` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.001 sec)
MySQL [test]> show create table t2;
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t2 | CREATE TABLE `t2` (
`id` bigint NOT NULL AUTO_INCREMENT,
`name` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=30001 |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.001 sec)
MySQL [test]> create view test.t_t1 as
-> select * from (
-> with a as (select * from test.t1),
-> b as (select * from test.t2),
-> c as (select count(*) from (select * from test.t1
-> union all
-> select * from test.t2 )combined )
-> select * from c
-> ) d;
Query OK, 0 rows affected (0.085 sec)
MySQL [test]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MySQL [mysql]> select * from test.t_t1;
ERROR 1356 (HY000): View 'test.t_t1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
MySQL [mysql]> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MySQL [test]> select * from test.t_t1;
+----------+
| count(*) |
+----------+
| 12293 |
+----------+
1 row in set (0.011 sec)
MySQL [test]> show create view test.t_t1;
+------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
| View | Create View | character_set_client | collation_connection |
+------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
| t_t1 | CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`%` SQL SECURITY DEFINER VIEW `t_t1` (`count(*)`) AS SELECT `test`.`d`.`count(*)` AS `count(*)` FROM (WITH `a` AS (SELECT `test`.`t1`.`id` AS `id`,`test`.`t1`.`name` AS `name` FROM `test`.`t1`), `b` AS (SELECT `test`.`t2`.`id` AS `id`,`test`.`t2`.`name` AS `name` FROM `test`.`t2`), `c` AS (SELECT COUNT(1) AS `count(*)` FROM (SELECT `test`.`t1`.`id` AS `id`,`test`.`t1`.`name` AS `name` FROM `test`.`t1` UNION ALL SELECT `test`.`t2`.`id` AS `id`,`test`.`t2`.`name` AS `name` FROM `test`.`t2`) AS `combined`) SELECT `c`.`count(*)` AS `count(*)` FROM `c`) AS `d` | utf8 | utf8_general_ci |
+------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
1 row in set (0.001 sec)
```
### 2. What did you expect to see? (Required)
normally select the view under another schema
### 3. What did you see instead (Required)
abnormally select the view under another schema
### 4. What is your TiDB version? (Required)
V8.5.3
Contributor guide
Assessment
This issue has not been assessed yet.