You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2022/07/10 10:52:52 UTC

[shardingsphere] branch master updated: Use SPI to handle PostgreSQL SET variable behaviour (#19002)

This is an automated email from the ASF dual-hosted git repository.

panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 49f1b5a3da9 Use SPI to handle PostgreSQL SET variable behaviour (#19002)
49f1b5a3da9 is described below

commit 49f1b5a3da9428b893098af612ff36ccdf68b61b
Author: 吴伟杰 <wu...@apache.org>
AuthorDate: Sun Jul 10 18:52:46 2022 +0800

    Use SPI to handle PostgreSQL SET variable behaviour (#19002)
---
 .../admin/executor/SessionVariableHandler.java     | 36 ++++++++++++++++++
 .../DefaultPostgreSQLSessionVariableHandler.java   | 35 ++++++++++++++++++
 .../postgresql/PostgreSQLAdminExecutorCreator.java | 23 +-----------
 .../PostgreSQLSessionVariableHandler.java          | 28 ++++++++++++++
 .../PostgreSQLSessionVariableHandlerFactory.java   | 41 +++++++++++++++++++++
 ...ava => PostgreSQLSetVariableAdminExecutor.java} | 31 ++++------------
 .../executor/PostgreSQLSetCharsetExecutor.java     | 16 ++++----
 ...min.postgresql.PostgreSQLSessionVariableHandler | 18 +++++++++
 ...efaultPostgreSQLSessionVariableHandlerTest.java | 35 ++++++++++++++++++
 .../PostgreSQLAdminExecutorFactoryTest.java        |  3 +-
 .../PostgreSQLSetVariableAdminExecutorTest.java    | 43 ++++++++++++++++++++++
 11 files changed, 254 insertions(+), 55 deletions(-)

diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/executor/SessionVariableHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/executor/SessionVariableHandler.java
new file mode 100644
index 00000000000..13ece21f7da
--- /dev/null
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/executor/SessionVariableHandler.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.proxy.backend.text.admin.executor;
+
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+import org.apache.shardingsphere.spi.type.typed.TypedSPI;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.SetStatement;
+
+/**
+ * Session variable handler.
+ */
+public interface SessionVariableHandler extends TypedSPI {
+    
+    /**
+     * Handle set statement for specific connection session.
+     *
+     * @param connectionSession connection session
+     * @param setStatement set statement
+     */
+    void handle(ConnectionSession connectionSession, SetStatement setStatement);
+}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/DefaultPostgreSQLSessionVariableHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/DefaultPostgreSQLSessionVariableHandler.java
new file mode 100644
index 00000000000..b30bf57367c
--- /dev/null
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/DefaultPostgreSQLSessionVariableHandler.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.proxy.backend.text.admin.postgresql;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.SetStatement;
+
+/**
+ * Default session variable handler for PostgreSQL.
+ */
+@Slf4j
+public final class DefaultPostgreSQLSessionVariableHandler implements PostgreSQLSessionVariableHandler {
+    
+    @Override
+    public void handle(final ConnectionSession connectionSession, final SetStatement setStatement) {
+        log.debug("Set statement {} was discarded.", setStatement.getVariableAssigns().stream().findFirst()
+                .map(segment -> String.format("%s = %s", segment.getVariable().getVariable(), segment.getAssignValue())).orElseGet(setStatement::toString));
+    }
+}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/PostgreSQLAdminExecutorCreator.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/PostgreSQLAdminExecutorCreator.java
index 3c13e07856d..099bbf998a3 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/PostgreSQLAdminExecutorCreator.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/PostgreSQLAdminExecutorCreator.java
@@ -21,11 +21,9 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
 import org.apache.shardingsphere.proxy.backend.text.admin.executor.AbstractDatabaseMetadataExecutor.DefaultDatabaseMetadataExecutor;
 import org.apache.shardingsphere.proxy.backend.text.admin.executor.DatabaseAdminExecutor;
 import org.apache.shardingsphere.proxy.backend.text.admin.executor.DatabaseAdminExecutorCreator;
-import org.apache.shardingsphere.proxy.backend.text.admin.postgresql.executor.PostgreSQLSetCharsetExecutor;
 import org.apache.shardingsphere.proxy.backend.text.admin.postgresql.executor.SelectDatabaseExecutor;
 import org.apache.shardingsphere.proxy.backend.text.admin.postgresql.executor.SelectTableExecutor;
 import org.apache.shardingsphere.sql.parser.sql.common.extractor.TableExtractor;
-import org.apache.shardingsphere.sql.parser.sql.common.segment.dal.VariableAssignSegment;
 import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
 import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SubqueryTableSegment;
 import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableSegment;
@@ -34,7 +32,6 @@ import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.SetStatemen
 import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
 
 import java.util.Collection;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Optional;
 import java.util.stream.Collectors;
@@ -76,20 +73,7 @@ public final class PostgreSQLAdminExecutorCreator implements DatabaseAdminExecut
                 return Optional.of(new DefaultDatabaseMetadataExecutor(sql));
             }
         }
