Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete with alias error #2961

Closed
wowojyc opened this issue Sep 2, 2019 · 18 comments
Closed

Delete with alias error #2961

wowojyc opened this issue Sep 2, 2019 · 18 comments

Comments

@wowojyc
Copy link

wowojyc commented Sep 2, 2019

Sharding-jdbc
version:4.0.0-RC1
my logical sql
delete Goods from goods AS Goods WHERE Goods.goods_id <= ?

However sharding-jdbc replace alias and the table name totally, just like this
delete goods_1 from goods_1 AS Goods WHERE Goods.goods_id <= ?
this will execute error in mysql 5.6

One solution is to change to another alias different table name, but this may difficult for me. What else should I do?

@wowojyc
Copy link
Author

wowojyc commented Sep 2, 2019

version 4.0.0.-RC1 and 4.0.0.RC2 have different error.

delete goos_s from goods as goods_s where good_s.goods_id< 10 will execute successfully under RC1, but will execute error under RC2

@sunbufu
Copy link
Contributor

sunbufu commented Sep 3, 2019

Can you show some exception?

@wowojyc
Copy link
Author

wowojyc commented Sep 3, 2019

Can you show some exception?
Here is the exception trace, but if i change to 4.0.0.RC1, it will execute normally.
image

@sunbufu
Copy link
Contributor

sunbufu commented Sep 3, 2019

Consider supporting DML for Multiple-Table with low ROI, SS can't support it for now.

@wowojyc
Copy link
Author

wowojyc commented Sep 3, 2019

Consider supporting DML for Multiple-Table with low ROI, SS can't support it for now.

No, it is not multiple table.

It is just add the table alias for delete operation.

And it runs well under 4.0.0-RC1, and it can not support now, is it reasonable?

@sunbufu
Copy link
Contributor

sunbufu commented Sep 3, 2019

Thanks for your issue. I'll look at it.

@strawhat925
Copy link

just saw this piece of source code, is to parse sql bug

@strawhat925
Copy link

Should take tableReferences this node to resolve table name

@wowojyc
Copy link
Author

wowojyc commented Sep 3, 2019

just saw this piece of source code, is to parse sql bug

Thank you for your help. But I can not see your picture, could you reply me again?

@strawhat925
Copy link

<sql-statement-rule context="delete" sql-statement-class="org.apache.shardingsphere.core.parse.sql.statement.dml.DeleteStatement" extractor-rule-refs="tables, columns, where, predicate " />
Tables changed to tableReferences, can be executed normally

@wowojyc
Copy link
Author

wowojyc commented Sep 3, 2019

<sql-statement-rule context="delete" sql-statement-class="org.apache.shardingsphere.core.parse.sql.statement.dml.DeleteStatement" extractor-rule-refs="tables, columns, where, predicate " />
Tables changed to tableReferences, can be executed normally

Thank you very much. This solution does really work.

Is it a bug or not?
@sunbufu

@strawhat925
Copy link

I think it is a bug, but the single table does not support it. Need to judge the data node
Maybe ss did not consider this grammar

@sunbufu
Copy link
Contributor

sunbufu commented Sep 3, 2019

It's looks like a bug, and I will work on it tomorrow. Please let me know if you have any advice.

@wowojyc
Copy link
Author

wowojyc commented Sep 4, 2019

It's looks like a bug, and I will work on it tomorrow. Please let me know if you have any advice.

I follow strawhat925's advice.

Download the source code, then change the xml in mysql-parser module. At the end, I run maven install locally to generate the jar package.

In my application, i replace mysql parser with maven system scope.

It really works.

@strawhat925
Copy link

I follow strawhat925's advice.

Download the source code, then change the xml in mysql-parser module. At the end, I run maven install locally to generate the jar package.

In my application, i replace mysql parser with maven system scope.

It really works.

Need to consider no aliases, I did not consider

@wowojyc
Copy link
Author

wowojyc commented Sep 4, 2019

I follow strawhat925's advice.
Download the source code, then change the xml in mysql-parser module. At the end, I run maven install locally to generate the jar package.
In my application, i replace mysql parser with maven system scope.
It really works.

Need to consider no aliases, I did not consider

Thank you very much. In my application, I will add alias default.

@strawhat925
Copy link

Thank you very much. In my application, I will add alias default.

ss only supports single table deletion, so you don't have much meaning with aliases.

@wowojyc
Copy link
Author

wowojyc commented Sep 4, 2019

Thank you very much. In my application, I will add alias default.

ss only supports single table deletion, so you don't have much meaning with aliases.
For example this sql,
delete Goods from goods AS Goods WHERE Goods.goods_id <= ?
My where condition is from the other sql parser engine, it's pattern is alias.column. So my delete sql must add alias as well. Otherwise, it will not run in mysql.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants