mycat learning-2- about joint table query

Before using database middleware, I thought that the operation of sub-database and sub-table may be very complicated for join table operations. Because if the data is stored in shards, if the data of the main table is in 1 shard, and the data corresponding to the slave table is in 2 shards, then this time the join table query needs to cross nodes. If the business is more complicated, it will obviously cause inconvenience. necessary performance loss. When I studied the mycat documentation today, I saw that mycat solved this problem very cleverly:

  MyCAT draws on the design ideas of Foundation DB, a rookie in the field of NewSQL. Foundation DB innovatively proposes the concept of Table Group, which depends on the storage location of sub-tables on the main table and stores them physically next to each other, thus completely solving the problem of JION. Efficiency and performance issues, according to this idea, a data sharding strategy based on ER relationship is proposed, the records of the child table and the associated parent table records are stored on the same data shard."

  There are currently two tables: tab_user(id,name) and tab_orders(id,user_id), and the id in tab_user is used as a foreign key in orders.

  Configure in schema.xml:  

<table name="tab_user" dataNode="dn1,dn2" rule="mod-long">
    <childTable name="tab_orders"  joinKey="user_id" parentKey="id"/>
</table>

  This configuration code tells mycat to associate the user_id of tab_orders with the id of tab_user. When inserting the orders table, it will determine which shard the user_id of the inserted data is in, and then insert the data into the shard, so that This achieves the purpose of storing the associated data in a shard. Of course, if more tables are associated, continue to configure childTable under childTable.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325397227&siteId=291194637