You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@mpcjanssen What version of ecto and sqlite_ecto2 are you using? Is it possible you have no data in your table? I am able to stream using very similar code to what you posted.
@ConnorRigby I am sure I have data in the table (2 million records). I will get a timeout when executing the query. So I think the sqlite_ecto adapter tries to get the full result first and then converts it to a stream. Before the full result (2 million records) is retrieved, the request times out.
I also have done some investigation and it seems that the sqlitex binding doesn't actually support cursors or row by row results.
More details:
:sqlite_ecto2, "2.2.4
:sqlitex, "1.4.2"
Actual error when doing the query:
Interactive Elixir (1.7.2)-pressCtrl+Ctoexit(typeh() ENTER for help)iex(1)>AppModule.query12:46:09.590[error] Sqlite.DbConnection.Protocol(#PID<0.277.0>) disconnected: ** (DBConnection.ConnectionError) client #PID<0.278.0> timed out because it checked out the connection for longer than 15000ms**(MatchError)nomatchofrighthandsidevalue: {:error,%Sqlite.DbConnection.Error{connection_id: nil,message: "Disconnected",sqlite: nil}}(sqlite_ecto2) lib/sqlite_db_connection/protocol.ex:206: Sqlite.DbConnection.Protocol.handle_transaction/3(db_connection) lib/db_connection.ex:1343: DBConnection.handle/5(db_connection) lib/db_connection.ex:1329: DBConnection.conclude_meter/6(db_connection) lib/db_connection.ex:1207: DBConnection.run_begin/3(db_connection) lib/db_connection.ex:798: DBConnection.transaction/3
Okay i understand now. I'll have to read how Postgres implements streaming. Sqlite does support cursors if i remember correctly, so we should be able to implement something. For what it's worth you can set pool_timeout: :infinity, but as you've noticed, you are not really streaming at that point, you are loading every record.
Activity
ConnorRigby commentedon Aug 15, 2018
Interesting. I've not used
streambefore. I will look into this.ConnorRigby commentedon Aug 22, 2018
@mpcjanssen What version of ecto and sqlite_ecto2 are you using? Is it possible you have no data in your table? I am able to stream using very similar code to what you posted.
mpcjanssen commentedon Aug 22, 2018
@ConnorRigby I am sure I have data in the table (2 million records). I will get a timeout when executing the query. So I think the sqlite_ecto adapter tries to get the full result first and then converts it to a stream. Before the full result (2 million records) is retrieved, the request times out.
When using Postgresql a database cursor is used instead so the results are returned one by one (see https://hexdocs.pm/postgrex/Postgrex.html#stream/4).
I also have done some investigation and it seems that the sqlitex binding doesn't actually support cursors or row by row results.
More details:
Actual error when doing the query:
ConnorRigby commentedon Aug 22, 2018
Okay i understand now. I'll have to read how Postgres implements streaming. Sqlite does support cursors if i remember correctly, so we should be able to implement something. For what it's worth you can set
pool_timeout: :infinity, but as you've noticed, you are not really streaming at that point, you are loading every record.ConnorRigby commentedon Aug 22, 2018
Also for what it's worth here is the responsible source:
https://github.com/Sqlite-Ecto/sqlite_ecto2/blob/master/lib/sqlite_db_connection/stream.ex#L7-L23
You called it. We are just trying to execute the entire query.
ConnorRigby commentedon Aug 22, 2018
And for reference here is the postgres implementation.