两年半后,因为我对这个问题很感兴趣:您确实可以使用命名不佳的“对象”表找到给定键的列。
例如,考虑下表
CREATE TABLE indextest (a INT, b INT);
ALTER TABLE indextest ADD CONSTRAINT indextest_pk PRIMARY KEY (a);
ALTER TABLE indextest ADD CONSTRAINT indextest_uq UNIQUE (a, b);
现在让我们找出哪些列属于indextest_uq
:
SELECT idxs.id AS index_id, columns.id AS column_id, tables.name AS table_name, columns.name AS column_name, columns.type AS column_type
FROM idxs JOIN objects ON idxs.id=objects.id JOIN tables ON idxs.table_id=tables.id JOIN columns ON idxs.table_id=columns.table_id AND objects.name=columns.name
WHERE idxs.name='indextest_uq';
此查询的结果如下所示:
+----------+-----------+------------+-------------+-------------+
| index_id | column_id | table_name | column_name | column_type |
+==========+===========+============+=============+=============+
| 6446 | 6438 | indextest | a | int |
| 6446 | 6439 | indextest | b | int |
+----------+-----------+------------+-------------+-------------+
显然,可以通过扩展查询部分来包含来自columns
和表的更多信息。tables
SELECT