Skip to content

Commit

Permalink
[inner-2321] fix: explain statement contained in multiple-sql appears…
Browse files Browse the repository at this point in the history
… lost connection...

(cherry picked from commit 02f9ee6)
  • Loading branch information
wenyh1 committed Jan 14, 2024
1 parent 5531360 commit d807f21
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,33 +246,33 @@ public static void writeOutHeadAndEof(ShardingService service, RouteResultset rr
ByteBuffer buffer = service.allocate();
// writeDirectly header
ResultSetHeaderPacket header = PacketUtil.getHeader(FIELD_COUNT);
byte packetId = header.getPacketId();
header.setPacketId(service.nextPacketId());
buffer = header.write(buffer, service, true);

// writeDirectly fields
for (FieldPacket field : FIELDS) {
field.setPacketId(++packetId);
field.setPacketId(service.nextPacketId());
buffer = field.write(buffer, service, true);
}

// writeDirectly eof
EOFPacket eof = new EOFPacket();
eof.setPacketId(++packetId);
eof.setPacketId(service.nextPacketId());
buffer = eof.write(buffer, service, true);

if (!rrs.isNeedOptimizer()) {
// writeDirectly rows
for (RouteResultsetNode node : rrs.getNodes()) {
RowDataPacket row = getRow(node, service.getCharset().getResults());
row.setPacketId(++packetId);
row.setPacketId(service.nextPacketId());
buffer = row.write(buffer, service, true);
}
} else {
BaseHandlerBuilder builder = buildNodes(rrs, service);
RouteResultsetNode routeSingleNode = getTryRouteSingleNode(builder, rrs);
if (routeSingleNode != null) {
RowDataPacket row = getRow(routeSingleNode, service.getCharset().getResults());
row.setPacketId(++packetId);
row.setPacketId(service.nextPacketId());
buffer = row.write(buffer, service, true);
} else {
List<ReferenceHandlerInfo> results = ComplexQueryPlanUtil.getComplexQueryResult(builder);
Expand All @@ -281,14 +281,14 @@ 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(++packetId);
row.setPacketId(service.nextPacketId());
buffer = row.write(buffer, service, true);
}
}
}
// writeDirectly last eof
EOFRowPacket lastEof = new EOFRowPacket();
lastEof.setPacketId(++packetId);
lastEof.setPacketId(service.nextPacketId());
lastEof.write(buffer, service);
}
}

0 comments on commit d807f21

Please sign in to comment.