Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning 1356 is returned and result is empty by querying information_schema.columns when a scalar subquery is used as a column in view definition #54343

Closed
pcqz opened this issue Jul 1, 2024 · 2 comments · Fixed by #54791
Labels
affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. component/ddl This issue is related to DDL of TiDB. report/community The community has encountered this bug. report/customer Customers have encountered this bug. severity/major type/bug The issue is confirmed as a bug.

Comments

@pcqz
Copy link

pcqz commented Jul 1, 2024

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

mysql> create table t1(id int);
Query OK, 0 rows affected (0.06 sec)

mysql> create view v1 as select (select id from t1) as col from dual;
Query OK, 0 rows affected (0.07 sec)

mysql> select column_name, table_name from information_schema.columns where table_name='v1';
Empty set, 1 warning (0.00 sec)

mysql> show warnings;
+---------+------+---------------------------------------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                                                   |
+---------+------+---------------------------------------------------------------------------------------------------------------------------+
| Warning | 1356 | View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them |
+---------+------+---------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

2. What did you expect to see? (Required)

+-------------+------------+
| column_name | table_name |
+-------------+------------+
| col         | v1         |
+-------------+------------+

3. What did you see instead (Required)

The warning 1356 is reported.

4. What is your TiDB version? (Required)

v6.1.0 and above

@pcqz pcqz added the type/bug The issue is confirmed as a bug. label Jul 1, 2024
@pcqz pcqz changed the title empty resultreturn when scalar subqueries are used as columns in a view Warning 1356 is returned by querying information_schema.columns when a scalar subquery is used as a column in view definition Jul 1, 2024
@pcqz
Copy link
Author

pcqz commented Jul 1, 2024

Possibly related to the use of sys session after #33946.

@jebter jebter added severity/major component/ddl This issue is related to DDL of TiDB. labels Jul 2, 2024
@seiya-annie seiya-annie added the report/customer Customers have encountered this bug. label Jul 5, 2024
@ti-chi-bot ti-chi-bot added affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. and removed may-affects-7.5 may-affects-6.5 may-affects-7.1 may-affects-8.1 labels Jul 9, 2024
@lance6716 lance6716 added the affects-6.1 This bug affects the 6.1.x(LTS) versions. label Jul 23, 2024
@lance6716 lance6716 added the affects-5.4 This bug affects the 5.4.x(LTS) versions. label Jul 23, 2024
@ti-chi-bot ti-chi-bot bot removed the may-affects-5.4 This bug maybe affects 5.4.x versions. label Jul 23, 2024
@lance6716 lance6716 changed the title Warning 1356 is returned by querying information_schema.columns when a scalar subquery is used as a column in view definition Warning 1356 is returned and result is empty by querying information_schema.columns when a scalar subquery is used as a column in view definition Dec 12, 2024
@lance6716
Copy link
Contributor

not only there are warnings. The result set is empty before the fix

6.5.8

mysql> use test;
Database changed
mysql> create table t(a int);
Query OK, 0 rows affected (0.12 sec)

mysql> create view v as select * from t where a = (select max(t2.a) from t t2) or a = (select min(t2.a) from t t2);
Query OK, 0 rows affected (0.10 sec)

mysql> select * from information_schema.columns where table_name = 'v' and table_schema = 'test';
Empty set, 1 warning (0.01 sec)

mysql> show warnings;
+---------+------+--------------------------------------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                                                  |
+---------+------+--------------------------------------------------------------------------------------------------------------------------+
| Warning | 1356 | View 'test.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them |
+---------+------+--------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

6.5.11 (include the fix)

mysql> use test;
Database changed
mysql> create table t(a int);
Query OK, 0 rows affected (0.08 sec)

mysql> create view v as select * from t where a = (select max(t2.a) from t t2) or a = (select min(t2.a) from t t2);
Query OK, 0 rows affected (0.12 sec)

mysql> select * from information_schema.columns where table_name = 'v' and table_schema = 'test';
+---------------+--------------+------------+-------------+------------------+----------------+-------------+-----------+--------------------------+------------------------+-------------------+---------------+--------------------+--------------------+----------------+-------------+------------+-------+---------------------------------+----------------+-----------------------+
| TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | COLUMN_NAME | ORDINAL_POSITION | COLUMN_DEFAULT | IS_NULLABLE | DATA_TYPE | CHARACTER_MAXIMUM_LENGTH | CHARACTER_OCTET_LENGTH | NUMERIC_PRECISION | NUMERIC_SCALE | DATETIME_PRECISION | CHARACTER_SET_NAME | COLLATION_NAME | COLUMN_TYPE | COLUMN_KEY | EXTRA | PRIVILEGES                      | COLUMN_COMMENT | GENERATION_EXPRESSION |
+---------------+--------------+------------+-------------+------------------+----------------+-------------+-----------+--------------------------+------------------------+-------------------+---------------+--------------------+--------------------+----------------+-------------+------------+-------+---------------------------------+----------------+-----------------------+
| def           | test         | v          | a           |                1 | NULL           | YES         | int       |                     NULL |                   NULL |                11 |             0 |               NULL | NULL               | NULL           | int(11)     |            |       | select,insert,update,references |                |                       |
+---------------+--------------+------------+-------------+------------------+----------------+-------------+-----------+--------------------------+------------------------+-------------------+---------------+--------------------+--------------------+----------------+-------------+------------+-------+---------------------------------+----------------+-----------------------+
1 row in set (0.01 sec)

@seiya-annie seiya-annie added the report/community The community has encountered this bug. label Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. component/ddl This issue is related to DDL of TiDB. report/community The community has encountered this bug. report/customer Customers have encountered this bug. severity/major type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants