You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by yi...@apache.org on 2022/05/26 07:06:28 UTC

[incubator-doris] branch master updated: [docs]add sql mode markdown (#9742)

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

yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 8898b11bb0 [docs]add sql mode markdown (#9742)
8898b11bb0 is described below

commit 8898b11bb035474bf8225339aac6edf9e9346fce
Author: wudi <67...@qq.com>
AuthorDate: Thu May 26 15:06:23 2022 +0800

    [docs]add sql mode markdown (#9742)
    
    Co-authored-by: wudi <>
---
 docs/en/advanced/sql-mode.md     | 71 +++++++++++++++++++++++++++++++++++++
 docs/en/advanced/variables.md    |  2 +-
 docs/zh-CN/advanced/sql-mode.md  | 76 ++++++++++++++++++++++++++++++++++++++++
 docs/zh-CN/advanced/variables.md |  2 +-
 4 files changed, 149 insertions(+), 2 deletions(-)

diff --git a/docs/en/advanced/sql-mode.md b/docs/en/advanced/sql-mode.md
new file mode 100644
index 0000000000..b39104cf96
--- /dev/null
+++ b/docs/en/advanced/sql-mode.md
@@ -0,0 +1,71 @@
+---
+{
+"title": "SQL MODE",
+"language": "en"
+}
+---
+
+<!-- 
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+# SQL MODE
+
+The sql mode newly supported by Doris refers to the sql mode management mechanism of Mysql. Each client can set its own sql mode, and database administrators with Admin privileges can set the global sql mode.
+## sql mode introduce
+
+sql mode enables users to switch between different styles of sql syntax and data validation strictness, making Doris more compatible with other databases. For example, in some databases, the '||' symbol is a string concatenator, but in Doris it is equivalent to 'or', then users only need to use sql mode to switch to the style they want. Each client can set the sql mode, which is valid in the current session. Only users with Admin privileges can set the global sql mode.
+## principle
+
+The sql mode is stored in SessionVariables with a 64-bit Long type. Each bit of this address represents the enable/disable (1 means open, 0 means disable) state of a mode, as long as you know where each mode is. Bit, we can easily and quickly perform checksum operations on sql mode through bit operations.
+
+Every time you query the sql mode, the Long type will be parsed and turned into a user-readable string. Similarly, the sql mode string sent by the user to the server will be parsed into a string that can be stored in SessionVariables. Long type.
+
+The global sql mode that has been set will be persisted, so the operation on the global sql mode always only needs to be performed once, and the last global sql mode can be restored even after the program is restarted.
+
+## Operation method
+
+1. Set sql mode
+```
+set global sql_mode = "DEFAULT"
+set session sql_mode = "DEFAULT"
+```
+>Currently Doris's default sql mode is DEFAULT (but this will be changed in subsequent revisions soon).
+>Setting global sql mode requires Admin privileges and will affect all clients connecting thereafter.
+>Setting session sql mode will only affect the current dialog client, the default is session mode.
+
+2. Query sql mode
+
+```
+select @@global.sql_mode
+select @@session.sql_mode
+```
+>In addition to this way, you can also check the current sql mode by returning all session variables in the following way
+```
+show global variables
+show session variables
+```
+
+## mode is supported
+
+1. `PIPES_AS_CONCAT`
+
+In this mode, the '||' symbol is a string concatenation symbol (same as the CONCAT() function), not a synonym for the 'OR' symbol. (e.g., `'a'||'b' = 'ab'`, `1||0 = '10'`)
+## composite mode
+
+(subsequent additions)
diff --git a/docs/en/advanced/variables.md b/docs/en/advanced/variables.md
index 69be05af92..1a0c6c1954 100644
--- a/docs/en/advanced/variables.md
+++ b/docs/en/advanced/variables.md
@@ -350,7 +350,7 @@ Translated with www.DeepL.com/Translator (free version)
 
 * `sql_mode`
 
-    Used to specify SQL mode to accommodate certain SQL dialects. For the SQL mode, see [here](https://doris.apache.org/zh-CN/administrator-guide/sql-mode.md).
+    Used to specify SQL mode to accommodate certain SQL dialects. For the SQL mode, see [here](./sql-mode.md).
     
 * `sql_safe_updates`
 
diff --git a/docs/zh-CN/advanced/sql-mode.md b/docs/zh-CN/advanced/sql-mode.md
new file mode 100644
index 0000000000..61cefd0ddc
--- /dev/null
+++ b/docs/zh-CN/advanced/sql-mode.md
@@ -0,0 +1,76 @@
+---
+{
+"title": "SQL MODE",
+"language": "zh-CN"
+}
+---
+
+<!-- 
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+# SQL MODE
+
+Doris新支持的sql mode参照了 Mysql 的sql mode管理机制,每个客户端都能设置自己的sql mode,拥有Admin权限的数据库管理员可以设置全局sql mode。
+
+## sql mode 介绍
+
+sql mode使用户能在不同风格的sql语法和数据校验严格度间做切换,使Doris对其他数据库有更好的兼容性。例如在一些数据库里,'||'符号是一个字符串连接符,但在Doris里却是与'or'等价的,这时用户只需要使用sql mode切换到自己想要的风格。每个客户端都能设置sql mode,并在当前对话中有效,只有拥有Admin权限的用户可以设置全局sql mode。
+
+## 原理
+
+sql mode用一个64位的Long型存储在SessionVariables中,这个地址的每一位都代表一个mode的开启/禁用(1表示开启,0表示禁用)状态,只要知道每一种mode具体是在哪一位,我们就可以通过位运算方便快速的对sql mode进行校验和操作。
+
+每一次对sql mode的查询,都会对此Long型进行一次解析,变成用户可读的字符串形式,同理,用户发送给服务器的sql mode字符串,会被解析成能够存储在SessionVariables中的Long型。
+
+已被设置好的全局sql mode会被持久化,因此对全局sql mode的操作总是只需一次,即使程序重启后仍可以恢复上一次的全局sql mode。
+
+## 操作方式
+
+1、设置sql mode
+
+```
+set global sql_mode = "DEFAULT"
+set session sql_mode = "DEFAULT"
+```
+>目前Doris的默认sql mode是DEFAULT(但马上会在后续修改中会改变)。
+>设置global sql mode需要Admin权限,并会影响所有在此后连接的客户端。
+>设置session sql mode只会影响当前对话客户端,默认为session方式。
+
+2、查询sql mode
+
+```
+select @@global.sql_mode
+select @@session.sql_mode
+```
+>除了这种方式,你还可以通过下面方式返回所有session variables来查看当前sql mode
+
+```
+show global variables
+show session variables
+```
+
+## 已支持mode
+
+1. `PIPES_AS_CONCAT`
+
+   在此模式下,'||'符号是一种字符串连接符号(同CONCAT()函数),而不是'OR'符号的同义词。(e.g., `'a'||'b' = 'ab'`, `1||0 = '10'`)
+
+## 复合mode
+
+(后续补充)
diff --git a/docs/zh-CN/advanced/variables.md b/docs/zh-CN/advanced/variables.md
index 467c38239f..3b4395d252 100644
--- a/docs/zh-CN/advanced/variables.md
+++ b/docs/zh-CN/advanced/variables.md
@@ -345,7 +345,7 @@ SELECT /*+ SET_VAR(query_timeout = 1, enable_partition_cache=true) */ sleep(3);
 
 - `sql_mode`
 
-  用于指定 SQL 模式,以适应某些 SQL 方言。
+  用于指定 SQL 模式,以适应某些 SQL 方言,关于 SQL 模式,可参阅[这里](./sql-mode.md)。
 
 - `sql_safe_updates`
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org