我需要加入两个数据库结果,第一个:
int mapStringToIntWithCache(std::string const& s) {
static std::unordered_map<std::string, int> cache;
auto pair = cache.emplace( s, 0 );
if( pair.second )
pair.first->second = myExpensiveFunction(s);
return pair.first->second;
}
它为我提供了包含数据类型的所有列,并且:
DESCRIBE my_table
为每个可能有一列的列提供 索引名称 。我需要在SHOW INDEXES FROM my_table
上加入它们,以便与DESCRIBE基本相同,但现在还有索引名称(如果它没有索引,则为show_indexes.Column_name = describe.Field
)而不是{{1} }或NULL
等。加入这两个结果就像使用两个PRI
一样,似乎不起作用。
这在MySQL中甚至可能吗?
答案 0 :(得分:0)
从INFORMATION_SCHEMA
1 - 显示等效的索引
SELECT * FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA = 'my_db' and TABLE_NAME = 'my_table';
2 - 描述等价物
SELECT COLUMN_NAME AS `Field`, COLUMN_TYPE AS `Type`, IS_NULLABLE AS `NULL`,
COLUMN_KEY AS `Key`, COLUMN_DEFAULT AS `Default`, EXTRA AS `Extra` FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = 'my_db' AND TABLE_NAME = 'my_table';
3 - 然后根据需要制定您的JOIN
查询,这是一个例如:
SELECT s.*, c.*
FROM
(
SELECT *
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = 'my_db' and TABLE_NAME = 'my_table'
) as s
RIGHT JOIN
(
SELECT COLUMN_NAME AS `Field`, COLUMN_TYPE AS `Type`, IS_NULLABLE AS `NULL`,
COLUMN_KEY AS `Key`, COLUMN_DEFAULT AS `Default`, EXTRA AS `Extra`
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = 'my_db' AND TABLE_NAME = 'my_table'
) as c
ON s.COLUMN_NAME = c.Field