One - One Code All

Blog Content

Mycat不支持的SQL语句总结

ElasticSearch   2020-04-19 15:22:56

这篇文章是转载,主要是在研究elasticsearch sql查询问题,顺腾摸瓜,从druid 摸到 mycat。

转载此文作为备忘。


转载网址:https://blog.csdn.net/liupeifeng3514/article/details/78988371



SELECT:


    跨分片(实体库)的交叉查询

    跨节点的联合查询 (如用户库的表和平台库的表做联合查询)


INSERT:


    插入的字段不包含分片字段 (如插入tbl_user_base_info表,没有提供user_id列)

    插入的分片字段找不到对应分片

    复制插入:Insert into…select…

    多行插入:insert into tab_a(c1,c2) values(v1,v2),(v11,v21)…


UPDATE:


    更新的列包含分片列

    多表更新:update a, b set a.nation='China', b.pwd='123456' where a.id=b.id;

    复杂更新:update a, b set a.nation='China' where a.id=b.id; 但支持子查询方式update a set a.nation='China' where id in (select id from b);


DELETE:


    复杂删除:delete a from a join b on a.id=b.id;

    支持子查询方式:delete from a where a.id in (select id from b), 但表不能起别名


其它:


    Call procedure():MyCat未支持存储过程定义, 因而不允许调用存储过程,但可通过注解来调用各个分片上的存储过程

    Select func():不支持这种方式直接调用自定义函数,但支持select id, func() from employee,只需employee所在的所有分片上存在这个函数。MySql自带函数可随意使用。


注意事项:


    Order by字段必须出现在select中(MyCat先将结果取出,然后排序);

    Group by务必使用标准语法select count(1),type from tab_a group by type;

    MyCat的一些自带函数sum,min,max等可以正确使用,但多分片执行的avg有bug,执行的结果是错误的。

    谨慎使用子查询,外层查询没有分片查询条件,则会在所有分片上执行(子查询内外层的表一样较为特殊)。



上一篇:ElasticSearch opendistro插件的CURL方式的SQL查询
下一篇:Elasticsearch相关资源下载地址

The minute you think of giving up, think of the reason why you held on so long.