optimize the display of specific statement results inner 1042 (#2718)

* optimize the display of specific statement results inner 1042

* Reuse method
This commit is contained in:
ylinzhu
2021-06-10 14:25:58 +08:00
committed by guoaomen
parent 33934bf956
commit 5c78436b3a
3 changed files with 26 additions and 3 deletions
@@ -9,6 +9,7 @@ import com.actiontech.dble.route.parser.util.ParseUtil;
import com.actiontech.dble.server.parser.ServerParse;
import com.actiontech.dble.server.parser.ServerParseSelect;
import com.actiontech.dble.server.response.*;
import com.actiontech.dble.services.manager.response.SelectMaxAllowedPacket;
import com.actiontech.dble.services.mysqlsharding.ShardingService;
@@ -107,6 +108,9 @@ public final class SelectHandler {
case ServerParseSelect.ROW_COUNT:
SelectRowCount.response(service);
break;
case ServerParseSelect.MAX_ALLOWED_PACKET:
SelectMaxAllowedPacket.execute(service);
break;
default:
service.execute(stmt, ServerParse.SELECT);
}
@@ -32,6 +32,7 @@ public final class ServerParseSelect {
public static final int SESSION_TRANSACTION_ISOLATION = 13;
public static final int SESSION_TRANSACTION_READ_ONLY = 14;
public static final int ROW_COUNT = 15;
public static final int MAX_ALLOWED_PACKET = 16;
private static final char[] TRACE_STR = "TRACE".toCharArray();
private static final char[] VERSION_COMMENT_STR = "VERSION_COMMENT".toCharArray();
@@ -492,6 +493,9 @@ public final class ServerParseSelect {
case 't':
case 'T':
return traceCheck(stmt, offset);
case 'm':
case 'M':
return maxCheck(stmt, offset);
default:
return OTHER;
}
@@ -499,6 +503,17 @@ public final class ServerParseSelect {
return OTHER;
}
// select @@max_allowed_packet;
private static int maxCheck(String stmt, int offset) {
if (stmt.length() > offset + 17) {
String suffix = stmt.substring(offset).toUpperCase();
if (suffix.startsWith("MAX_ALLOWED_PACKET") && (stmt.length() == offset + 18 || ParseUtil.isEOF(stmt, offset + 18))) {
return MAX_ALLOWED_PACKET;
}
}
return OTHER;
}
/**
* SELECT DATABASE()
*/
@@ -7,12 +7,16 @@ package com.actiontech.dble.services.manager.response;
import com.actiontech.dble.backend.mysql.PacketUtil;
import com.actiontech.dble.config.Fields;
import com.actiontech.dble.config.model.SystemConfig;
import com.actiontech.dble.net.mysql.*;
import com.actiontech.dble.services.manager.ManagerService;
import com.actiontech.dble.net.service.AbstractService;
import com.actiontech.dble.util.LongUtil;
import java.nio.ByteBuffer;
/**
* @author yuanlinzhu
*/
public final class SelectMaxAllowedPacket {
private SelectMaxAllowedPacket() {
}
@@ -34,7 +38,7 @@ public final class SelectMaxAllowedPacket {
EOF.setPacketId(++packetId);
}
public static void execute(ManagerService service) {
public static void execute(AbstractService service) {
ByteBuffer buffer = service.allocate();
// write header
@@ -52,7 +56,7 @@ public final class SelectMaxAllowedPacket {
byte packetId = EOF.getPacketId();
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.setPacketId(++packetId);
row.add(LongUtil.toBytes(1048576));
row.add(LongUtil.toBytes(SystemConfig.getInstance().getMaxPacketSize()));
buffer = row.write(buffer, service, true);
// write last eof