cockroachdb / cockroachdb/cockroach

sql: do not re-lookup columns in catalog during execbuilding (0.1% cpu)

Open
#137,796 0 comments 0 reactions 0 assignees View on GitHub
C-enhancement o-perf-efficiency T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

![image](https://github.com/user-attachments/assets/415ca5ad-7f83-43dc-a91d-130de38fcd8f)

There's some unnecessary work done above to lookup each column in a scan (and some other operators like lookup joins) by their stable ID. There should be no reason to do this—the optimizer should already have access to all of the necessary column information.

I looked into making this change and there was some spaghetti to untangle. Some ideas:

1. `execbuilder` can build the `ResultColumns` slice, rather than building them from the `[]catalog.Column` slice. This breaks one dependency on the catalog lookups.
2. I think we'll need `execbuilder` to also pass along the column IDs in a separate slice for cases like this: https://github.com/cockroachdb/cockroach/blob/238573145b109a905997237dcd97a046cec399d9/pkg/sql/distsql_physical_planner.go#L2143-L2155
3. We might also need `execbuilder` to pass along the column ordinals for this case: https://github.com/cockroachdb/cockroach/blob/238573145b109a905997237dcd97a046cec399d9/pkg/sql/distsql_physical_planner.go#L3363

Jira issue: CRDB-45745

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.