sql: reject qualified column names that match whole-row references - #174772
Open
Alignyx wants to merge 1 commit into
Open
sql: reject qualified column names that match whole-row references#174772Alignyx wants to merge 1 commit into
Alignyx wants to merge 1 commit into
Conversation
When column lookup failed, optbuilder tried to resolve the final name as a whole-row reference even if the original name had a table prefix. Consequently, SELECT t1.t1 FROM t1 returned the row of t1 when t1 only contained f1, and predicates using the same typo silently used that row. Restrict the whole-row fallback to unqualified references. Qualified missing columns retain the resolver's undefined-column error, while bare whole-row references and existing columns retain their current behavior. Add optbuilder regression cases for qualified references, aliases, predicates, multiple sources, CTEs, derived tables, and correlation. Fixes cockroachdb#120625 See also: cockroachdb#173881 Epic: none Release note (bug fix): Fixed a bug where a qualified reference to a nonexistent column, such as SELECT t1.t1 FROM t1, could silently return an entire table row. Such references now report an undefined-column error (SQLSTATE 42703). Unqualified whole-row references such as SELECT t1 FROM t1 and references to existing columns remain valid.
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SELECT t1.t1 FROM t1returned a whole-row record whent1contained onlyf1. A predicate such asWHERE t1.t1 IS NULLcould therefore silently test the row instead of reporting a missing column.Restrict optbuilder's whole-row fallback to unqualified references. Qualified missing columns now preserve the original undefined-column error (
42703); bare whole-row references and real columns retain their behavior. Add seven native optbuilder regression cases covering qualified names, aliases, predicates, multiple sources, CTEs, derived tables, and correlation.Fixes #120625.
Related PR: #173881 also addresses this issue. This PR contains an independently generated fix with regression coverage in optbuilder's data-driven tests.
Validation:
//pkg/sql/opt/optbuilder:optbuilder_testexecutable on this branch: 109 tests and subtests passed, with no skips.crlfmt -fast -tab 2andgit diff --checkpassed.The product fix and regression fixture were generated using DeepSeek, then reviewed and validated locally. Local native test binaries were built with Bazel using
--norun_validations; the./devwrapper refuses to run in this root execution environment. Full-repository generation and lint are not claimed here.Release note (bug fix): Fixed a bug where a qualified reference to a nonexistent column, such as
SELECT t1.t1 FROM t1, could silently return an entire table row. Such references now report an undefined-column error (SQLSTATE 42703). Unqualified whole-row references such asSELECT t1 FROM t1and references to existing columns remain valid.