Skip to content

Conversation

@ruslandoga
Copy link
Contributor

@ruslandoga ruslandoga commented Nov 29, 2022

👋

This makes Repo.stream a bit faster.

# although `max_rows: 1` now adds the overhead of `multi_step` compared to prev approach using `step`
iex> :timer.tc fn -> Repo.transaction(fn -> Repo.stream(Word, max_rows: 1) |> Enum.take(500) end); :ok end
{168632, :ok}

iex> :timer.tc fn -> Repo.transaction(fn -> Repo.stream(Word, max_rows: 100) |> Enum.take(500) end); :ok end
{63922, :ok}

@ruslandoga
Copy link
Contributor Author

ruslandoga commented Nov 29, 2022

BTW, I'm getting logs spammed when the stream is being fetched. Is this expected? I guess it comes from Ecto so there is little we can do about it.

iex(4)> :timer.tc fn -> Repo.transaction(fn -> Repo.stream(Word, max_rows: 100) |> Enum.take(500) end); :ok end
[debug] QUERY OK db=0.3ms idle=1289.1ms
begin []
↳ anonymous fn/4 in :elixir.eval_external_handler/1, at: src/elixir.erl:298
[debug] QUERY OK source="words" db=0.2ms
SELECT w0."user_id", w0."word", w0."pronunciation", w0."senses", w0."inserted_at", w0."updated_at" FROM "words" AS w0 []
↳ anonymous fn/4 in :elixir.eval_external_handler/1, at: src/elixir.erl:298
[debug] QUERY OK source="words" db=1.3ms
SELECT w0."user_id", w0."word", w0."pronunciation", w0."senses", w0."inserted_at", w0."updated_at" FROM "words" AS w0 []
↳ anonymous fn/4 in :elixir.eval_external_handler/1, at: src/elixir.erl:298
[debug] QUERY OK source="words" db=1.2ms
SELECT w0."user_id", w0."word", w0."pronunciation", w0."senses", w0."inserted_at", w0."updated_at" FROM "words" AS w0 []
↳ anonymous fn/4 in :elixir.eval_external_handler/1, at: src/elixir.erl:298
[debug] QUERY OK source="words" db=0.4ms
SELECT w0."user_id", w0."word", w0."pronunciation", w0."senses", w0."inserted_at", w0."updated_at" FROM "words" AS w0 []
↳ anonymous fn/4 in :elixir.eval_external_handler/1, at: src/elixir.erl:298
[debug] QUERY OK source="words" db=0.3ms
SELECT w0."user_id", w0."word", w0."pronunciation", w0."senses", w0."inserted_at", w0."updated_at" FROM "words" AS w0 []
↳ anonymous fn/4 in :elixir.eval_external_handler/1, at: src/elixir.erl:298
[debug] QUERY OK source="words" db=0.4ms
SELECT w0."user_id", w0."word", w0."pronunciation", w0."senses", w0."inserted_at", w0."updated_at" FROM "words" AS w0 []
↳ anonymous fn/4 in :elixir.eval_external_handler/1, at: src/elixir.erl:298
[debug] QUERY OK source="words" db=0.0ms
SELECT w0."user_id", w0."word", w0."pronunciation", w0."senses", w0."inserted_at", w0."updated_at" FROM "words" AS w0 []
↳ anonymous fn/4 in :elixir.eval_external_handler/1, at: src/elixir.erl:298
[debug] QUERY OK db=0.0ms
commit []
↳ anonymous fn/4 in :elixir.eval_external_handler/1, at: src/elixir.erl:298
{63922, :ok}

@ruslandoga ruslandoga changed the title use multi_select in stream use multi_step in stream Nov 29, 2022
@warmwaffles
Copy link
Member

Oh I didn't even realize max_rows was an existing option. We should deprecate the chunk_size and emit a warning if it is used.

@warmwaffles
Copy link
Member

Also I wonder why I didn't use multi_step in the handle_fetch call.

@warmwaffles
Copy link
Member

@ruslandoga I'll get to this soon. I think this is a good change.

@warmwaffles warmwaffles self-assigned this Dec 5, 2022
@warmwaffles warmwaffles merged commit adbe5a2 into elixir-sqlite:main Dec 6, 2022
@ruslandoga ruslandoga deleted the use-multi-step-in-stream branch December 7, 2022 02:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants