Skip to content

Commit

Permalink
cli/sql: put a limit on history size
Browse files Browse the repository at this point in the history
Previously, there was no limit. Some users managed to make their
history run into megabyte-size, despite de-duplication, which was
causing slowness.

This patch fixes it by adding a limit of 1000 entries. Sufficiently
large to not be inconvenient, but sufficiently small that it prevents
the history file from growing abnormally large.

Release note (cli change): The interactive SQL shell now retains a
maximum of 1000 entries. There was no limit previously.
  • Loading branch information
knz committed Sep 19, 2022
1 parent 595749c commit bcba12c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/cli/clisqlshell/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -2158,8 +2158,18 @@ func (c *cliState) configurePreShellDefaults(
// memory when e.g. piping a large SQL script through the
// command-line client.

// maxHistEntries is the maximum number of entries to
// preserve. Note that libedit de-duplicates entries under the
// hood. We expect that folk entering SQL in a shell will often
// reuse the same queries over time, so we don't expect this limit
// to ever be reached in practice, or to be an annoyance to
// anyone. We do prefer a limit however (as opposed to no limit at
// all), to prevent abnormal situation where a history runs into
// megabytes and starts slowing down the shell.
const maxHistEntries = 1000

c.ins.SetCompleter(c)
if err := c.ins.UseHistory(-1 /*maxEntries*/, true /*dedup*/); err != nil {
if err := c.ins.UseHistory(maxHistEntries, true /*dedup*/); err != nil {
fmt.Fprintf(c.iCtx.stderr, "warning: cannot enable history: %v\n ", err)
} else {
homeDir, err := envutil.HomeDir()
Expand Down

0 comments on commit bcba12c

Please sign in to comment.