You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/11/07 08:16:03 UTC

[shardingsphere] branch master updated: update the subquery document (#8064)

This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new faa4ff6  update the subquery document (#8064)
faa4ff6 is described below

commit faa4ff60876f5e403e61547d415364b43b238613
Author: Zhengqiang Duan <st...@gmail.com>
AuthorDate: Sat Nov 7 16:15:41 2020 +0800

    update the subquery document (#8064)
---
 docs/document/content/features/sharding/use-norms/sql.cn.md | 9 ++++++---
 docs/document/content/features/sharding/use-norms/sql.en.md | 9 ++++++---
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/docs/document/content/features/sharding/use-norms/sql.cn.md b/docs/document/content/features/sharding/use-norms/sql.cn.md
index 7d1d4d8..4cfa3f0 100644
--- a/docs/document/content/features/sharding/use-norms/sql.cn.md
+++ b/docs/document/content/features/sharding/use-norms/sql.cn.md
@@ -55,20 +55,23 @@ tbl_name [AS] alias] [index_hint_list]
 不支持 HAVING、UNION (ALL)
 
 部分支持子查询
-* 子查询中必须包含分片键,且分片键必须和父查询中的分片键一致
+* 子查询中使用WHERE条件时,必须包含分片键,当外层查询中也包含分片键时,子查询和外层查询中的分片键必须保持一致
 
 除了分页子查询的支持之外(详情请参考[分页](/cn/features/sharding/use-norms/pagination)),也支持同等模式的子查询。无论嵌套多少层,ShardingSphere都可以解析至第一个包含数据表的子查询,一旦在下层嵌套中再次找到包含数据表的子查询将直接抛出解析异常。
 
 例如,以下子查询可以支持:
 
 ```sql
-SELECT COUNT(*) FROM (SELECT * FROM t_order o where id>10) where id>10;
+SELECT COUNT(*) FROM (SELECT * FROM t_order) o;
+SELECT COUNT(*) FROM (SELECT * FROM t_order WHERE order_id = 1) o;
+SELECT COUNT(*) FROM (SELECT * FROM t_order WHERE order_id = 1) o WHERE o.order_id = 1;
 ```
 
 以下子查询不支持:
 
 ```sql
-SELECT COUNT(*) FROM (SELECT * FROM t_order o)
+SELECT COUNT(*) FROM (SELECT * FROM t_order WHERE product_id = 1) o;
+SELECT COUNT(*) FROM (SELECT * FROM t_order WHERE order_id = 1) o WHERE o.order_id = 2;
 ```
 
 简单来说,通过子查询进行非功能需求,在大部分情况下是可以支持的。比如分页、统计总数等;而通过子查询实现业务查询当前并不能支持。
diff --git a/docs/document/content/features/sharding/use-norms/sql.en.md b/docs/document/content/features/sharding/use-norms/sql.en.md
index fc7eb13..4d9a9bf 100644
--- a/docs/document/content/features/sharding/use-norms/sql.en.md
+++ b/docs/document/content/features/sharding/use-norms/sql.en.md
@@ -55,20 +55,23 @@ Partially support CASE WHEN
 
 Do not support HAVING and UNION (ALL) 
 Partly available sub-query
-* If there is a subquery, it needs sharding key condition and be consistent with the parent query.
+* If subquery contains `WHERE` condition, the sharding key must be included. If the outer query also contains the sharding key, the sharding key in subquery and outer query must be consistent.
 
 Support not only pagination sub-query (see [pagination](https://shardingsphere.apache.org/document/current/cn/features/sharding/usage-standard/pagination) for more details), but also sub-query with the same mode. No matter how many layers are nested, ShardingSphere can parse to the first sub-query that contains data table. Once it finds another sub-query of this kind in the sub-level nested, it will directly throw a parsing exception.
 
 For example, the following sub-query is available:
 
 ```sql
-SELECT COUNT(*) FROM (SELECT * FROM t_order o where id>10) where id>10;
+SELECT COUNT(*) FROM (SELECT * FROM t_order) o;
+SELECT COUNT(*) FROM (SELECT * FROM t_order WHERE order_id = 1) o;
+SELECT COUNT(*) FROM (SELECT * FROM t_order WHERE order_id = 1) o WHERE o.order_id = 1;
 ```
 
 The following sub-query is unavailable:
 
 ```sql
-SELECT COUNT(*) FROM (SELECT * FROM t_order o)
+SELECT COUNT(*) FROM (SELECT * FROM t_order WHERE product_id = 1) o;
+SELECT COUNT(*) FROM (SELECT * FROM t_order WHERE order_id = 1) o WHERE o.order_id = 2;
 ```
 
 To be simple, through sub-query, non-functional requirements are available in most cases, such as pagination, sum count and so on; but functional requirements are unavailable for now.