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/10/10 06:37:56 UTC

[GitHub] [shardingsphere] yunmengmeng opened a new issue, #18837: LAST_INSERT_ID() is wrong

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

   I set two databases.The second is sharding database.
   When i use ` INSERT INTO   .... SELECT LAST_INSERT_ID() AS ...` to the first dabase,the tables's primary key type is auto-incrment,it saves in the first database,but when querying insert id,it's return value is wrong.Just retuns 0.
   
   ### Which version of ShardingSphere did you use?
   5.1.2
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   ShardingSphere-JDBC
   ### Expected behavior
   LAST_INSERT_ID()
   ### Actual behavior
   0
   ### Reason analyze (If you can)
   It chooses the second database.
   
   
   ![image](https://user-images.githubusercontent.com/46476040/177172870-397deb3a-d77c-4ad8-ae73-2c056ebeae94.png)
   
   PartialSQLRouteExecutor
   
   ![image](https://user-images.githubusercontent.com/46476040/177173113-0434040d-4b8f-4473-9f29-5eee18a2fd8c.png)
   
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
   INSERT INTO tree1 (pid) VALUES (1);
   SELECT LAST_INSERT_ID() AS id;
   
   
   
   


-- 
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] chenzhikun12 commented on issue #18837: LAST_INSERT_ID() is wrong

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

   > 你好@yunmengmeng, 感谢您的反馈意见。如果您使用分片功能,那么我建议使用分布式 id 而不是 mysql 递增 id。
   
   我配置了分布式id,数据能够正常insert进数据库,并且数据库中有雪花算法生成的id,但当我想从内存中获取id时很像发现没有回写id,我想知道支持主键回写吗?


-- 
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] github-actions[bot] commented on issue #18837: LAST_INSERT_ID() is wrong

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on issue #18837:
URL: https://github.com/apache/shardingsphere/issues/18837#issuecomment-1272349499

   Hello , this issue has not received a reply for several days.
   This issue is supposed to be closed.


-- 
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] yunmengmeng commented on issue #18837: LAST_INSERT_ID() is wrong

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

   now i use `useGeneratedKeys="true" keyProperty="xxx"` to replace `SELECT LAST_INSERT_ID() `


-- 
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] strongduanmu commented on issue #18837: LAST_INSERT_ID() is wrong

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

   Hi @yunmengmeng, thank you for your feedback. If you are using sharding feature, then I recommend using distributed id instead of mysql incrementing id.


-- 
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] github-actions[bot] closed issue #18837: LAST_INSERT_ID() is wrong

Posted by GitBox <gi...@apache.org>.
github-actions[bot] closed issue #18837: LAST_INSERT_ID() is wrong
URL: https://github.com/apache/shardingsphere/issues/18837


-- 
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] yunmengmeng commented on issue #18837: LAST_INSERT_ID() is wrong

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

   目前可以使用`useGeneratedKeys="true" keyProperty="xxx"`来替代


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