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

SHOW DATABASES LIKE should be case insensitive #34766

Closed
espresso98 opened this issue May 18, 2022 · 8 comments · Fixed by #34925
Closed

SHOW DATABASES LIKE should be case insensitive #34766

espresso98 opened this issue May 18, 2022 · 8 comments · Fixed by #34925
Assignees
Labels
affects-6.1 help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. severity/minor sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@espresso98
Copy link
Collaborator

espresso98 commented May 18, 2022

Bug Report

1. Minimal reproduce step

DROP DATABASE IF EXISTS `TEST_$1`;
DROP DATABASE IF EXISTS `test_$2`;

CREATE DATABASE `TEST_$1`;
CREATE DATABASE `test_$2`;
SHOW DATABASES LIKE "TEST%";
SHOW DATABASES LIKE "test%";

DROP DATABASE `TEST_$1`;
DROP DATABASE `test_$2`;

2. What did you expect to see?

mysql> SHOW DATABASES LIKE "TEST%";
+------------------+
| Database (TEST%) |
+------------------+
| TEST_$1          |
| test_$2          |
+------------------+
2 rows in set (0.00 sec)

mysql> SHOW DATABASES LIKE "test%";
+------------------+
| Database (test%) |
+------------------+
| TEST_$1          |
| test_$2          |
+------------------+
2 rows in set (0.00 sec)

3. What did you see instead

SHOW DATABASES LIKE "TEST%";
+----------+
| Database |
+----------+
| TEST_$1  |
+----------+
1 row in set (0.00 sec)

mysql> SHOW DATABASES LIKE "test%";
+----------+
| Database |
+----------+
| test_$2  |
+----------+
1 row in set (0.00 sec)

4. What is your TiDB version?

tidb_version(): Release Version: v6.1.0-alpha-460-g2d44ac927
Edition: Community
Git Commit Hash: 2d44ac9274b4694ed237fc14e5d6500398e93164
Git Branch: master
UTC Build Time: 2022-05-19 04:40:29
GoVersion: go1.18.1
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
@espresso98 espresso98 added the type/bug The issue is confirmed as a bug. label May 18, 2022
@fanrenhoo
Copy link
Contributor

This should be correct I guess. Under linux, even mysql will be case sensitive for Database name

@espresso98
Copy link
Collaborator Author

I worked on macOS 11.2.3 (20D91).

@morgo morgo changed the title TiDB case sensitivity issue SHOW DATABASES LIKE should be case insensitive May 19, 2022
@morgo
Copy link
Contributor

morgo commented May 19, 2022

The bug here is with SHOW DATABASES LIKE. It should be showing databases that match in an insensitive manor, but it is infact case sensistive.

This is similar to #7518

@zimulala zimulala added the help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. label May 20, 2022
@likzn
Copy link
Contributor

likzn commented May 22, 2022

Is this the reason of it? https://docs.pingcap.com/tidb/v6.0/character-set-and-collation
TiDB defaults to using a binary collation. This differs from MySQL, which uses a case-insensitive collation by default.

I ran the below test, it can work. I assign collate of utf8mb4_general_ci.

func TestShowDatabasesLike(t *testing.T) {
	store, clean := testkit.CreateMockStore(t)
	defer clean()
	tk := testkit.NewTestKit(t, store)
	require.True(t, tk.Session().Auth(&auth.UserIdentity{
		Username: "root", Hostname: "%"}, nil, nil))

	tk.MustExec("DROP DATABASE IF EXISTS `TEST$1`")
	tk.MustExec("DROP DATABASE IF EXISTS `test$2`")
	tk.MustExec("CREATE DATABASE `TEST$1`;")
	tk.MustExec("CREATE DATABASE `test$2`;")

	tk.MustQuery("SHOW DATABASES LIKE 'TEST$%' COLLATE utf8mb4_general_ci;").Check(testkit.Rows("TEST$1", "test$2"))
	tk.MustQuery("SHOW DATABASES LIKE 'test$%' COLLATE utf8mb4_general_ci;").Check(testkit.Rows("TEST$1", "test$2"))
}

@hawkingrei
Copy link
Member

Is this the reason of it? https://docs.pingcap.com/tidb/v6.0/character-set-and-collation TiDB defaults to using a binary collation. This differs from MySQL, which uses a case-insensitive collation by default.

I ran the below test, it can work. I assign collate of utf8mb4_general_ci.

func TestShowDatabasesLike(t *testing.T) {
	store, clean := testkit.CreateMockStore(t)
	defer clean()
	tk := testkit.NewTestKit(t, store)
	require.True(t, tk.Session().Auth(&auth.UserIdentity{
		Username: "root", Hostname: "%"}, nil, nil))

	tk.MustExec("DROP DATABASE IF EXISTS `TEST$1`")
	tk.MustExec("DROP DATABASE IF EXISTS `test$2`")
	tk.MustExec("CREATE DATABASE `TEST$1`;")
	tk.MustExec("CREATE DATABASE `test$2`;")

	tk.MustQuery("SHOW DATABASES LIKE 'TEST$%' COLLATE utf8mb4_general_ci;").Check(testkit.Rows("TEST$1", "test$2"))
	tk.MustQuery("SHOW DATABASES LIKE 'test$%' COLLATE utf8mb4_general_ci;").Check(testkit.Rows("TEST$1", "test$2"))
}

Yes. but we also need to think of old users who are using the old collation.

@e1ijah1
Copy link
Contributor

e1ijah1 commented May 24, 2022

Hi, I'd like to work on this issue

@hawkingrei
Copy link
Member

Hi, I'd like to work on this issue

Great! Thank you~

@hawkingrei
Copy link
Member

SHOW TABLE had some problems and were fixed in #31919. so we add a filter plannercore.ShowPredicateExtractor in the ShowExec. It will bring the like expression to the place where to get meta and filter them for getting the right result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-6.1 help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. severity/minor sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants