Skip to content

opt: drop provably-non-null COALESCE operands#170858

Open
lohitkolluri wants to merge 1 commit into
cockroachdb:masterfrom
lohitkolluri:opt-coalesce-not-null
Open

opt: drop provably-non-null COALESCE operands#170858
lohitkolluri wants to merge 1 commit into
cockroachdb:masterfrom
lohitkolluri:opt-coalesce-not-null

Conversation

@lohitkolluri
Copy link
Copy Markdown

Fixes #103596

Uses NotNullCols to trim leading COALESCE args in Project and Select. Example: SELECT COALESCE(i, j) FROM ij with i NOT NULL no longer keeps the coalesce in the plan.

Test plan: bazel test //pkg/sql/opt/norm:norm_test --test_filter=TestNormRules

@lohitkolluri lohitkolluri requested a review from a team as a code owner May 24, 2026 07:28
@lohitkolluri lohitkolluri requested review from mw5h and removed request for a team May 24, 2026 07:28
@trunk-io
Copy link
Copy Markdown
Contributor

trunk-io Bot commented May 24, 2026

Merging to master in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@blathers-crl
Copy link
Copy Markdown

blathers-crl Bot commented May 24, 2026

Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR.

My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI.

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

@blathers-crl blathers-crl Bot added the O-community Originated from the community label May 24, 2026
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@lohitkolluri
Copy link
Copy Markdown
Author

Friendly ping for review when you have time.

Fixes #103596 — implements SimplifyCoalesceProject / SimplifyCoalesceSelect using NotNullCols as discussed in the issue thread.

Test plan (run locally):

bazel test //pkg/sql/opt/norm:norm_test --test_filter=TestNormRules

@mgartner — you outlined the approach on the issue; would appreciate your eyes on the norm rules / testdata if you have bandwidth.

@mw5h — thanks if you're already on this via code owners.

Happy to iterate on any feedback. If full CI needs a maintainer trigger for community PRs, please let me know what to run.

@blathers-crl
Copy link
Copy Markdown

blathers-crl Bot commented May 25, 2026

Detected infrastructure failure (matched: self-hosted runner lost communication with the server). Automatically rerunning failed jobs. (run link)

@blathers-crl
Copy link
Copy Markdown

blathers-crl Bot commented May 25, 2026

Thank you for updating your pull request.

Before a member of our team reviews your PR, I have some potential action items for you:

  • We notice you have more than one commit in your PR. We try break logical changes into separate commits, but commits such as "fix typo" or "address review commits" should be squashed into one commit and pushed with --force
  • Please ensure your git commit message contains a release note.
  • When CI has completed, please ensure no errors have appeared.

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

When a leading COALESCE argument is known non-null from the input's
NotNullCols, later arguments aren't needed. Starting with Project and
Select since scalar rules don't have relational props.

Fixes cockroachdb#103596

Release note: None
@lohitkolluri lohitkolluri force-pushed the opt-coalesce-not-null branch from 96f43bf to 164d43d Compare May 25, 2026 04:59
@blathers-crl
Copy link
Copy Markdown

blathers-crl Bot commented May 25, 2026

Thank you for updating your pull request.

My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-community Originated from the community

Projects

None yet

Development

Successfully merging this pull request may close these issues.

opt: eliminate all arguments of coalesce after the first argument that is guaranteed to be non-null

2 participants