DRDS SQL支持范围__产品简介_分布式关系型数据库 DRDS-阿里云
DRDS支持绝大部分MySQL语法和协议,包括类似SHOW DATABASES, SHOW TABLES, 以及各种DML语句包括SELECT,UPDATE,INSERT,REPLACE, DELETE,UNION等,以及有限的DRDS自定义控制命令. 总体来说,DRDS在常规的DML SQL使用几乎没有限制,但从性能考虑,我们会有一些针对分布式系统的特殊优化方式,如小表复制,如分布式索引,请参阅我们的最佳使用场景.
SQL大类的限制与约束:
- 暂不支持用户自定义数据类型、自定义函数
- 暂不支持视图、存储过程、触发器、游标
- 暂不支持类似 BEGIN…END,LOOP…END LOOP,REPEAT…UNTIL…END REPEAT,WHILE…DO…END WHILE 等的复合语句
- 暂不支类似 IF,WHILE 等流程控制类语句
- 全面的DML支持,有限的DDL支持,有限的控制指令支持
下面罗列了目前DRDS支持的SQL语法列表,以mysql的语法列表为蓝本,下面列出的语法代表为已支持,如有特殊说明,代表部分不支持的CASE.
数据库登陆协议
经过测试的客户端: Workbench , Navicat, SQLyog等
数据库DDL语法
- CREATE TABLE Syntax
- create table tbl_name like old_tbl_name / create table tbl_name select_statement 暂不支持拆分表
- CREATE INDEX Syntax
- DROP TABLE Syntax
- DROP INDEX Syntax
- ALTER TABLE Syntax
- TRUNCATE TABLE Syntax
数据库DML语法
- INSERT Syntax
- INSERT DELAYED Syntax 暂不支持
- REPLACE Syntax
- UPDATE Syntax
- DELETE Syntax
- Subquery Syntax
- SELECT Syntax
- SELECT INTO OUTFILE/INTO DUMPFILE/INTO var_name 暂不支持
- JOIN/UNION Syntax 均支持
- 跨分库函数支持见下表.
不支持的语法:
- 受限于分布式事务
- 跨分片操作, UPDATE/DELETE [ORDER BY] LIMIT
- 跨分片操作, UPDATE A,B set A.s = B.s+1 WHERE A.ID = B.NAME , 非拆分字段之间的跨库JOIN
- 拆分键变更, UPDATE A SET A.ID = 1 WHERE XXX, ID为拆分字段
- 跨分片操作, INSERT A SELECT B WHERE B.ID > XX , 跨库导入导出数据
- 跨库事物, 比如两次UPDATE不在一个分片上
- 子查询限制
- 暂不支持非where条件的correlate subquery
- 暂不支持sql中带聚合条件和correlate subquery
例1: 父查询的select列上存在关联子查询,引用了父查询的a.user_idselect a.user_id , (select sum(score) from b where b.user_id = a.user_id) from a order by a.user_id desc limit 10例2: 父查询存在count聚合函数,where条件存在exists的关联子查询引用了a.user_idselect count(*) from a where exists (select * from b where b.user_id = a.user_id and b.score < 60)
数据库事务语法
- START TRANSACTION, COMMIT, and ROLLBACK Syntax
- 暂不支持transaction_characteristic定义
- 暂不支持savepoint嵌套事务的相关语法
- 暂不支持XA事务的相关语法
- 兼容set autocommit=0/false/off 等多种写法.
- SET TRANSACTION Syntax
- 暂不支持对global的事务隔离级别进行调整
数据库prepare语法
限制: prepare协议不可与SQL多语句一起混用
数据库管理语法
- SET Syntax
- 目前不支持global的变更,比如
SET GLOBAL var=xx或者set @@global.var=xx - 目前不支持SQL中对于变量的引用和操作,比如
set @c=1, @d=@c+1; select @c, @d
- 目前不支持global的变更,比如
- Show Syntax
- SHOW COLUMNS Syntax
- SHOW CREATE TABLE Syntax
- SHOW INDEX
- SHOW TABLES Syntax
- SHOW TABLE STATUS Syntax
- SHOW TABLE STATUS Syntax
- SHOW TABLES Syntax
- SHOW VARIABLES Syntax
- SHOW WARNINGS Syntax 不支持limit/count的组合
- SHOW ERRORS Syntax 不支持limit/count的组合
- 其余的show指令会默认下发到DB处理,结果数据没有进行分库数据合并
- KILL Syntax
- 目前只支持KILL QUERY processlist_id
数据库工具命令
DRDS自定义指令
- SHOW SEQUENCES / CREATE SEQUENCE / ALTER SEQUENCE / DROP SEQUENCE 【全局sequence管理】
- SHOW PARTITIONS FROM TABLE 【查询表的拆分字段】
- SHOW TOPOLOGY FROM TABLE 【查询表的物理拓扑】
- SHOW BRAODCASTS 【查询所有广播表】
- SHOW RULE [FROM TABLE] 【查询表拆分定义】
- SHOW DATASOURCES 【查询后端DB链接池定义】
- SHOW DBLOCK / RELEASE DBLOCK 【分布式LOCK定义】
- SHOW NODE 【查询读写库流量】
- SHOW SLOW 【查询慢SQL列表】
- SHOW PHYSICAL_SLOW 【查询物理DB执行慢SQL列表】
- TRACE SQL_STATEMENT / SHOW TRACE 【跟踪SQL执行,profile整个执行过程】
- EXPLAIN [DETAIL/EXECUTE] SQL_STATEMENT 【分析DRDS执行计划和物理DB上的执行计划】
- RELOAD USERS 【同步DRDS控制台用户信息到DRDS SERVER】
- RELOAD SCHEMA 【清理DRDS对应DB库数据缓存,比如SQL解析/语法树/表结构缓存】
- RELOAD DATASOURCES 【重建后端与所有DB的链接池】
数据库系统函数
整体函数分为解析和执行部分
- 函数解析: 主要指解析纯SQL中的函数定义,如果函数可以被正常解析,意味着如果用户SQL中带着了拆分字段,函数都可以下发到MySQL上进行执行
- 函数执行: 主要指用户SQL不能完全下推到MySQL得到结果的情况,需要DRDS层进行二次计算时的函数支持列表.
一个例子理解:
1. select count(*) from users where user_id = 1; # user_id为切分条件, count(*)函数主要就是一个SQL解析然后发给MySQL执行,这一类的行为就取决于DRDS的函数解析的支持能力.2. select count(*) from users; # 用户SQL未带切分条件, DRDS会对每个分片返回的count结果,在DRDS层面重新计算出一个全局的count(*)结果返回给用户,这一类的行为就取决于DRDS的函数执行的支持能力.
支持范围:
- 函数解析支持范围: MySQL全函数解析
- 函数执行支持范围: 实现绝大部分的常用函数,总计约280+函数,覆盖了MySQL所有函数的近70%+
操作符函数
| function | description |
|---|---|
| AND, && | Logical AND |
| = | Assign a value (as part of a SET statement, or as part of the SET clause in an UPDATE statement) |
| BETWEEN … AND … | Check whether a value is within a range of values |
| BINARY | Cast a string to a binary string |
| & | Bitwise AND |
| ~ | Bitwise inversion |
| ^ | Bitwise XOR |
| DIV | Integer division |
| / | Division operator |
| <=> | NULL-safe equal to operator |
| = | Equal operator |
| >= | Greater than or equal operator |
| > | Greater than operator |
| IS NOT NULL | NOT NULL value test |
| IS NOT | Test a value against a boolean |
| IS NULL | NULL value test |
| IS | Test a value against a boolean |
<< |
Left shift |
<= |
Less than or equal operator |
< |
Less than operator |
| LIKE | Simple pattern matching |
| - | Minus operator |
| %, MOD | Modulo operator |
| NOT BETWEEN … AND … | Check whether a value is not within a range of values |
| !=, <> | Not equal operator |
| NOT LIKE | Negation of simple pattern matching |
| NOT REGEXP | Negation of REGEXP |
| NOT, ! | Negates value |
| OR | Logical OR |
| + | Addition operator |
| REGEXP | Pattern matching using regular expressions |
| >> | Right shift |
| RLIKE | Synonym for REGEXP |
| * | Multiplication operator |
| - | Change the sign of the argument |
| XOR | Logical XOR |
| Coalesce | Return the first non-NULL argument |
| GREATEST | Return the largest argument |
| LEAST | Return the smallest argument |
| STRCMP | Compare two strings |
流程控制函数
| function | description |
|---|---|
| CASE | Case operator |
| IF() | If/else construct |
| IFNULL() | Null if/else construct |
| NULLIF() | Return NULL if expr1 = expr2 |
字符串函数
| function | description |
|---|---|
| ASCII() | Return numeric value of left-most character |
| BIN() | Return a string containing binary representation of a number |
| BIT_LENGTH() | Return length of argument in bits |
| CHAR_LENGTH() | Return number of characters in argument |
| CHAR() | Return the character for each integer passed |
| CHARACTER_LENGTH() | Synonym for CHAR_LENGTH() |
| CONCAT_WS() | Return concatenate with separator |
| CONCAT() | Return concatenated string |
| ELT() | Return string at index number |
| EXPORT_SET() | Return a string such that for every bit set in the value bits, you get an on string and for every unset bit, you get an off string |
| FIELD() | Return the index (position) of the first argument in the subsequent arguments |
| FIND_IN_SET() | Return the index position of the first argument within the second argument |
| FORMAT() | Return a number formatted to specified number of decimal places |
| HEX() | Return a hexadecimal representation of a decimal or string value |
| INSERT() | Insert a substring at the specified position up to the specified number of characters |
| INSTR() | Return the index of the first occurrence of substring |
| LCASE() | Synonym for LOWER() |
| LEFT() | Return the leftmost number of characters as specified |
| LENGTH() | Return the length of a string in bytes |
| LIKE | Simple pattern matching |
| LOCATE() | Return the position of the first occurrence of substring |
| LOWER() | Return the argument in lowercase |
| LPAD() | Return the string argument, left-padded with the specified string |
| LTRIM() | Remove leading spaces |
| MAKE_SET() | Return a set of comma-separated strings that have the corresponding bit in bits set |
| MID() | Return a substring starting from the specified position |
| NOT LIKE | Negation of simple pattern matching |
| NOT REGEXP | Negation of REGEXP |
| OCT() | Return a string containing octal representation of a number |
| OCTET_LENGTH() | Synonym for LENGTH() |
| ORD() | Return character code for leftmost character of the argument |
| POSITION() | Synonym for LOCATE() |
| QUOTE() | Escape the argument for use in an SQL statement |
| REPEAT() | Repeat a string the specified number of times |
| REPLACE() | Replace occurrences of a specified string |
| REVERSE() | Reverse the characters in a string |
| RIGHT() | Return the specified rightmost number of characters |
| RPAD() | Append string the specified number of times |
| RTRIM() | Remove trailing spaces |
| SPACE() | Return a string of the specified number of spaces |
| STRCMP() | Compare two strings |
| SUBSTR() | Return the substring as specified |
| SUBSTRING_INDEX() | Return a substring from a string before the specified number of occurrences of the delimiter |
| SUBSTRING() | Return the substring as specified |
| TRIM() | Remove leading and trailing spaces |
| UCASE() | Synonym for UPPER() |
| UNHEX() | Return a string containing hex representation of a number |
| UPPER() | Convert to uppercase |
数学函数
| function | description |
|---|---|
| ABS() | Return the absolute value |
| ACOS() | Return the arc cosine |
| ASIN() | Return the arc sine |
| ATAN2(),ATAN() | Return the arc tangent of the two arguments |
| ATAN() | Return the arc tangent |
| CEIL() | Return the smallest integer value not less than the argument |
| CEILING() | Return the smallest integer value not less than the argument |
| CONV() | Convert numbers between different number bases |
| COS() | Return the cosine |
| COT() | Return the cotangent |
| CRC32() | Compute a cyclic redundancy check value |
| DEGREES() | Convert radians to degrees |
| DIV | Integer division |
| EXP() | Raise to the power of |
| FLOOR() | Return the largest integer value not greater than the argument |
| LN() | Return the natural logarithm of the argument |
| LOG10() | Return the base-10 logarithm of the argument |
| LOG2() | Return the base-2 logarithm of the argument |
| LOG() | Return the natural logarithm of the first argument |
| MOD() | Return the remainder |
| %, MOD | Modulo operator |
| PI() | Return the value of pi |
| POW() | Return the argument raised to the specified power |
| POWER() | Return the argument raised to the specified power |
| RADIANS() | Return argument converted to radians |
| RAND() | Return a random floating-point value |
| ROUND() | Round the argument |
| SIGN() | Return the sign of the argument |
| SIN() | Return the sine of the argument |
| SQRT() | Return the square root of the argument |
| TAN() | Return the tangent of the argument |
| TRUNCATE() | Truncate to specified number of decimal places |
时间函数
| function | description |
|---|---|
| ADDDATE() | Add time values (intervals) to a date value |
| ADDTIME() | Add time |
| CURDATE() | Return the current date |
| CURRENT_DATE() | CURRENT_DATE Synonyms for CURDATE() |
| CURRENT_TIME() | CURRENT_TIME Synonyms for CURTIME() |
| CURRENT_TIMESTAMP() | CURRENT_TIMESTAMP Synonyms for NOW() |
| CURTIME() | Return the current time |
| DATE_ADD() | Add time values (intervals) to a date value |
| DATE_FORMAT() | Format date as specified |
| DATE_SUB() | Subtract a time value (interval) from a date |
| DATE() | Extract the date part of a date or datetime expression |
| DATEDIFF() | Subtract two dates |
| DAY() | Synonym for DAYOFMONTH() |
| DAYNAME() | Return the name of the weekday |
| DAYOFMONTH() | Return the day of the month (0-31) |
| DAYOFWEEK() | Return the weekday index of the argument |
| DAYOFYEAR() | Return the day of the year (1-366) |
| EXTRACT() | Extract part of a date |
| FROM_DAYS() | Convert a day number to a date |
| FROM_UNIXTIME() | Format UNIX timestamp as a date |
| GET_FORMAT() | Return a date format string |
| HOUR() | Extract the hour |
| LAST_DAY() | Return the last day of the month for the argument |
| LOCALTIME() | LOCALTIME Synonym for NOW() |
| LOCALTIMESTAMP, LOCALTIMESTAMP() | Synonym for NOW() |
| MAKEDATE() | Create a date from the year and day of year |
| MAKETIME() | Create time from hour, minute, second |
| MICROSECOND() | Return the microseconds from argument |
| MINUTE() | Return the minute from the argument |
| MONTH() | Return the month from the date passed |
| MONTHNAME() | Return the name of the month |
| NOW() | Return the current date and time |
| PERIOD_ADD() | Add a period to a year-month |
| PERIOD_DIFF() | Return the number of months between periods |
| QUARTER() | Return the quarter from a date argument |
| SEC_TO_TIME() | Converts seconds to ‘HH:MM:SS’ format |
| SECOND() | Return the second (0-59) |
| STR_TO_DATE() | Convert a string to a date |
| SUBDATE() | Synonym for DATE_SUB() when invoked with three arguments |
| SUBTIME() | Subtract times |
| SYSDATE() | Return the time at which the function executes |
| TIME_FORMAT() | Format as time |
| TIME_TO_SEC() | Return the argument converted to seconds |
| TIME() | Extract the time portion of the expression passed |
| TIMEDIFF() | Subtract time |
| TIMESTAMP() | With a single argument, this function returns the date or datetime expression; with two arguments, the sum of the arguments |
| TIMESTAMPADD() | Add an interval to a datetime expression |
| TIMESTAMPDIFF() | Subtract an interval from a datetime expression |
| UNIX_TIMESTAMP() | Return a UNIX timestamp |
| UTC_DATE() | Return the current UTC date |
| UTC_TIME() | Return the current UTC time |
| UTC_TIMESTAMP() | Return the current UTC date and time |
| WEEKDAY() | Return the weekday index |
| WEEKOFYEAR() | Return the calendar week of the date (1-53) |
| YEAR() | Return the year |
类型转换函数
| function | description |
|---|---|
| BINARY | Cast a string to a binary string |
| CAST() | Cast a value as a certain type |
| CONVERT() | Cast a value as a certain type |
最后更新:2016-11-23 17:31:06
上一篇:
DRDS简单原理__产品简介_分布式关系型数据库 DRDS-阿里云
下一篇:
专享/共享实例对比__产品简介_分布式关系型数据库 DRDS-阿里云
批量操作表__管理表_数据库开发_用户指南(RDBMS)_数据管理-阿里云
漏洞等级说明__漏洞说明_先知计划-阿里云
EDAS 简介__产品简介_企业级分布式应用服务 EDAS-阿里云
查询可用镜像__镜像相关接口_API 参考_云服务器 ECS-阿里云
附录:SQL Server 2008 R2/2012 功能差异__快速入门(SQL Server)_云数据库 RDS 版-阿里云
使用指南__订阅日志服务数据_链接计算_表格存储-阿里云
使用阿里云部署服务__使用手册_Eclipse 插件-阿里云
事件通知__开发人员指南_消息服务-阿里云
设置静态网站托管__管理存储空间_控制台用户指南_对象存储 OSS-阿里云
云上系统专家保障(精简版)__工作说明书_尊享服务_支持计划-阿里云
相关内容
常见错误说明__附录_大数据计算服务-阿里云
发送短信接口__API使用手册_短信服务-阿里云
接口文档__Android_安全组件教程_移动安全-阿里云
运营商错误码(联通)__常见问题_短信服务-阿里云
设置短信模板__使用手册_短信服务-阿里云
OSS 权限问题及排查__常见错误及排除_最佳实践_对象存储 OSS-阿里云
消息通知__操作指南_批量计算-阿里云
设备端快速接入(MQTT)__快速开始_阿里云物联网套件-阿里云
查询API调用流量数据__API管理相关接口_API_API 网关-阿里云
使用STS访问__JavaScript-SDK_SDK 参考_对象存储 OSS-阿里云