Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APIJSON支持left join 、union all、子查询等其他复杂sql吗 #98

Open
zhangxiaozhang opened this issue Jul 8, 2019 · 3 comments
Labels
Enhancement 增强 增强功能、提高性能等

Comments

@zhangxiaozhang
Copy link

环境信息

  • 系统:
  • JDK:
  • 数据库:
  • APIJSON:

问题描述

错误信息

@TommyLemon
Copy link
Collaborator

TommyLemon commented Jul 8, 2019

JOIN 和 子查询 见 3.2 功能符
https://github.com/APIJSON/APIJSON/blob/master/Document.md#3.2

目前还不支持 UNION ALL,可以用主副表条件 OR 连接的 INNER JOIN 替代("join": "/ViceTable/refKey@")
也可以在建议收集箱加一个新增功能的建议
https://github.com/APIJSON/APIJSON/issues/37

@TommyLemon TommyLemon added the Enhancement 增强 增强功能、提高性能等 label Aug 6, 2019
@gsqatm
Copy link

gsqatm commented May 6, 2020

JOIN和子查询见3.2功能符
https://github.com/APIJSON/APIJSON/blob/master/Document.md#3.2

目前还不支持UNION ALL,可以用主副表条件或连接的INNER JOIN替代(“ join”:“ / ViceTable / refKey @”)
也可以在建议收集箱加一个补充功能的建议
#37

LEFT JOIN中,除了主表,其他表为何要先建立临时表?
例如:
{
"[]": {
"join": "</User/id@,</Comment/momentId@",
"Moment": {},
"User": {
"name~": "t",
"id@": "/Moment/userId"
},
"Comment": {
"momentId@": "/Moment/id"
}
},
"@Explain": true
}

SQL:
SELECT Moment.*, User.*, Comment.* FROM apijson_demo.Moment AS Moment LEFT JOIN ( SELECT * FROM apijson_demo.apijson_user WHERE ( (name REGEXP BINARY 't') ) ) AS User ON User.id = Moment.userId LEFT JOIN ( SELECT * FROM apijson_demo.Comment ) AS Comment ON Comment.momentId = Moment.id LIMIT 10 OFFSET 0

@TommyLemon
Copy link
Collaborator

TommyLemon commented Dec 17, 2020

JOIN和子查询见3.2功能符
https://github.com/APIJSON/APIJSON/blob/master/Document.md#3.2
目前还不支持UNION ALL,可以用主副表条件或连接的INNER JOIN替代(“ join”:“ / ViceTable / refKey @”)
也可以在建议收集箱加一个补充功能的建议
#37

LEFT JOIN中,除了主表,其他表为何要先建立临时表?
例如:
{
"[]": {
"join": "</User/id@,</Comment/momentId@",
"Moment": {},
"User": {
"name~": "t",
"id@": "/Moment/userId"
},
"Comment": {
"momentId@": "/Moment/id"
}
},
"@Explain": true
}

SQL:
SELECT Moment.*, User.*, Comment.* FROM apijson_demo.Moment AS Moment LEFT JOIN ( SELECT * FROM apijson_demo.apijson_user WHERE ( (name REGEXP BINARY 't') ) ) AS User ON User.id = Moment.userId LEFT JOIN ( SELECT * FROM apijson_demo.Comment ) AS Comment ON Comment.momentId = Moment.id LIMIT 10 OFFSET 0

如果移到外层就不支持副表带条件了。

这个不会影响性能,像

LEFT JOIN ( SELECT * FROM `apijson_demo`.`Comment` ) AS `Comment`

image

这种简单的子查询,MySQL 5.7+ 会自动优化为

LEFT JOIN `apijson_demo`.`Comment` AS `Comment`

image

见以上两条 SQL 下的两张 EXPLAIN 效果图,执行过程一样

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement 增强 增强功能、提高性能等
Projects
None yet
Development

No branches or pull requests

3 participants