Skip to content

Commit

Permalink
[improvement](mysql)Support mysql COM_RESET_CONNECTION command. (#44747)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?
Support mysql COM_RESET_CONNECTION command.
Doris server side reset default catalog and return
ctx.getState().setOk()

Python test code:
```
import mysql.connector

connection = mysql.connector.connect(
    host="172.20.32.136", 
    port=29030,
    user="root", 
    password="", 
    database=""
)
print(connection.cmd_reset_connection())
```

Issue Number: close #xxx

Related PR: #xxx

Problem Summary:

### Release note

None
  • Loading branch information
Jibing-Li authored Nov 29, 2024
1 parent 46575e5 commit 0ffb71b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,11 @@ public String removeLastDBOfCatalog(String catalog) {
return lastDBOfCatalog.get(catalog);
}

// Used by COM_RESET_CONNECTION
public void clearLastDBOfCatalog() {
lastDBOfCatalog.clear();
}

public void setNotEvalNondeterministicFunction(boolean notEvalNondeterministicFunction) {
this.notEvalNondeterministicFunction = notEvalNondeterministicFunction;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.apache.doris.common.util.SqlUtils;
import org.apache.doris.common.util.Util;
import org.apache.doris.datasource.CatalogIf;
import org.apache.doris.datasource.InternalCatalog;
import org.apache.doris.metric.MetricRepo;
import org.apache.doris.mysql.MysqlChannel;
import org.apache.doris.mysql.MysqlPacket;
Expand Down Expand Up @@ -198,6 +199,12 @@ protected void handleDebug() {
ctx.getState().setOk();
}

protected void handleResetConnection() {
ctx.changeDefaultCatalog(InternalCatalog.INTERNAL_CATALOG_NAME);
ctx.clearLastDBOfCatalog();
ctx.getState().setOk();
}

protected void handleStmtReset() {
ctx.getState().setOk();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ private void dispatch() throws IOException {
case COM_SET_OPTION:
handleSetOption();
break;
case COM_RESET_CONNECTION:
handleResetConnection();
break;
default:
ctx.getState().setError(ErrorCode.ERR_UNKNOWN_COM_ERROR, "Unsupported command(" + command + ")");
LOG.warn("Unsupported command(" + command + ")");
Expand Down

0 comments on commit 0ffb71b

Please sign in to comment.