閱讀347 返回首頁    go 小米 go 小米 note


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語法

數據庫DML語法

不支持的語法:

  • 受限於分布式事務
    • 跨分片操作, 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. 例1: 父查詢的select列上存在關聯子查詢,引用了父查詢的a.user_id
  2. select 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
  3. 例2: 父查詢存在count聚合函數,where條件存在exists的關聯子查詢引用了a.user_id
  4. select count(*) from a where exists (select * from b where b.user_id = a.user_id and b.score < 60)

數據庫事務語法

數據庫prepare語法

限製: prepare協議不可與SQL多語句一起混用

數據庫管理語法

數據庫工具命令

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. 1. select count(*) from users where user_id = 1; # user_id為切分條件, count(*)函數主要就是一個SQL解析然後發給MySQL執行,這一類的行為就取決於DRDS的函數解析的支持能力.
  2. 2. select count(*) from users; # 用戶SQL未帶切分條件, DRDS會對每個分片返回的count結果,在DRDS層麵重新計算出一個全局的count(*)結果返回給用戶,這一類的行為就取決於DRDS的函數執行的支持能力.

支持範圍:

操作符函數

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

  上一篇:go DRDS簡單原理__產品簡介_分布式關係型數據庫 DRDS-阿裏雲
  下一篇:go 專享/共享實例對比__產品簡介_分布式關係型數據庫 DRDS-阿裏雲