Skip to content

Commit b2c6097

Browse files
committed
1 parent 4f925c5 commit b2c6097

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/test/java/net/sf/jsqlparser/statement/select/NestedBracketsPerformanceTest.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
*/
2323
public class NestedBracketsPerformanceTest {
2424

25-
private static final int ITERATIONS_20 = 20;
26-
2725
@Test
2826
public void testIssue766() throws JSQLParserException {
2927
assertSqlCanBeParsedAndDeparsed("SELECT concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat('1','2'),'3'),'4'),'5'),'6'),'7'),'8'),'9'),'10'),'11'),'12'),'13'),'14'),'15'),'16'),'17'),'18'),'19'),'20'),'21'),col1 FROM tbl t1", true);
@@ -50,6 +48,18 @@ public void testIssue856() throws JSQLParserException {
5048
String sql = "SELECT " + buildRecursiveBracketExpression("if(month(today()) = 3, sum(\"Table5\".\"Month 002\"), $1)", "0", 5) + " FROM mytbl";
5149
assertSqlCanBeParsedAndDeparsed(sql);
5250
}
51+
52+
@Test
53+
public void testRecursiveBracketExpressionIssue1019() {
54+
assertEquals("IF(1=1, 1, 2)", buildRecursiveBracketExpression("IF(1=1, $1, 2)", "1", 0));
55+
assertEquals("IF(1=1, IF(1=1, 1, 2), 2)", buildRecursiveBracketExpression("IF(1=1, $1, 2)", "1", 1));
56+
assertEquals("IF(1=1, IF(1=1, IF(1=1, 1, 2), 2), 2)", buildRecursiveBracketExpression("IF(1=1, $1, 2)", "1", 2));
57+
}
58+
59+
@Test
60+
public void testRecursiveBracketExpressionIssue1019_2() throws JSQLParserException {
61+
doIncreaseOfParseTimeTesting("IF(1=1, $1, 2)", "1", 10);
62+
}
5363

5464
/**
5565
* Try to avoid or border exceptionally big parsing time increments by adding more bracket constructs.
@@ -58,10 +68,14 @@ public void testIssue856() throws JSQLParserException {
5868
*/
5969
@Test
6070
public void testIncreaseOfParseTime() throws JSQLParserException {
71+
doIncreaseOfParseTimeTesting("concat($1,'B')", "'A'", 20);
72+
}
73+
74+
private void doIncreaseOfParseTimeTesting(String template, String finalExpression, int maxDepth) throws JSQLParserException {
6175
long oldDurationTime = 1000;
6276
int countProblematic = 0;
63-
for (int i = 0; i < ITERATIONS_20; i++) {
64-
String sql = "SELECT " + buildRecursiveBracketExpression("concat($1,'B')", "'A'", i) + " FROM mytbl";
77+
for (int i = 0; i < maxDepth; i++) {
78+
String sql = "SELECT " + buildRecursiveBracketExpression(template, finalExpression, i) + " FROM mytbl";
6579
long startTime = System.currentTimeMillis();
6680
assertSqlCanBeParsedAndDeparsed(sql, true);
6781
long durationTime = System.currentTimeMillis() - startTime;
@@ -86,7 +100,7 @@ public void testRecursiveBracketExpression() {
86100
assertEquals("concat(concat('A','B'),'B')", buildRecursiveBracketExpression("concat($1,'B')", "'A'", 1));
87101
assertEquals("concat(concat(concat('A','B'),'B'),'B')", buildRecursiveBracketExpression("concat($1,'B')", "'A'", 2));
88102
}
89-
103+
90104
private String buildRecursiveBracketExpression(String template, String finalExpression, int depth) {
91105
if (depth == 0) {
92106
return template.replace("$1", finalExpression);

0 commit comments

Comments
 (0)