使用SpringBoot + Mybatis方式进行TiDB查询sql,发现无法使用Mybatis的statement-timeout设置来取消超时查询。
进行Statement Timeout设置后,当语句查询超时时,不会取消查询而是等到语句执行完成后,才抛出一个超时异常。
比如设置statement timeout为3秒,然后执行select sleep(10);
使用mysql时,会在3秒时抛出超时异常;
使用TiDB时,会在10秒语句执行完才抛出超时异常;
com.mysql.cj.jdbc.exceptions.MySQLTimeoutException: Statement cancelled due to timeout or client request
2020-07-21 11:32:43.128 ERROR 10840 — [p-nio-80-exec-1] c.c.s.d.s.m.controller.TestController : org.springframework.dao.QueryTimeoutException
ps: 使用jdbc的socket timeout设置似乎可以实现当执行查询超时时,立即断开并抛出异常。但无法做到语句级超时设置。