數據庫水平切分(MyCat分片Join)

Mycat(proxy中間件層)mysql

Sharding-jdbc(TDDL爲表明的應用層)sql

分片Join

1.全局表  工具

2.Share Join性能

mysql> /*!mycat:catlet=io.mycat.catlets.ShareJoin*/select * from employee a, employee_detail b where a.id = b.id;spa

目前只支持兩張分片表的Join。3d

3.ER表code

<table name="customer" primaryKey="ID" dataNode="dn1,dn2" rule="sharding-by-intfile">
      <childTable name="orders" primaryKey="ID" joinKey="customer_id" parentKey="id">
              <childTable name="order_items" joinKey="order_id"  parentKey="id" />
      </childTable>
      <childTable name="customer_addr" primaryKey="ID" joinKey="customer_id" parentKey="id" />
 </table>

childTable標籤用來聲明子表:xml

joinKey:聲明子表的那個字段和主表關聯中間件

parentKey:聲明主表的關聯主鍵blog

primaryKey:主表自身的主鍵

Mycat分頁

分頁的大坑必定要注意:

    mysql> select *  from customer order by id limit 1000000,100;

    Mycat會分紅:

       1 -> dn1{SELECT * FROM customer ORDER BY id LIMIT 0, 1000100}

       2 -> dn2{SELECT * FROM customer ORDER BY id LIMIT 0, 1000100}

開啓使用非堆內存。減小內容消耗

<property name="useOffHeapForMerge">1</property>

 

Catlet使用

MyCat註解規範

  1. 註解SQL使用select語句,不容許使用delete/update/insert等語句;雖然delete/update/insert等語句也能用在註解中,但這些語句在Sql處理中有額外的邏輯判斷,從性能考慮,請使用select語句。
  2. 註解SQL禁用表關聯語句。
  3. 註解SQL儘可能用最簡單的SQL語句,如select id from tab_a where id=’10000’(若是必要,最好能在註解中指定分片)
  4. 不管是原始SQL 仍是註解SQL,禁止DDL語句
  5. 能不用註解的儘可能不用

建立存儲過程:

/*!mycat:sql=select 1 from customer*/create producer ‘test_proc()’ BEGIN END;

調用存儲過程:

/*!mycat:sql=select 1 from customer*/call ‘test_proc()’;

 

Mycat管理端使用

Zookeeper工具:ZooInspector

相關文章
相關標籤/搜索