Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit 1fbdba1

Browse files
Tianyi Chenapavlo
authored andcommitted
solve noop query handling
1 parent b7805ac commit 1fbdba1

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

src/network/postgres_protocol_handler.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -425,15 +425,17 @@ void PostgresProtocolHandler::ExecParseMessage(InputPacket *pkt) {
425425
return;
426426
}
427427

428-
// If the query is either empty or redundant commands, or not supported yet,
428+
// If the query is not supported yet,
429429
// we will skip the rest commands (B,E,..) for this query
430-
bool skip = (sql_stmt_list.get() == nullptr ||
430+
// For empty query, we still want to get it constructed
431+
// TODO (Tianyi) Consider handle more statement
432+
bool empty = (sql_stmt_list.get() == nullptr ||
431433
sql_stmt_list->GetNumStatements() == 0);
432-
if (!skip) {
434+
if (!empty) {
433435
parser::SQLStatement *sql_stmt = sql_stmt_list->GetStatement(0);
434436
query_type = StatementTypeToQueryType(sql_stmt->GetType(), sql_stmt);
435437
}
436-
skip = skip || !HardcodedExecuteFilter(query_type);
438+
bool skip = !HardcodedExecuteFilter(query_type);
437439
if (skip) {
438440
skipped_stmt_ = true;
439441
skipped_query_string_ = query;
@@ -539,6 +541,20 @@ void PostgresProtocolHandler::ExecBindMessage(InputPacket *pkt) {
539541
LOG_ERROR("%s", error_message.c_str());
540542
SendErrorResponse(
541543
{{NetworkMessageType::HUMAN_READABLE_ERROR, error_message}});
544+
return;
545+
}
546+
547+
// Empty query
548+
if (statement->GetQueryType() == QueryType::QUERY_INVALID) {
549+
std::unique_ptr<OutputPacket> response(new OutputPacket());
550+
// Send Bind complete response
551+
response->msg_type = NetworkMessageType::BIND_COMPLETE;
552+
responses.push_back(std::move(response));
553+
// TODO(Tianyi) This is a hack to respond correct describe message
554+
// as well as execute message
555+
skipped_stmt_ = true;
556+
skipped_query_string_ == "";
557+
return;
542558
}
543559

544560
// UNNAMED STATEMENT

src/traffic_cop/traffic_cop.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,19 @@ std::shared_ptr<Statement> TrafficCop::PrepareStatement(
255255
UNUSED_ATTRIBUTE std::string &error_message,
256256
const size_t thread_id UNUSED_ATTRIBUTE) {
257257
LOG_TRACE("Prepare Statement query: %s", query_string.c_str());
258+
259+
// Empty statement
260+
// TODO (Tianyi) Read through the parser code to see if this is appropriate
261+
if (sql_stmt_list.get() == nullptr ||
262+
sql_stmt_list->GetNumStatements() == 0) {
263+
264+
// TODO (Tianyi) Do we need another query type called QUERY_EMPTY?
265+
std::shared_ptr<Statement> statement =
266+
std::make_shared<Statement>(stmt_name, QueryType::QUERY_INVALID,
267+
query_string, std::move(sql_stmt_list));
268+
return statement;
269+
}
270+
258271
StatementType stmt_type = sql_stmt_list->GetStatement(0)->GetType();
259272
QueryType query_type =
260273
StatementTypeToQueryType(stmt_type, sql_stmt_list->GetStatement(0));

0 commit comments

Comments
 (0)