You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/11/08 06:32:01 UTC

[GitHub] [shardingsphere] tuichenchuxin commented on a diff in pull request #22004: Do not throw an exception if the statement contains `if not exists`

tuichenchuxin commented on code in PR #22004:
URL: https://github.com/apache/shardingsphere/pull/22004#discussion_r1016190734


##########
kernel/single-table/core/src/main/java/org/apache/shardingsphere/singletable/route/engine/SingleTableStandardRouteEngine.java:
##########
@@ -82,9 +83,14 @@ private void route0(final RouteContext routeContext, final SingleTableRule rule)
         if (sqlStatement instanceof CreateTableStatement) {
             String dataSourceName = rule.assignNewDataSourceName();
             QualifiedTable table = singleTableNames.iterator().next();
-            if (isTableExists(table, rule)) {
+            boolean tableExists = isTableExists(table, rule);
+            boolean ifNotExists = CreateTableStatementHandler.ifNotExists((CreateTableStatement) sqlStatement);
+            if (tableExists && !ifNotExists) {
                 throw new TableExistsException(table.getTableName());
             }
+            if (tableExists) {
+                return;

Review Comment:
   just return may cause create table if not exists actually execute. And if ds_0 has this table. It may execute on ds_1 ,Then we'll get two same name single table.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org