手册上有这么一句话:
•The FEDERATED storage engine supports SELECT, INSERT, UPDATE, DELETE, TRUNCATE TABLE, and indexes. It does not support ALTER TABLE, or any Data Definition Language statements that directly affect the structure of the table, other than DROP TABLE. The current implementation does not use prepared statements. 我测试时,在源表上建的所有,FEDERATED 表上看不到。在FEDERATED表上建索引,提示mysql> show create table user;
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                            |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| user  | CREATE TABLE `user` (
  `a` int(11) DEFAULT NULL,
  `ttoken` varchar(2048) DEFAULT NULL
) ENGINE=FEDERATED DEFAULT CHARSET=latin1 CONNECTION='mysql://root:[email protected]/test/user' |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)mysql> create index idx_2 on user(a);
ERROR 1031 (HY000): Table storage engine for 'user' doesn't have this option
mysql> 它说的支持INDEX,是怎么体现的?有用过FEDERATED的来说说看。

解决方案 »

  1.   

    确定源是有索引的,而且本查询也可以用到索引,但是在调用端,就看不到,也用不到索引。mysql> explain select * from user where a=1;
    +----+-------------+-------+------+---------------+------+---------+------+------+-------------+
    | id | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra       |
    +----+-------------+-------+------+---------------+------+---------+------+------+-------------+
    |  1 | SIMPLE      | user  | ALL  | NULL          | NULL | NULL    | NULL |    4 | Using where |
    +----+-------------+-------+------+---------------+------+---------+------+------+-------------+
    1 row in set (0.01 sec)mysql> show index from user;
    Empty set (0.01 sec)
      

  2.   

    源的索引如下:mysql> show create table user;
    +-------+--------------------------------
    | Table | Create Table
    +-------+--------------------------------
    | user  | CREATE TABLE `user` (
      `a` int(11) DEFAULT NULL,
      `ttoken` varchar(2048) DEFAULT NULL,
      KEY `idx_1` (`a`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
    +-------+--------------------------------
    1 row in set (0.00 sec)