-        if (sqlStatement instanceof SetStatement) {
-            SetStatement setStatement = (SetStatement) sqlStatement;
-            // TODO Consider refactoring this with SPI.
-            switch (getSetConfigurationParameter(setStatement)) {
-                case "client_encoding":
-                    return Optional.of(new PostgreSQLSetCharsetExecutor(setStatement));
-                case "extra_float_digits":
-                case "application_name":
-                    return Optional.of(connectionSession -> {
-                    });
-                default:
-            }
-        }
-        return Optional.empty();
+        return sqlStatement instanceof SetStatement ? Optional.of(new PostgreSQLSetVariableAdminExecutor((SetStatement) sqlStatement)) : Optional.empty();
     }
     
     private boolean isQueryPgTable(final Collection<String> selectedTableNames) {
@@ -110,11 +94,6 @@ public final class PostgreSQLAdminExecutorCreator implements DatabaseAdminExecut
                 .map(each -> ((SimpleTableSegment) each).getTableName().getIdentifier().getValue()).collect(Collectors.toList());
     }
     
-    private String getSetConfigurationParameter(final SetStatement setStatement) {
-        Iterator<VariableAssignSegment> iterator = setStatement.getVariableAssigns().iterator();
-        return iterator.hasNext() ? iterator.next().getVariable().getVariable().toLowerCase() : "";
-    }
-    
     @Override
     public String getType() {
         return "PostgreSQL";
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/PostgreSQLSessionVariableHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/PostgreSQLSessionVariableHandler.java
new file mode 100644
index 00000000000..5d492403e21
--- /dev/null
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/PostgreSQLSessionVariableHandler.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.proxy.backend.text.admin.postgresql;
+
+import org.apache.shardingsphere.proxy.backend.text.admin.executor.SessionVariableHandler;
+import org.apache.shardingsphere.spi.annotation.SingletonSPI;
+
+/**
+ * Session variable handler for PostgreSQL.
+ */
+@SingletonSPI
+public interface PostgreSQLSessionVariableHandler extends SessionVariableHandler {
+}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/PostgreSQLSessionVariableHandlerFactory.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/PostgreSQLSessionVariableHandlerFactory.java
new file mode 100644
index 00000000000..3279720f542
--- /dev/null
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/PostgreSQLSessionVariableHandlerFactory.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.proxy.backend.text.admin.postgresql;
+
+import org.apache.shardingsphere.spi.ShardingSphereServiceLoader;
+import org.apache.shardingsphere.spi.type.typed.TypedSPIRegistry;
+
+/**
+ * Factory for {@link PostgreSQLSessionVariableHandler}.
+ */
+public final class PostgreSQLSessionVariableHandlerFactory {
+    
+    static {
+        ShardingSphereServiceLoader.register(PostgreSQLSessionVariableHandler.class);
+    }
+    
+    /**
+     * Get {@link PostgreSQLSessionVariableHandler} for specific variable.
+     *
+     * @param variableName variable name
+     * @return {@link PostgreSQLSessionVariableHandler} for variable
+     */
+    public static PostgreSQLSessionVariableHandler getHandler(final String variableName) {
+        return TypedSPIRegistry.findRegisteredService(PostgreSQLSessionVariableHandler.class, variableName).orElseGet(DefaultPostgreSQLSessionVariableHandler::new);
+    }
+}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/PostgreSQLSetCharsetExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/PostgreSQLSetVariableAdminExecutor.java
similarity index 52%
copy from shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/PostgreSQLSetCharsetExecutor.java
copy to shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/PostgreSQLSetVariableAdminExecutor.java
index 60d7031cca2..e76acd626ad 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/PostgreSQLSetCharsetExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/PostgreSQLSetVariableAdminExecutor.java
@@ -15,47 +15,32 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.proxy.backend.text.admin.postgresql.executor;
+package org.apache.shardingsphere.proxy.backend.text.admin.postgresql;
 
 import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.db.protocol.CommonConstants;
-import org.apache.shardingsphere.proxy.backend.exception.InvalidParameterValueException;
 import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
 import org.apache.shardingsphere.proxy.backend.text.admin.executor.DatabaseAdminExecutor;
-import org.apache.shardingsphere.proxy.backend.text.admin.postgresql.PostgreSQLCharacterSets;
 import org.apache.shardingsphere.sql.parser.sql.common.segment.dal.VariableAssignSegment;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.SetStatement;
 
-import java.nio.charset.Charset;
-import java.nio.charset.StandardCharsets;
 import java.sql.SQLException;
-import java.util.Locale;
+import java.util.Iterator;
 
 /**
- * Set charset executor of PostgreSQL.
+ * Set variable admin executor for PostgreSQL.
  */
 @RequiredArgsConstructor
-public final class PostgreSQLSetCharsetExecutor implements DatabaseAdminExecutor {
+public final class PostgreSQLSetVariableAdminExecutor implements DatabaseAdminExecutor {
     
     private final SetStatement setStatement;
     
     @Override
     public void execute(final ConnectionSession connectionSession) throws SQLException {
-        VariableAssignSegment segment = setStatement.getVariableAssigns().iterator().next();
-        String value = formatValue(segment.getAssignValue().trim());
-        connectionSession.getAttributeMap().attr(CommonConstants.CHARSET_ATTRIBUTE_KEY).set(parseCharset(value));
+        PostgreSQLSessionVariableHandlerFactory.getHandler(getSetConfigurationParameter(setStatement)).handle(connectionSession, setStatement);
     }
     
-    private String formatValue(final String value) {
-        return value.startsWith("'") && value.endsWith("'") ? value.substring(1, value.length() - 1).trim() : value;
-    }
-    
-    private Charset parseCharset(final String value) {
-        try {
-            String result = value.toLowerCase(Locale.ROOT);
-            return "default".equals(result) ? StandardCharsets.UTF_8 : PostgreSQLCharacterSets.findCharacterSet(result);
-        } catch (final IllegalArgumentException ignored) {
-            throw new InvalidParameterValueException("client_encoding", value.toLowerCase(Locale.ROOT));
-        }
+    private String getSetConfigurationParameter(final SetStatement setStatement) {
+        Iterator<VariableAssignSegment> iterator = setStatement.getVariableAssigns().iterator();
+        return iterator.hasNext() ? iterator.next().getVariable().getVariable().toLowerCase() : "";
     }
 }
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/PostgreSQLSetCharsetExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/PostgreSQLSetCharsetExecutor.java
index 60d7031cca2..1e558658c77 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/PostgreSQLSetCharsetExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/executor/PostgreSQLSetCharsetExecutor.java
@@ -17,30 +17,25 @@
 
 package org.apache.shardingsphere.proxy.backend.text.admin.postgresql.executor;
 
-import lombok.RequiredArgsConstructor;
 import org.apache.shardingsphere.db.protocol.CommonConstants;
 import org.apache.shardingsphere.proxy.backend.exception.InvalidParameterValueException;
 import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
-import org.apache.shardingsphere.proxy.backend.text.admin.executor.DatabaseAdminExecutor;
 import org.apache.shardingsphere.proxy.backend.text.admin.postgresql.PostgreSQLCharacterSets;
+import org.apache.shardingsphere.proxy.backend.text.admin.postgresql.PostgreSQLSessionVariableHandler;
 import org.apache.shardingsphere.sql.parser.sql.common.segment.dal.VariableAssignSegment;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.dal.SetStatement;
 
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
-import java.sql.SQLException;
 import java.util.Locale;
 
 /**
  * Set charset executor of PostgreSQL.
  */
-@RequiredArgsConstructor
-public final class PostgreSQLSetCharsetExecutor implements DatabaseAdminExecutor {
-    
-    private final SetStatement setStatement;
+public final class PostgreSQLSetCharsetExecutor implements PostgreSQLSessionVariableHandler {
     
     @Override
-    public void execute(final ConnectionSession connectionSession) throws SQLException {
+    public void handle(final ConnectionSession connectionSession, final SetStatement setStatement) {
         VariableAssignSegment segment = setStatement.getVariableAssigns().iterator().next();
         String value = formatValue(segment.getAssignValue().trim());
         connectionSession.getAttributeMap().attr(CommonConstants.CHARSET_ATTRIBUTE_KEY).set(parseCharset(value));
@@ -58,4 +53,9 @@ public final class PostgreSQLSetCharsetExecutor implements DatabaseAdminExecutor
             throw new InvalidParameterValueException("client_encoding", value.toLowerCase(Locale.ROOT));
         }
     }
+    
+    @Override
+    public String getType() {
+        return "client_encoding";
+    }
 }
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/resources/META-INF/services/org.apache.shardingsphere.proxy.backend.text.admin.postgresql.PostgreSQLSessionVariableHandler b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/resources/META-INF/services/org.apache.shardingsphere.proxy.backend.text.admin.postgresql.PostgreSQLSessionVariableHandler
new file mode 100644
index 00000000000..59e8fae7661
--- /dev/null
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/resources/META-INF/services/org.apache.shardingsphere.proxy.backend.text.admin.postgresql.PostgreSQLSessionVariableHandler
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.proxy.backend.text.admin.postgresql.executor.PostgreSQLSetCharsetExecutor
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/DefaultPostgreSQLSessionVariableHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/DefaultPostgreSQLSessionVariableHandlerTest.java
new file mode 100644
index 00000000000..0001cabf4fa
--- /dev/null
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/DefaultPostgreSQLSessionVariableHandlerTest.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.proxy.backend.text.admin.postgresql;
+
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.dal.PostgreSQLSetStatement;
+import org.junit.Test;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verifyNoInteractions;
+
+public final class DefaultPostgreSQLSessionVariableHandlerTest {
+    
+    @Test
+    public void assertHandle() {
+        ConnectionSession connectionSession = mock(ConnectionSession.class);
+        new DefaultPostgreSQLSessionVariableHandler().handle(connectionSession, new PostgreSQLSetStatement());
+        verifyNoInteractions(connectionSession);
+    }
+}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/PostgreSQLAdminExecutorFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/PostgreSQLAdminExecutorFactoryTest.java
index d14d61fb09a..8ca19d854e8 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/PostgreSQLAdminExecutorFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/PostgreSQLAdminExecutorFactoryTest.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
 import org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
 import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
 import org.apache.shardingsphere.proxy.backend.text.admin.executor.DatabaseAdminExecutor;
-import org.apache.shardingsphere.proxy.backend.text.admin.postgresql.executor.PostgreSQLSetCharsetExecutor;
 import org.apache.shardingsphere.proxy.backend.text.admin.postgresql.executor.SelectDatabaseExecutor;
 import org.apache.shardingsphere.sql.parser.sql.common.segment.dal.VariableAssignSegment;
 import org.apache.shardingsphere.sql.parser.sql.common.segment.dal.VariableSegment;
@@ -78,7 +77,7 @@ public final class PostgreSQLAdminExecutorFactoryTest {
         CommonSQLStatementContext<SetStatement> statementContext = new CommonSQLStatementContext<>(setStatement);
         Optional<DatabaseAdminExecutor> actual = postgreSQLAdminExecutorFactory.create(statementContext, null, null);
         assertTrue(actual.isPresent());
-        assertThat(actual.get(), instanceOf(PostgreSQLSetCharsetExecutor.class));
+        assertThat(actual.get(), instanceOf(PostgreSQLSetVariableAdminExecutor.class));
     }
     
     @Test
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/PostgreSQLSetVariableAdminExecutorTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/PostgreSQLSetVariableAdminExecutorTest.java
new file mode 100644
index 00000000000..227bdf9df00
--- /dev/null
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/postgresql/PostgreSQLSetVariableAdminExecutorTest.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.proxy.backend.text.admin.postgresql;
+
+import org.apache.shardingsphere.sql.parser.sql.dialect.statement.postgresql.dal.PostgreSQLSetStatement;
+import org.junit.Test;
+import org.mockito.MockedStatic;
+
+import java.sql.SQLException;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
+import static org.mockito.Mockito.verify;
+
+public final class PostgreSQLSetVariableAdminExecutorTest {
+    
+    @Test
+    public void assertExecute() throws SQLException {
+        PostgreSQLSetStatement setStatement = new PostgreSQLSetStatement();
+        PostgreSQLSetVariableAdminExecutor executor = new PostgreSQLSetVariableAdminExecutor(setStatement);
+        try (MockedStatic<PostgreSQLSessionVariableHandlerFactory> mockStatic = mockStatic(PostgreSQLSessionVariableHandlerFactory.class)) {
+            PostgreSQLSessionVariableHandler mockHandler = mock(PostgreSQLSessionVariableHandler.class);
+            mockStatic.when(() -> PostgreSQLSessionVariableHandlerFactory.getHandler("")).thenReturn(mockHandler);
+            executor.execute(null);
+            verify(mockHandler).handle(null, setStatement);
+        }
+    }
+}