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/06/21 06:19:11 UTC

[GitHub] [shardingsphere] IneverStop opened a new issue, #18487: Can not get correct result

IneverStop opened a new issue, #18487:
URL: https://github.com/apache/shardingsphere/issues/18487

   ## Bug Report
   
   ### Which version of ShardingSphere did you use?
   5.1.1
   
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
    
   ShardingSphere-JDBC
   
   ### Problem description
   
   Here is my table DDL:
   ```sql
   CREATE TABLE `user` (
     `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'user id',
     `name` varchar(255) NOT NULL DEFAULT '' COMMENT 'user name',
     PRIMARY KEY (`id`)
   ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
   ```
   
   Here is part of pom.xml:
   ```xml
   <dependency>
               <groupId>com.baomidou</groupId>
               <artifactId>mybatis-plus-boot-starter</artifactId>
               <version>3.4.3</version>
           </dependency>
           <dependency>
               <groupId>org.apache.shardingsphere</groupId>
               <artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
               <version>5.1.1</version>
           </dependency>
   ```
   
   Here is entity:
   ```java
   @Data
   @TableName("user")
   public class User {
       private static final long serialVersionUID = 1L;
   
       @TableId(value = "id", type = IdType.AUTO)
       private Long id;
   
       private String name;
   
       @TableField(exist = false)
       private long idp;
   }
   ```
   
   This mybatis sql works:
   ```xml
       <select id="selectOneNoUpdate" resultType="org.example.learn.entity.User">
           SELECT id, name, id + 1 as idp FROM user where id = #{id}
       </select>
   ```
   logs:
   ```
   ==>  Preparing: SELECT id, name, id+ 1 as idp FROM user where id = ?
   ==> Parameters: 1(Long)
   2022-06-21 14:16:02.239  INFO 18960 --- [nio-8081-exec-6] ShardingSphere-SQL                       : Logic SQL: SELECT id, name, id+ 1 as idp FROM user where id = ?
   2022-06-21 14:16:02.239  INFO 18960 --- [nio-8081-exec-6] ShardingSphere-SQL                       : SQLStatement: MySQLSelectStatement(table=Optional.empty, limit=Optional.empty, lock=Optional.empty, window=Optional.empty)
   2022-06-21 14:16:02.239  INFO 18960 --- [nio-8081-exec-6] ShardingSphere-SQL                       : Actual SQL: slave ::: SELECT id, name, id+ 1 as idp FROM user where id = ? ::: [1]
   <==    Columns: id, name, idp
   <==        Row: 1, bee, 2
   <==      Total: 1
   ```
   As you can see, I got id、name、idp as I wish.
   
   But this mybatis sql not works:
   ```xml
       <select id="selectOneNoUpdate" resultType="org.example.learn.entity.User">
           SELECT * FROM (SELECT id, name, id + 1 as idp FROM user where id = #{id} ) temp
       </select>
   ```
   logs:
   ```
   ==>  Preparing: SELECT * FROM (SELECT id, name, id + 1 as idp FROM user where id = ? ) temp
   ==> Parameters: 1(Long)
   2022-06-21 14:18:04.824  INFO 7720 --- [nio-8081-exec-4] ShardingSphere-SQL                       : Logic SQL: SELECT * FROM (SELECT id, name, id + 1 as idp FROM user where id = ? ) temp
   2022-06-21 14:18:04.824  INFO 7720 --- [nio-8081-exec-4] ShardingSphere-SQL                       : SQLStatement: MySQLSelectStatement(table=Optional.empty, limit=Optional.empty, lock=Optional.empty, window=Optional.empty)
   2022-06-21 14:18:04.824  INFO 7720 --- [nio-8081-exec-4] ShardingSphere-SQL                       : Actual SQL: slave ::: SELECT * FROM (SELECT id, name, id + 1 as idp FROM user where id = ? ) temp ::: [1]
   <==    Columns: id, name
   <==        Row: 1, bee
   <==      Total: 1
   ```
   As you can see, I can not get `idp`
   
   How can i fix this problem?
   


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

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


[GitHub] [shardingsphere] IneverStop commented on issue #18487: Can not get correct result

Posted by GitBox <gi...@apache.org>.
IneverStop commented on issue #18487:
URL: https://github.com/apache/shardingsphere/issues/18487#issuecomment-1161340774

   ```java
   org.apache.shardingsphere.infra.binder.segment.select.projection.engine.ProjectionEngine
   
       private Collection<ColumnProjection> getColumnProjections(final Collection<Projection> projections) {
           Collection<ColumnProjection> result = new LinkedList<>();
           for (Projection each : projections) {
               if (each instanceof ColumnProjection) {
                   result.add((ColumnProjection) each);
               }
               if (each instanceof ShorthandProjection) {
                   result.addAll(((ShorthandProjection) each).getActualColumns().values());
               }
           }
           return result;
       }
   ```
   
   `id + 1` is a `ExpressionProjection`, so this function will skip `ExpressionProjection`, may be this occur the problem.


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


[GitHub] [shardingsphere] terrymanu commented on issue #18487: Sub query Can not get correct result

Posted by GitBox <gi...@apache.org>.
terrymanu commented on issue #18487:
URL: https://github.com/apache/shardingsphere/issues/18487#issuecomment-1182121808

   Can you try to analyze by JDBC layer? The 3rd party library is too complicated, I am afraid we have no enough time to investigate it.


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


[GitHub] [shardingsphere] terrymanu commented on issue #18487: Sub query Can not get correct result

Posted by GitBox <gi...@apache.org>.
terrymanu commented on issue #18487:
URL: https://github.com/apache/shardingsphere/issues/18487#issuecomment-1193649006

   Closed because of no feedback for long time.


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


[GitHub] [shardingsphere] terrymanu closed issue #18487: Sub query Can not get correct result

Posted by GitBox <gi...@apache.org>.
terrymanu closed issue #18487: Sub query Can not get correct result
URL: https://github.com/apache/shardingsphere/issues/18487


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