查询时收到重复结果 information_schema

Receiving Duplicate Results When Querying information_schema

我正在 运行 进行快速查询,以确保我 table 中的所有外键都引用了已编入索引的字段。

我的代码如下:

select table_name, column_name, index_name from statistics where table_name in (select referenced_table_name from key_column_usage where table_name='table' and table_schema='schema') and column_name in (select referenced_column_name from key_column_usage where table_name='table' and table_schema='schema') order by table_name;

我 运行 在多个环境中都这样做,但出于某种原因,我在一个特定环境中收到了重复的结果。但是,table 的设置都是一样的,所以我不确定是什么导致了这种行为。

有什么建议吗?

在那个 mysql 服务器中,您可能有 2 个具有相同结构的数据库(模式),或者您有多列外键。在外部查询的 select 列表中包含 table_schema 字段以确认。

在查询的 where 子句中使用多列 in 运算符或内部联接,而不是多个单列 in 运算符。