diff --git a/docs/en/docs/advanced/variables.md b/docs/en/docs/advanced/variables.md index 806068fc3d09a1..b61a175c87bf90 100644 --- a/docs/en/docs/advanced/variables.md +++ b/docs/en/docs/advanced/variables.md @@ -176,6 +176,10 @@ Note that the comment must start with /*+ and can only follow the SELECT. Used for compatibility with MySQL clients. No practical effect. +* `default_order_by_limit` + + Used to control the default number of items returned after OrderBy. The default value is -1, and the maximum number of records after the query is returned by default, and the upper limit is the MAX_VALUE of the long data type. + * `delete_without_partition` When set to true. When using the delete command to delete partition table data, no partition is required. The delete operation will be automatically applied to all partitions. @@ -548,4 +552,4 @@ Translated with www.DeepL.com/Translator (free version) * `validate_password_policy` - Password strength verification policy. Defaults to `NONE` or `0`, i.e. no verification. Can be set to `STRONG` or `2`. When set to `STRONG` or `2`, when setting a password via the `ALTER USER` or `SET PASSWORD` commands, the password must contain any of "uppercase letters", "lowercase letters", "numbers" and "special characters". 3 items, and the length must be greater than or equal to 8. Special characters include: `~!@#$%^&*()_+|<>,.?/:;'[]{}"`. \ No newline at end of file + Password strength verification policy. Defaults to `NONE` or `0`, i.e. no verification. Can be set to `STRONG` or `2`. When set to `STRONG` or `2`, when setting a password via the `ALTER USER` or `SET PASSWORD` commands, the password must contain any of "uppercase letters", "lowercase letters", "numbers" and "special characters". 3 items, and the length must be greater than or equal to 8. Special characters include: `~!@#$%^&*()_+|<>,.?/:;'[]{}"`. diff --git a/docs/zh-CN/docs/advanced/variables.md b/docs/zh-CN/docs/advanced/variables.md index 80e1b6e4fe793a..39cf63610e6d63 100644 --- a/docs/zh-CN/docs/advanced/variables.md +++ b/docs/zh-CN/docs/advanced/variables.md @@ -174,6 +174,10 @@ SELECT /*+ SET_VAR(query_timeout = 1, enable_partition_cache=true) */ sleep(3); 用于兼容 MySQL 客户端。无实际作用。 +- `default_order_by_limit` + + 用于控制 OrderBy 以后返回的默认条数。默认值为 -1,默认返回查询后的最大条数,上限为 long 数据类型的 MAX_VALUE 值。 + - `delete_without_partition` 设置为 true 时。当使用 delete 命令删除分区表数据时,可以不指定分区。delete 操作将会自动应用到所有分区。 diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java b/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java index 24d07d98e39e58..50677acc7a4855 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java +++ b/fe/fe-core/src/main/java/org/apache/doris/planner/SingleNodePlanner.java @@ -236,8 +236,13 @@ private void unmarkCollectionSlots(QueryStmt stmt) { private PlanNode createQueryPlan(QueryStmt stmt, Analyzer analyzer, long defaultOrderByLimit) throws UserException { long newDefaultOrderByLimit = defaultOrderByLimit; + long defaultLimit = analyzer.getContext().getSessionVariable().defaultOrderByLimit; if (newDefaultOrderByLimit == -1) { - newDefaultOrderByLimit = 65535; + if (defaultLimit <= -1) { + newDefaultOrderByLimit = Long.MAX_VALUE; + } else { + newDefaultOrderByLimit = defaultLimit; + } } PlanNode root; if (stmt instanceof SelectStmt) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java index e28e4545123da1..95fb7f8a02429c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java @@ -203,6 +203,8 @@ public class SessionVariable implements Serializable, Writable { static final String SESSION_CONTEXT = "session_context"; + public static final String DEFAULT_ORDER_BY_LIMIT = "default_order_by_limit"; + public static final String ENABLE_SINGLE_REPLICA_INSERT = "enable_single_replica_insert"; public static final String ENABLE_FUNCTION_PUSHDOWN = "enable_function_pushdown"; @@ -244,6 +246,11 @@ public class SessionVariable implements Serializable, Writable { @VariableMgr.VarAttr(name = ENABLE_EXCHANGE_NODE_PARALLEL_MERGE) public boolean enableExchangeNodeParallelMerge = false; + // By default, the number of Limit items after OrderBy is changed from 65535 items + // before v1.2.0 (not included), to return all items by default + @VariableMgr.VarAttr(name = DEFAULT_ORDER_BY_LIMIT) + public long defaultOrderByLimit = -1; + // query timeout in second. @VariableMgr.VarAttr(name = QUERY_TIMEOUT) public int queryTimeoutS = 300;