cockroachdb / cockroachdb/cockroach
sql: do not re-lookup columns in catalog during execbuilding (0.1% cpu)
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description

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
Assessment
This issue has not been assessed yet.