-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Share blank nodes #3418
base: master
Are you sure you want to change the base?
Share blank nodes #3418
Conversation
Thank you for the PR, @nieqiurong ! I really liked the effect of your original PR #3349 which significantly reduces the number of After evaluating each I think, for consistency, Cc: @epochcoder |
If empty rows are removed, it can lead to some extreme cases. @Test
void test(){
var script = """
<script>
select * from `user` -- use sql comment
<where>
<if test="true">1=1 -- test</if>
<if test="true">and 1=1</if>
and 2=2
</where>
</script>
""";
var languageDriver = new XMLLanguageDriver();
var sqlSource = languageDriver.createSqlSource(new Configuration(), script, Object.class);
System.out.println(sqlSource.getBoundSql(null).getSql());
} For example, in this comment case, - -test is a comment, and if no newline character exists, the following condition is connected, resulting in the later execution condition to be treated as a comment -- error sql
select * from `user` -- use sql comment
WHERE 1=1 -- test and 1=1
and 2=2
--
select * from `user` -- use sql comment
WHERE 1=1 -- test
and 1=1
and 2=2 |
Can we also expose the shrinkWhitespacesInSql processing method to the users' customization? System.out.println(SqlSourceBuilder.removeExtraWhitespaces("select * from `user` -- use sql comment\n" +
" WHERE 1=1 -- test\n" +
" and 1=1\n" +
" and 2=2"));
// select * from `user` -- use sql comment WHERE 1=1 -- test and 1=1 and 2=2 |
Thanks for the comment, @nieqiurong ! In general, you should avoid single line comments when you use JDBC. Still, it may be better not to surprise users. |
@harawata Thank you for your reply. Yes, if treated by removing new lines and adding blank spaces, it will cause some incompatibilities. <script>
select * from `user`
<where>
<if test="true">1=1</if><if test="true">and 1=1</if>
and 2=2
</where>
<if test="true">and 3=3</if><if test="true">and 4=4</if>
</script> select * from `user`
WHERE 1=1 and 1=1
and 2=2 and 3=3 and 4=4
-- old version
select * from `user`
WHERE 1=1and 1=1
and 2=2
and 3=3 and 4=4 Maybe there are better options for improvement, but I haven't found it yet. |
In the memory analysis, it was found that there were some blank nodes in mybatis,
Some are line breaks followed by blank strings, which are considered as blank nodes. However, the space occupied by these nodes is meaningless, and it is possible to cache these blank nodes during parsing and only retain one instance
example:
For example, when parsing the sample script, four line break tags will be created. This is just a simple example, and we will use more dynamic tags in the project.
This modification will not change the original script content.