阅读(4082) (13)

Mycat2 BKAJOIN(values)

2021-09-09 14:56:33 更新

形式2:Values语句(MySQL8.0.19以后支持Values语法,Mycat2支持使用该形式下推BKAJOIN)

该形式默认不启用,因为它与特定数据库版本有关。

基本形式

SELECT * FROM (VALUES  ROW('4'),
            ROW('8'),
            ROW('1'),
            ROW('5'),
            ROW('9'),
            ROW('2'),
            ROW('6'),
            ROW('3'),
            ROW('7') ) AS `t`
    LEFT JOIN db1.company AS `normal` ON (`t`.`column_0` = `normal`.`id`)
    INNER JOIN db1.global AS `global` ON (`t`.`column_0` = `global`.`id`)

其中 db1.companydb1.global都是单表或全局表。而且会先把左表数据完整读取后,再拼接成右表,然后右表数据一次查询。

由于Values不支持0行数据,所以左表没有数据的时候,右表不会发送SQL查询。

它可以使用use_values_join启用

样例:

/*+MYCAT:use_values_join(s,e) use_values_join(s,g)*/
SELECT * FROM db1.sharding s LEFT JOIN db1.normal e ON s.id = e.id INNER JOIN db1.global g ON s.id = g.id  ORDER BY s.id


plan
MycatProject(id=[$0], user_id=[$1], traveldate=[$2], fee=[$3], days=[$4], blob=[$5], id0=[$6], companyname=[$7], addressid=[$8], id1=[$9], companyname0=[$10], addressid0=[$11])
  MycatMemSort(sort0=[$0], dir0=[ASC])
    MycatSQLTableLookup(condition=[=($0, $6)], joinType=[left], type=[NONE], correlationIds=[[$cor0]], leftKeys=[[0]])
      MycatView(distribution=[[db1.sharding]])
      MycatView(distribution=[[db1.global, db1.normal]])
Each(targetName=prototype, sql=SELECT * FROM (VALUES  $cor0 ) AS `t`     LEFT JOIN db1.normal AS `normal` ON (`t`.`column_0` = `normal`.`id`)     INNER JOIN db1.global AS `global` ON (`t`.`column_0` = `global`.`id`))
Each(targetName=c0, sql=SELECT * FROM db1_0.sharding_0 AS `sharding` union all SELECT * FROM db1_0.sharding_1 AS `sharding`)
Each(targetName=c1, sql=SELECT * FROM db1_1.sharding_2 AS `sharding` union all SELECT * FROM db1_1.sharding_3 AS `sharding`)