edit-icon download-icon

SQL compatibility

Last Updated: Mar 30, 2018

DRDS is highly compatible with the MySQL protocol and syntaxes. However, due to the great architecture difference between distributed databases and single-host databases, SQL use has the following constraints:

DRDS SQL constraints

General SQL constraints

  • Currently does not support custom data types or functions.
  • Currently does not support views, stored procedures, triggers, and cursors.
  • Currently does not support compound statements, for example, BEG…END, LOOP…END LOOP, REPEAT…UNTIL…END REPEAT, and WHILE…DO…END WHILE.
  • Currently does not support IF, WHILE, and other process control statements.

Syntax constraints

DDL

  • CREATE TABLE tbl_name LIKE old_tbl_name does not support table splitting.
  • CREATE TABLE tbl_name SELECT does not support table splitting.

DML

  • Currently does not support SELECT INTO OUTFILE/INTO DUMPFILE/INTO var_name.
  • Currently does not support INSERT DELAYED.
  • Currently does not support correlated subqueries that are not in a WHERE clause.
  • Currently does not support correlated subqueries with aggregate functions.
  • Currently does not allow users to reference or operate variables, for example, SET @c=1, @d=@c+1; SELECT @c, @d

Database management

  • SHOW WARNINGS does not support the LIMIT/COUNT combination.
  • SHOW ERRORS does not support the LIMIT/COUNT combination.

DRDS SQL compatibility

Protocol compatibility

DRDS supports mainstream MySQL clients, including MySQL Workbench, Navicat for MySQL, and SQLyog.

DDL compatibility

  • CREATE TABLE
  • CREATE INDEX
  • DROP TABLE
  • DROP INDEX
  • ALTER TABLE
  • TRUNCATE TABLE

DML compatibility

  • INSERT
  • REPLACE
  • UPDATE
  • DELETE
  • Subquery
  • Scalar Subquery
  • Comparisons Subquery
  • Subqueries with ANY, IN, or SOME
  • Subqueries with ALL
  • Row Subqueries
  • Subqueries with EXISTS or NOT EXISTS
  • Subqueries in the FROM clause
  • SELECT

Prepare syntax compatibility

  • PREPARE
  • EXECUTE
  • DEALLOCATE PREPARE

Database management syntax compatibility

  • SET
  • SHOW
  • SHOW COLUMNS
  • SHOW CREATE TABLE
  • SHOW INDEX
  • SHOW TABLES
  • SHOW TABLE STATUS
  • SHOW TABLE STATUS
  • SHOW TABLES
  • SHOW VARIABLES
  • SHOW WARNINGS
  • SHOW ERRORS
  • Other SHOW commands are delivered to DB for processing by default, and results returned by different databases are not integrated.
  • KILL ‘PROCESS_ID’ (DRDS does not support KILL QUERY, but KILL ‘PROCESS_ID’ only.)

Database tool commands

  • DESCRIBE
  • EXPLAIN
  • USE

DRDS custom commands

  • SHOW SEQUENCES / CREATE SEQUENCE / ALTER SEQUENCE / DROP SEQUENCE [manage sequences]
  • SHOW PARTITIONS FROM TABLE [query table partitions]
  • SHOW TOPOLOGY FROM TABLE [query the physical topology of the table]
  • SHOW BROADCASTS [query all broadcast tables]
  • SHOW RULE [FROM TABLE] [query the table partition definition]
  • SHOW DATASOURCES [query the definition of the backend DB connection pool]
  • SHOW DBLOCK / RELEASE DBLOCK [Query the definition of the distributed LOCK]
  • SHOW NODE [query read/write traffic]
  • SHOW SLOW [query the slow SQL list]
  • SHOW PHYSICAL_SLOW [query the list of slow SQL list of the physical database]
  • TRACE SQL_STATEMENT / SHOW TRACE [trace the whole SQL execution process]
  • EXPLAIN [DETAIL/EXECUTE] SQL_STATEMENT [analyze execution plans of DRDS and physical databases]
  • RELOAD USERS [synchronize DRDS console user information to the DRDS server]
  • RELOAD SCHEMA [clear the DRDS database cache, for example, SQL parsing, syntax tree, and table structure cache]
  • RELOAD DATASOURCES [rebuild the pool of connections between the backend and all databases]

Database functions

  • SQL statements with a sharding key are supported by all MySQL functions.
  • SQL statements without the sharding key are supported only by certain functions.

Operator functions

Function expression 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 value
BINARY Cast a string to a binary string
& Bitwise AND
~ Bitwise inversion
^ Bitwise XOR
DIV Integer division
/ Division operator
<=> NULL-safe equal to perator
= 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
%, MODModulo 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

Process control functions

Function Description
CASE Case operator
IF() If/else construct
IFNULL() Null if/else construct
NULLIF() Return NULL if expr1 = expr2

Mathematical functions

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
CEILIG() 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 Intger 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

String functions

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

Time functions

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

Type conversion functions

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
Thank you! We've received your feedback.