Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[inner-2340] fix: explain' lost connection.... #3863

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.sql.SQLException;
import java.sql.SQLNonTransientException;
import java.sql.SQLSyntaxErrorException;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -243,6 +244,7 @@ private static RouteResultsetNode getTryRouteSingleNode(BaseHandlerBuilder build
}

public static void writeOutHeadAndEof(ShardingService service, RouteResultset rrs) {
final List<RowDataPacket> rows = getRows(service, rrs);
ByteBuffer buffer = service.allocate();
// writeDirectly header
ResultSetHeaderPacket header = PacketUtil.getHeader(FIELD_COUNT);
Expand All @@ -260,20 +262,30 @@ 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<RowDataPacket> getRows(ShardingService service, RouteResultset rrs) {
LinkedList<RowDataPacket> 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);
RouteResultsetNode routeSingleNode = getTryRouteSingleNode(builder, rrs);
if (routeSingleNode != null) {
RowDataPacket row = getRow(routeSingleNode, service.getCharset().getResults());
row.setPacketId(service.nextPacketId());
buffer = row.write(buffer, service, true);
rows.add(getRow(routeSingleNode, service.getCharset().getResults()));
} else {
List<ReferenceHandlerInfo> results = ComplexQueryPlanUtil.getComplexQueryResult(builder);
for (ReferenceHandlerInfo result : results) {
Expand All @@ -282,13 +294,10 @@ public static void writeOutHeadAndEof(ShardingService service, RouteResultset rr
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;
}
}
Loading