Skip to content

Commit

Permalink
introduce query rows limit to avoid OOM
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanueltouzery committed Dec 8, 2023
1 parent 738cfc2 commit a4d0866
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
9 changes: 7 additions & 2 deletions autoload/db.vim
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,13 @@ 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
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 @@ -214,5 +214,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

0 comments on commit a4d0866

Please sign in to comment.