From a4d0866716a314def5b55095cf3ba1a971e80783 Mon Sep 17 00:00:00 2001 From: Emmanuel Touzery Date: Fri, 8 Dec 2023 22:31:59 +0100 Subject: [PATCH] introduce query rows limit to avoid OOM --- autoload/db.vim | 9 +++++++-- doc/dadbod.txt | 8 ++++++++ plugin/dadbod.vim | 2 ++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/autoload/db.vim b/autoload/db.vim index 026bf9e..e8326db 100644 --- a/autoload/db.vim +++ b/autoload/db.vim @@ -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 diff --git a/doc/dadbod.txt b/doc/dadbod.txt index 3850138..8a4a799 100644 --- a/doc/dadbod.txt +++ b/doc/dadbod.txt @@ -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: diff --git a/plugin/dadbod.vim b/plugin/dadbod.vim index 1f45fd5..beadc05 100644 --- a/plugin/dadbod.vim +++ b/plugin/dadbod.vim @@ -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, {