From ebb187ac8277a8648367373a4cbdeeea49542508 Mon Sep 17 00:00:00 2001 From: wenyh1 <2365151147@qq.com> Date: Mon, 5 Feb 2024 15:13:21 +0800 Subject: [PATCH] [inner-2340] fix: explain' lost connection.... (cherry picked from commit 2b87829dc786e4644c4ee67bf842a94a887ec04f) --- .../dble/server/handler/ExplainHandler.java | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/actiontech/dble/server/handler/ExplainHandler.java b/src/main/java/com/actiontech/dble/server/handler/ExplainHandler.java index 87d7c7c93d..986f011628 100644 --- a/src/main/java/com/actiontech/dble/server/handler/ExplainHandler.java +++ b/src/main/java/com/actiontech/dble/server/handler/ExplainHandler.java @@ -42,6 +42,7 @@ import java.sql.SQLException; import java.sql.SQLNonTransientException; import java.sql.SQLSyntaxErrorException; +import java.util.LinkedList; import java.util.List; /** @@ -197,6 +198,7 @@ private static boolean isInsertSeq(ShardingService service, String stmt, SchemaC } public static void writeOutHeadAndEof(ShardingService service, RouteResultset rrs) { + final List rows = getRows(service, rrs); ByteBuffer buffer = service.allocate(); // writeDirectly header ResultSetHeaderPacket header = PacketUtil.getHeader(FIELD_COUNT); @@ -214,12 +216,23 @@ public static void writeOutHeadAndEof(ShardingService service, RouteResultset rr eof.setPacketId(service.nextPacketId()); buffer = eof.write(buffer, service, true); + // writeDirectly rows + for (RowDataPacket row : rows) { + row.setPacketId(service.nextPacketId()); + buffer = row.write(buffer, service, true); + } + + // writeDirectly last eof + EOFRowPacket lastEof = new EOFRowPacket(); + lastEof.setPacketId(service.nextPacketId()); + lastEof.write(buffer, service); + } + + private static List getRows(ShardingService service, RouteResultset rrs) { + LinkedList rows = new LinkedList<>(); if (!rrs.isNeedOptimizer()) { - // writeDirectly rows for (RouteResultsetNode node : rrs.getNodes()) { - RowDataPacket row = getRow(node, service.getCharset().getResults()); - row.setPacketId(service.nextPacketId()); - buffer = row.write(buffer, service, true); + rows.add(getRow(node, service.getCharset().getResults())); } } else { BaseHandlerBuilder builder = buildNodes(rrs, service); @@ -229,13 +242,9 @@ public static void writeOutHeadAndEof(ShardingService service, RouteResultset rr row.add(StringUtil.encode(result.getName(), service.getCharset().getResults())); row.add(StringUtil.encode(result.getType(), service.getCharset().getResults())); row.add(StringUtil.encode(result.getRefOrSQL(), service.getCharset().getResults())); - row.setPacketId(service.nextPacketId()); - buffer = row.write(buffer, service, true); + rows.add(row); } } - // writeDirectly last eof - EOFRowPacket lastEof = new EOFRowPacket(); - lastEof.setPacketId(service.nextPacketId()); - lastEof.write(buffer, service); + return rows; } }