从手册上看
http://dev.mysql.com/doc/refman/5.1/en/federated-description.html
When executing queries and statements on a FEDERATED table on the local server, the operations that would normally insert, update or delete information from a local data file are instead sent to the remote server for execution, where they update the data file on the remote server or return matching rows from the remote server.
这中间没有提到select……
没理解错的话,应该是在本地发起查询,实际上查询是送到远程服务器上去执行,然后返回执行结果。
但我今天做了个实验,令我怀疑这套说法
实验为:在A服务器上(64位)存了1亿条数据(分区表),然后在我机器上(32位)建立了对应的federated表,然后发起查询,在服务器上执行非常快(因为我查询的范围超过了分区表的最大范围),在我机器上查询,等了两分钟,期间内存飙升至2g,页面交换频繁,最后显示out of memory的错误!很明显,在我机器下该查询超出了32位机器的2g内存限制!
这就很奇怪了,难道federated是先将所有的数据获取下来,再select?
因为我除开这种情况想不到其他原因在本机上会发生out of memory错误。
后来又查看中文的mysql 5.1手册
http://dev.mysql.com/doc/refman/5.1/zh/storage-engines.html#federated-storage-engine
有一句话很意外:
数据取回被通过SELECT * FROM tbl_name SQL语句来初始化。要读这个结果,通过使用mysql_fetch_row() C API函数,行被一次取一个,然后从SELECT结果包中的列转换成FEDERATED处理器期望的格式。
这貌似从侧面证实了我的想法,那要federated的意义何在?迷糊了