Mycat一般的なSQL文の概要

2029 ワード

本文は主にMycatでよく見られるSQL文について簡単に説明し、更新を続けます.
  • order by+limit n,m文SQL文:
    # Mycat 
    EXPLAIN SELECT
    	*
    FROM
    	oms_track_trace
    WHERE
    	PUSH_STATUS IN (1101, 1103)
    AND PUSH_NUM < 20
    AND NEXT_PUSH_TIME < NOW()
    ORDER BY
    	CREATE_TIME ASC
    LIMIT 10,20
    実行計画:
    dn1	SELECT * FROM oms_track_trace WHERE PUSH_STATUS IN (1101, 1103)  AND PUSH_NUM < 20  AND NEXT_PUSH_TIME < NOW() ORDER BY CREATE_TIME ASC LIMIT 0, 30
    dn10	SELECT * FROM oms_track_trace WHERE PUSH_STATUS IN (1101, 1103)  AND PUSH_NUM < 20  AND NEXT_PUSH_TIME < NOW() ORDER BY CREATE_TIME ASC LIMIT 0, 30
    dn2	SELECT * FROM oms_track_trace WHERE PUSH_STATUS IN (1101, 1103)  AND PUSH_NUM < 20  AND NEXT_PUSH_TIME < NOW() ORDER BY CREATE_TIME ASC LIMIT 0, 30
    dn3	SELECT * FROM oms_track_trace WHERE PUSH_STATUS IN (1101, 1103)  AND PUSH_NUM < 20  AND NEXT_PUSH_TIME < NOW() ORDER BY CREATE_TIME ASC LIMIT 0, 30
    dn4	SELECT * FROM oms_track_trace WHERE PUSH_STATUS IN (1101, 1103)  AND PUSH_NUM < 20  AND NEXT_PUSH_TIME < NOW() ORDER BY CREATE_TIME ASC LIMIT 0, 30
    dn5	SELECT * FROM oms_track_trace WHERE PUSH_STATUS IN (1101, 1103)  AND PUSH_NUM < 20  AND NEXT_PUSH_TIME < NOW() ORDER BY CREATE_TIME ASC LIMIT 0, 30
    dn6	SELECT * FROM oms_track_trace WHERE PUSH_STATUS IN (1101, 1103)  AND PUSH_NUM < 20  AND NEXT_PUSH_TIME < NOW() ORDER BY CREATE_TIME ASC LIMIT 0, 30
    dn7	SELECT * FROM oms_track_trace WHERE PUSH_STATUS IN (1101, 1103)  AND PUSH_NUM < 20  AND NEXT_PUSH_TIME < NOW() ORDER BY CREATE_TIME ASC LIMIT 0, 30
    dn8	SELECT * FROM oms_track_trace WHERE PUSH_STATUS IN (1101, 1103)  AND PUSH_NUM < 20  AND NEXT_PUSH_TIME < NOW() ORDER BY CREATE_TIME ASC LIMIT 0, 30
    dn9	SELECT * FROM oms_track_trace WHERE PUSH_STATUS IN (1101, 1103)  AND PUSH_NUM < 20  AND NEXT_PUSH_TIME < NOW() ORDER BY CREATE_TIME ASC LIMIT 0, 30
    分析:Mycatは従来のlimitクエリーをサポートし、それ自体が元のsqlを解析し、limit n,mは各ルーティングのスライス上で自動的にlimit 0,n+mに解析する.次に、各スライスのデータをまとめ、order by順に従って、ビジネスに必要なlimit n,mデータを導出する.