简体   繁体   English

是否有任何ORM框架支持跨数据库/跨服务器联接?

[英]Do any ORM frameworks support cross-database/cross-server joins?

I have two servers: 我有两台服务器:

  • Server A: MySql 服务器A:MySql
    • Table A 表A
      • key-a
      • foreign-key-b 外键-b
  • Server B: MsSql 服务器B:MsSql
    • Table B 表B
      • key-b 键b
      • foreign-key-a 外键

Presumably I have two objects with methods that handle the relationships: 大概我有两个带有处理关系的方法的对象:

TableA->getRelatedTableB(); TableA-> getRelatedTableB();

TableB->getRelatedTableA(); TableB-> getRelatedTableA();

This is easy to implement in most ORMs. 这在大多数ORM中都很容易实现。 But what if I want to get a large set of objects with only one query per database server? 但是,如果我想在每个数据库服务器上仅通过一个查询获得大量对象,该怎么办? Ideally the framework would abstract this and do the logical join so that the developer can pretend he doesn't know anything about the database(s). 理想情况下,框架将对此进行抽象并进行逻辑连接,以便开发人员可以假装自己对数据库一无所知。 Something like: 就像是:

FinderObject->getAlotOfTableAObjectsWithTableBAlreadyLoaded() FinderObject-> getAlotOfTableAObjectsWithTableBAlreadyLoaded()

and it would perform a query on each database and logically join the results in some efficient manner. 它将在每个数据库上执行查询,并以某种有效的方式将结果逻辑上合并。


Does anyone know of a way to implement this in Doctrine or some other php ORM framework? 有谁知道在Doctrine或其他PHP ORM框架中实现此目的的方法?

Doctrine doesn't explicitly support cross-database joins, but there is a way to do it: Doctrine不明确支持跨数据库联接,但是有一种方法可以做到:

http://www.doctrine-project.org/blog/cross-database-joins http://www.doctrine-project.org/blog/cross-database-joins

One solution for this is to use federated tables , but I've read that this hasn't a good performance. 解决此问题的一种方法是使用联合表 ,但我已经读到它的性能不好。 All depends in how you need to use it. 一切都取决于您需要如何使用它。

I don't know of any that do... BUT maybe you could use Propel, Memcached, and MySQL together . 我不知道该怎么做...但是也许您可以一起使用Propel, Memcached和MySQL Setup a distributed memory cache using Memcached, and see if there's a way to store some MySQL data in there. 使用Memcached设置分布式内存缓存,并查看是否有一种方法可以在其中存储一些MySQL数据。 Because Memcached is distributed, both of your MySQL servers could store data there. 由于Memcached是分布式的,因此两个MySQL服务器都可以在其中存储数据。 Then you'd have to find a way to access that memory (via Memory Tables?). 然后,您必须找到一种方法(通过Memory Tables)访问该内存。 Seems a very tricky situation. 似乎是一个非常棘手的情况。

Perhaps the problem is being approached from the wrong direction. 也许是从错误的方向解决了问题。 Could you tell us what problem you're trying to solve? 您能告诉我们您要解决什么问题吗? There might be a completely different (and simpler!) solution just around the corner. 指日可待,可能会有一个完全不同的(并且更简单!)解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM