Closed ghennequin closed 6 years ago
I have the same problem but fails for ~24000 rows. It would be great to have a way to fix this! Thank you!
Also, note that this issue does not occur when using Sqlite3
directly, so it seems specific to sqlexpr
.
On Sun, Mar 04, 2018 at 04:40:42PM +0000, Guillaume Hennequin wrote:
Also, note that this issue does not occur when using
Sqlite3
directly, so it seems specific tosqlexpr
.
I have been able to reproduce the issue. It seems the loop that iterates over the rows becomes non-tail-recursive when the Sqlexpr_sqlite.Make functor is applied to the identity monad Sqlexpr_concurrency.Id in a way that is not syntactically obvious. I suspect that this is caused by a non-tail-recursive (in the Id case) function call like backtrace_bind being inserted by the lwt ppx extension, but I haven't established this for sure yet.
In the meantime, you could try to use the non-blocking flavor Sqlexpr_sqlite_lwt or Sqlexpr_sqlite.Make(Sqlexpr_concurrency.Lwt), which do not exhibit the issue. The following works:
$ cat sqlfaillwt.ml
module S = Sqlexpr_sqlite.Make(Sqlexpr_concurrency.Lwt)
module Sqlexpr = S
let run () =
let db = S.open_db "db.sqlite" in
(* create simple but large table *)
let%lwt () = S.execute db [%sql "CREATE TABLE test (x FLOAT)"] in
let%lwt () =
S.transaction db
(fun db ->
for%lwt i=1 to 100000 do
let%lwt _ =
S.insert db [%sqlc "INSERT INTO test(x) VALUES(%f)"] @@ Random.float 1.
in
Lwt.return_unit
done) in
let%lwt result = S.select db [%sqlc "SELECT @f{x} FROM test"] in
Printf.printf "Read %d rows\n" @@ List.length result;
Lwt.return @@ S.close_db db
let () = Lwt_main.run @@ run ()
$ ocamlfind ocamlopt -package sqlexpr,sqlexpr.ppx sqlfaillwt.ml -o sqlfaillwt -linkpkg -thread
$ ./sqlfaillwt
Read 100000 rows
-- Mauricio Fernández
Thanks @mfp ! Looking forward to a fix for the Sqlexpr_concurrency.Id
case.
Fixed in 1d08315b5e0. The let%lwt syntax was wrapping each iteration with multiple backtrace_bind
calls, which broke tail-recursion with Id concurrency. The testcase runs OK now (tested on 4.02.3 and 4.05).
Thanks @mfp !
This fails (stack overflow):
On my computer, it won't fail if I limit the query to return < 65202 rows. Any idea how to fix this? Thank you!