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

sql: chunk deletions #22991

Merged
merged 1 commit into from
Feb 23, 2018
Merged

sql: chunk deletions #22991

merged 1 commit into from
Feb 23, 2018

Conversation

tbg
Copy link
Member

@tbg tbg commented Feb 23, 2018

In the absence of a fast path deletion, DELETE would generate one
potentially giant batch and OOM the gateway node. This became obvious
quickly via heap profiling.

Added chunking of the deletions to tableDeleter. SQL folks may have
stronger opinions on how to achieve this, or a better idea of a
preexisting chunking mechanism that works more reliably. If nothing
else, this change serves as a prototype to fix #17921.

With this change, roachtest run drop works (as in, it doesn't
out-of-memory right away; the run takes a long time so I can't yet
confirm that it actually passes).

Release note (sql change): deleting many rows at once now consumes less
memory.

@tbg tbg requested review from a team February 23, 2018 06:14
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with nit

@@ -736,6 +737,15 @@ func (td *tableDeleter) init(txn *client.Txn, evalCtx *tree.EvalContext) error {
func (td *tableDeleter) row(
ctx context.Context, values tree.Datums, traceKV bool,
) (tree.Datums, error) {
if td.batchSize > 10000 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract the constant in the global scope and give it an explanatory comment.

@knz
Copy link
Contributor

knz commented Feb 23, 2018

if this merges into master, please also cherry-pick into 2.0

@petermattis
Copy link
Collaborator

:lgtm:


Review status: 0 of 1 files reviewed at latest revision, 1 unresolved discussion, all commit checks successful.


pkg/sql/tablewriter.go, line 740 at r1 (raw file):

Previously, knz (kena) wrote…

extract the constant in the global scope and give it an explanatory comment.

Not sure the constant needs to be in the global scope given it is only accessed here, but 👍 on making a constant.

Also, shouldn't this be >=? Otherwise you'll be running batches of 10001 rows, which while not wrong, offends my sense of propriety.


Comments from Reviewable

In the absence of a fast path deletion, `DELETE` would generate one
potentially giant batch and OOM the gateway node. This became obvious
quickly via heap profiling.

Added chunking of the deletions to `tableDeleter`. SQL folks may have
stronger opinions on how to achieve this, or a better idea of a
preexisting chunking mechanism that works more reliably. If nothing
else, this change serves as a prototype to fix cockroachdb#17921.

With this change, `roachtest run drop` works (as in, it doesn't
out-of-memory right away; the run takes a long time so I can't yet
confirm that it actually passes).

Release note (sql change): deleting many rows at once now consumes less
memory.
@tbg tbg merged commit 494b091 into cockroachdb:master Feb 23, 2018
@tbg tbg deleted the delete-oom branch February 23, 2018 17:15
@spencerkimball
Copy link
Member

@tschottdorf (+@knz, @andreimatei) when I ran this locally, I noticed that we seem to be scanning and buffering the entire set of rows to be deleted. It seems with this change that the total memory footprint should not soar into the GiBs. Why doesn't SQL consume rows from the scanner in a streaming fashion to feed to the table writer?

@andreimatei
Copy link
Contributor

andreimatei commented Feb 24, 2018 via email

@tbg tbg restored the delete-oom branch April 16, 2018 15:23
@tbg tbg deleted the delete-oom branch May 8, 2018 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DELETE FROM ... [returning nothing] crashes a node
6 participants