Skip to content

Commit a4d0866

Browse files
introduce query rows limit to avoid OOM
1 parent 738cfc2 commit a4d0866

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

autoload/db.vim

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,13 @@ function! s:vim_job_close_cb(state, channel) abort
169169
endfunction
170170

171171
function! s:nvim_job_callback(lines, job_id, data, event) dict abort
172-
let a:lines[-1] .= a:data[0]
173-
call extend(a:lines, a:data[1:])
172+
if len(a:lines) < g:db_query_rows_limit
173+
let a:lines[-1] .= a:data[0]
174+
call extend(a:lines, a:data[1:])
175+
else
176+
call extend(a:lines, ['Query aborted: it exceeded the rows limit'])
177+
call s:job_stop(a:job_id)
178+
endif
174179
endfunction
175180

176181
function! s:job_run(cmd, on_finish, in_file) abort

doc/dadbod.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,5 +214,13 @@ the following variable to enable an experimental mode where dbext's
214214
configuration always mirrors Dadbod's default.
215215
>
216216
let g:dadbod_manage_dbext = 1
217+
<
218+
QUERY ROWS LIMIT *g:db_query_rows_limit*
219+
220+
In order to avoid out of memory when querying vast amounts of data from the
221+
database, dadbod will cancel queries exceeding the maximum number of rows that
222+
you set up in this variable. The default is 10,000 rows.
223+
>
224+
let g:db_query_rows_limit= 10000
217225
<
218226
vim:tw=78:et:ft=help:norl:

plugin/dadbod.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ if exists('g:loaded_dadbod') || &cp || v:version < 704
88
endif
99
let g:loaded_dadbod = 1
1010

11+
let g:db_query_rows_limit = get(g:, 'db_query_rows_limit', 10000)
12+
1113
call extend(g:, {'db_adapters': {}}, 'keep')
1214

1315
call extend(g:db_adapters, {

0 commit comments

Comments
 (0)