预处理
最近更新时间: 2024-06-12 15:06:00
TDSQL 支持预处理协议,使用方式与单机 MySQL 相同,例如:
PREPARE Syntax
EXECUTE Syntax
二进制协议的支持:
COM_STMT_PREPARE
COM_STMT_EXECUTE
注意:
目前TDSQL只对Prepare/Execute命令做语法兼容,从性能角度的话,在分布式下建议用户尽量不要使用该种方式,直接使用文本协议。
示例:
MySQL [test]> DROP TABLE IF EXISTS test1; Query OK, 0 rows affected (0.08 sec) MySQL [test]> create table test1(a int not null primary key,b int) shardkey=a; Query OK, 0 rows affected (1.71 sec) MySQL [test]> insert into test1(a,b) values(5,6),(3,4),(1,2); Query OK, 3 rows affected (0.06 sec) Records: 3 Duplicates: 0 Warnings: 0 MySQL [test]> select a,b from test1; +---+------+ | a | b | +---+------+ | 1 | 2 | | 3 | 4 | | 5 | 6 | +---+------+ 3 rows in set (0.02 sec) mysql> prepare ff from "select a,b from test1 where a=?"; Query OK, 0 rows affected (0.00 sec) Statement prepared mysql> set @aa=3; Query OK, 0 rows affected (0.00 sec) mysql> execute ff using @aa; +---+------+ | a | b | +---+------+ | 3 | 4 | +---+------+ 1 row in set (0.06 sec)