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

the SQL in sys.schema_unused_indexes is over-simplified, and not aggregated across nodes #51269

Closed
YangKeao opened this issue Feb 23, 2024 · 0 comments · Fixed by #51270
Closed
Labels
severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@YangKeao
Copy link
Member

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

mysql> select * from sys.schema_unused_indexes;                                                                                                                                                                                    +---------------+-------------+------------+
| object_schema | object_name | index_name |
+---------------+-------------+------------+
| test          | t           | idx_1      |
| test          | t           | idx_2      |
| test          | t           | idx_1      |
| test          | t           | idx_2      |
+---------------+-------------+------------+
4 rows in set (0.00 sec)

An index in different nodes will appear multiple times in the sys.schema_unused_indexes. I forgot to finish the aggregation 🤦.

Re-write the SQL should work well:

CREATE OR REPLACE VIEW sys.schema_unused_indexes AS
		SELECT
			table_schema as object_schema,
			table_name as object_name,
			index_name
		FROM information_schema.cluster_tidb_index_usage
		WHERE
			table_schema not in ('sys', 'mysql', 'INFORMATION_SCHEMA', 'PERFORMANCE_SCHEMA') and
			index_name != 'PRIMARY'
		GROUP BY table_schema, table_name, index_name
		HAVING
			sum(last_access_time) is null;
@YangKeao YangKeao added the type/bug The issue is confirmed as a bug. label Feb 23, 2024
@YangKeao YangKeao changed the title The SQL in sys.schema_unused_indexes is over-simplified, and not aggregated across nodes the SQL in sys.schema_unused_indexes is over-simplified, and not aggregated across nodes Feb 23, 2024
@aytrack aytrack added the sig/sql-infra SIG: SQL Infra label Feb 27, 2024
ti-chi-bot bot pushed a commit that referenced this issue Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/major 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.

2 participants