sandynz commented on issue #6729:
URL: https://github.com/apache/shardingsphere/issues/6729#issuecomment-671023051


   Reason analyze of: rewritten sql with wrong values clause "((?, ?))", it 
cause syntax error, it should be "(?, ?)"
   
   Comparing PostgreSQL and MySQL execution process, some screenshots:
   
   
![pg-ctx](https://user-images.githubusercontent.com/42492540/89727752-44899300-da5a-11ea-934b-120812b7a744.png)
   
![mysql-ctx](https://user-images.githubusercontent.com/42492540/89727775-553a0900-da5a-11ea-9971-95102412b084.png)
   ShardingInsertValuesToken have different startIndex and stopIndex.
   
   
![pg-token](https://user-images.githubusercontent.com/42492540/89727797-7c90d600-da5a-11ea-9d15-cdc4a6d0b891.png)
   
![mysql-token](https://user-images.githubusercontent.com/42492540/89727800-83b7e400-da5a-11ea-9b74-1f692d9a1c5a.png)
   
   ```
   ShardingInsertValuesTokenGenerator.java
       @Override
       public InsertValuesToken generateSQLToken(final InsertStatementContext 
insertStatementContext) {
           Collection<InsertValuesSegment> insertValuesSegments = 
(insertStatementContext.getSqlStatement()).getValues();
           InsertValuesToken result = new 
ShardingInsertValuesToken(getStartIndex(insertValuesSegments), 
getStopIndex(insertValuesSegments));
           Iterator<Collection<DataNode>> originalDataNodesIterator = null == 
routeContext || routeContext.getRouteResult().getOriginalDataNodes().isEmpty()
                   ? null : 
routeContext.getRouteResult().getOriginalDataNodes().iterator();
           for (InsertValueContext each : 
insertStatementContext.getInsertValueContexts()) {
               List<ExpressionSegment> expressionSegments = 
each.getValueExpressions();
               Collection<DataNode> dataNodes = null == 
originalDataNodesIterator ? Collections.emptyList() : 
originalDataNodesIterator.next();
               result.getInsertValues().add(new 
ShardingInsertValue(expressionSegments, dataNodes));
           }
           return result;
       }
   ShardingInsertValuesToken is initialized here, index from InsertValuesSegment
   ```
   
   ```
   PostgreSQLDMLVisitor.java
       private Collection<InsertValuesSegment> createInsertValuesSegments(final 
ValuesClauseContext ctx) {
           Collection<InsertValuesSegment> result = new LinkedList<>();
           if (null != ctx.valuesClause()) {
               Collection<InsertValuesSegment> expressions = 
createInsertValuesSegments(ctx.valuesClause());
               result.addAll(expressions);
           }
           Collection<ExpressionSegment> expressions = 
createInsertValuesSegments(ctx.exprList());
           InsertValuesSegment insertValuesSegment = new 
InsertValuesSegment(ctx.exprList().start.getStartIndex(), 
ctx.exprList().stop.getStopIndex(), (List<ExpressionSegment>) expressions);
           result.add(insertValuesSegment);
           return result;
       }
   ctx.exprList().start.getStartIndex(), ctx.exprList().stop.getStopIndex(), 
47,50
   insert into varchar_tc (id, real_name) values (?, ?) , substring(46,52) is 
"(?, ?)"
   ```
   
   Seems it caused by DMLStatement.g4, don't know exact reason
   


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to