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: avoid an allocation when running subqueries in some cases #126509

Merged
merged 1 commit into from
Jul 2, 2024

Conversation

yuzefovich
Copy link
Member

This commit reuses recently added DatumAlloc to the planner when creating the tuple that is the result of a subquery evaluation in order to reduce allocations. In a profile obtained from a customer I observed this allocation to be about 2% of all allocated objects.

Epic: None

Release note: None

@yuzefovich yuzefovich requested a review from mgartner July 1, 2024 18:23
@yuzefovich yuzefovich requested a review from a team as a code owner July 1, 2024 18:23
Copy link

blathers-crl bot commented Jul 1, 2024

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

This commit reuses recently added `DatumAlloc` to the planner when
creating the tuple that is the result of a subquery evaluation in order
to reduce allocations. In a profile obtained from a customer I observed
this allocation to be about 2% of all allocated objects.

Release note: None
Copy link
Collaborator

@mgartner mgartner left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 3 of 3 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @yuzefovich)


pkg/sql/distsql_running.go line 1885 at r1 (raw file):

				toAppend = row[0]
			} else {
				toAppend = planner.datumAlloc.NewDTuple(tree.DTuple{D: row})

So this will reduce allocations as long as subqueries return more than one row, correct?

Copy link
Member Author

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

TFTR!

bors r+

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @mgartner)


pkg/sql/distsql_running.go line 1885 at r1 (raw file):

Previously, mgartner (Marcus Gartner) wrote…

So this will reduce allocations as long as subqueries return more than one row, correct?

IIUC this will reduce allocations when multiple rows could be returned, even if one is actually returned, in exec.SubqueryAnyRows / rowexec.SubqueryExecModeAllRowsNormalized execution mode.

@craig craig bot merged commit fa8149f into cockroachdb:master Jul 2, 2024
22 checks passed
@yuzefovich yuzefovich deleted the subquery-alloc branch July 3, 2024 03:59
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.

3 participants