Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce query rows limit to avoid OOM #151

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions autoload/db.vim
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,22 @@ function! s:vim_job_close_cb(state, channel) abort
endfunction

function! s:nvim_job_callback(lines, job_id, data, event) dict abort
let a:lines[-1] .= a:data[0]
call extend(a:lines, a:data[1:])
if len(a:lines) < g:db_query_rows_limit
let a:lines[-1] .= a:data[0]
call extend(a:lines, a:data[1:])
else
" remove the last line that was written.
" since we're killing the process, it could have been stopped in the
" middle of a line. I have seen the case that it was stopped in the middle
" of a multibyte unicode glyph, resulting in invalid utf8 for the file,
" causing a fallback to latin1 encoding in vim and bad display.
" side-effect: this could be called multiple times as killing the process
" won't be instantaneous, this ensures the 'query aborted' message is
" printed only once.
call remove(a:lines, -1)
call extend(a:lines, ['Query aborted: it exceeded the rows limit'])
call s:job_stop(a:job_id)
endif
endfunction

function! s:job_run(cmd, on_finish, in_file) abort
Expand Down
8 changes: 8 additions & 0 deletions doc/dadbod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,13 @@ the following variable to enable an experimental mode where dbext's
configuration always mirrors Dadbod's default.
>
let g:dadbod_manage_dbext = 1
<
QUERY ROWS LIMIT *g:db_query_rows_limit*

In order to avoid out of memory when querying vast amounts of data from the
database, dadbod will cancel queries exceeding the maximum number of rows that
you set up in this variable. The default is 10,000 rows.
>
let g:db_query_rows_limit= 10000
<
vim:tw=78:et:ft=help:norl:
2 changes: 2 additions & 0 deletions plugin/dadbod.vim
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ if exists('g:loaded_dadbod') || &cp || v:version < 704
endif
let g:loaded_dadbod = 1

let g:db_query_rows_limit = get(g:, 'db_query_rows_limit', 10000)

call extend(g:, {'db_adapters': {}}, 'keep')

call extend(g:db_adapters, {
Expand Down