SQLite Forum

SQLite3.exe fails to handle huge multi-line-comment
> With above change, it's still O n^2. Dunno why, yet.

My experiment was with non-semicolon-terminated comments. So, regarding [Richard's post](https://sqlite.org/forum/forumpost/9f1fa87d28), (about calls to line_contains_semicolon() contributing to the O n^2 behavior), that clearly makes a difference, but less than one might imagine.

To convert the reallocation calls to O log(n), my favored computation is:<code>
      nAlloc = nSql+(nSql>>1)+nLine+100;
</code>. With that in place, the execution time remains O n^2 whether the commented lines end with ';' or not. With my test<sup><b>a</b></sup>, screen-scrape of which is<code>
> timer \`big_comment 20000 "select null;" | sqlite3\`
 ... Elapsed: 0:00:04.422
> timer \`big_comment 40000 "select null;" | sqlite3\`
 ... Elapsed: 0:00:17.143
> timer \`big_comment 20000 "select null." | sqlite3\`
 ... Elapsed: 0:00:02.619
> timer \`big_comment 40000 "select null." | sqlite3\`
 ... Elapsed: 0:00:09.429
</code>, I see that the O scale factor changes by about 2x with trailing ';', but the elapsed time clearly varies with n^2.

I intend to investigate why execution time remains O n^2 when I can see no code path explaining such growth. Curiously, the realloc() calls play a very small role. More later.


a. The big_comment script reads:<code>
if (@ARGV \< 2){
    print stderr "Args are comment_line_count and comment_line_content.\\n";
    exit 1;
$nc = shift(@ARGV) + 0;
$sql = shift(@ARGV);
print \<\<\'\_\';
.print Starting big SQL comment ...
while ($nc-- \> 0){
    print $sql, "\\n";
print \<\<\'\_\';
.print End big SQL comment and run.