Skip to content

Commit ebfcca9

Browse files
authored
Merge pull request #365 from mk3008/364-supports-parsing-of-large-values-queries
Supports parsing of large value queries
2 parents f0c3cdc + bdfb1f4 commit ebfcca9

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

src/Carbunql/CommandTextBuilder.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@ public string Execute(IEnumerable<Token> tokens)
7575
{
7676
Logger?.Invoke($"decrement indent and line break on before : {t.Text}");
7777
Level = lv;
78-
79-
//NOTE:
80-
//Remembering indentation has a big impact on performance.
81-
//Improves performance by deleting the cache of indentation levels when the indentation is no longer present.
82-
if (Level == 0) IndentLevels.Clear();
8378
sb.Append(GetLineBreakText());
8479
}
8580
else
@@ -138,7 +133,16 @@ private string GetTokenTextCore(Token token)
138133

139134
private string GetLineBreakText()
140135
{
136+
//init previous token
141137
PrevToken = null;
138+
139+
// NOTE:
140+
// For performance improvement, remove unnecessary indent information
141+
// However, keep one for the starting position of brackets
142+
var startIndent = IndentLevels.Where(x => x.Level == Level).FirstOrDefault();
143+
IndentLevels.RemoveAll(x => Level <= x.Level && x != startIndent);
144+
145+
//line break
142146
if (!SpacerCache.ContainsKey(Level))
143147
{
144148
SpacerCache[Level] = (Level * 4).ToSpaceString();

test/Carbunql.Analysis.Test/StackOverFlowTest.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ public StackOverFlowTest(ITestOutputHelper output)
1616
public void Union_50k()
1717
{
1818
var sb = new StringBuilder();
19-
sb.Append("select 1");
19+
sb.Append("select 1,2,3,4,5,6,7,8,9,10");
2020
for (int i = 0; i < 50000; i++)
2121
{
22-
sb.Append(" union all select 1");
22+
sb.Append(" union all select 1,2,3,4,5,6,7,8,9,10");
2323
}
2424

2525
var exception = Record.Exception(() =>
@@ -32,4 +32,25 @@ public void Union_50k()
3232

3333
Assert.Null(exception);
3434
}
35+
36+
[Fact]
37+
public void Values_50k()
38+
{
39+
var sb = new StringBuilder();
40+
sb.Append("values (1,2,3,4,5,6,7,8,9,10)");
41+
for (int i = 0; i < 50000; i++)
42+
{
43+
sb.Append(", (1,2,3,4,5,6,7,8,9,10)");
44+
}
45+
46+
var exception = Record.Exception(() =>
47+
{
48+
var vq = new ValuesQuery(sb.ToString());
49+
vq.GetTokens();
50+
51+
Output.WriteLine(vq.ToText());
52+
});
53+
54+
Assert.Null(exception);
55+
}
3556
}

0 commit comments

Comments
 (0)