-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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: make database, table, view and columns lookups properly case-sensitive #16884
Conversation
4f9bd2d
to
1ba4ad7
Compare
1ba4ad7
to
5f50cb9
Compare
Added the part for column names too. |
8cda01e
to
87da655
Compare
Thanks so much for your hard work on this! Aside from some nits (noted below), my main concern is that there are no new/altered tests concerned with Unicode normalization. Also, has management approved this behavior change? Reviewed 38 of 48 files at r1, 56 of 56 files at r2. pkg/ccl/sqlccl/targets.go, line 35 at r2 (raw file):
Can you change the type of the map instead of converting everywhere? pkg/sql/alter_table.go, line 89 at r2 (raw file):
Could we change the signature of pkg/sql/data_source.go, line 677 at r2 (raw file):
Is this a change that should be made more systematically? pkg/sql/drop.go, line 433 at r2 (raw file):
Perhaps rename to pkg/sql/table.go, line 388 at r2 (raw file):
I vaguely remember that the parser accepts a different syntax for specifying tables by ID? Perhaps I'm confused. pkg/sql/logictest/testdata/logic_test/case_sensitive_names, line 36 at r2 (raw file):
Is there a good reason that this one is not like the others? pkg/sql/logictest/testdata/logic_test/select, line 173 at r2 (raw file):
Are the quotes still needed? Comments from Reviewable |
4384026
to
5c193f4
Compare
@bdarnell said "ok as long as it brings us closer to pg compatibility". Review status: 69 of 99 files reviewed at latest revision, 7 unresolved discussions. pkg/ccl/sqlccl/targets.go, line 35 at r2 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
Not comfortable about that: there are more uses below which do not convert. pkg/sql/alter_table.go, line 89 at r2 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
Done. pkg/sql/data_source.go, line 677 at r2 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
Done. pkg/sql/drop.go, line 433 at r2 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
Done. pkg/sql/table.go, line 388 at r2 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
Not yet. This feature will only come when #15388 is merged (or the underlying commit which adds the syntax). pkg/sql/logictest/testdata/logic_test/case_sensitive_names, line 36 at r2 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
Fixed. pkg/sql/logictest/testdata/logic_test/select, line 173 at r2 (raw file): Previously, eisenstatdavid (David Eisenstat) wrote…
they are not needed, it's only a smoke test to check that the double quote syntax is allowed also in expression context. Comments from Reviewable |
5c193f4
to
4009728
Compare
a2dcf44
to
4240905
Compare
Review status: 69 of 100 files reviewed at latest revision, 7 unresolved discussions. pkg/sql/table.go, line 388 at r2 (raw file): Previously, knz (kena) wrote…
Scratch that, actually we supported the feature already. Changed. Comments from Reviewable |
4240905
to
d9092ed
Compare
Added a unicode normalization test as requested. |
Reviewed 31 of 31 files at r3. Comments from Reviewable |
d9092ed
to
4cfcde8
Compare
- use the same word "relation" for tables and views for permission errors and "descriptor does not exist" errors, for consistency with the existing "already exists" message that already uses the word "relation". - ensure that names containing special characters are not double-quoted in the error message. - use pg error codes more often.
An earlier change introduced pre-normalization of descriptor names upon descriptor creation, thereby aiming for two goals: - normalize descriptor names upon creation of the descriptor, so as to avoid the time overhead of re-normalizing the name on every access; - creating a distinction, like one exists in postgres, between descriptors created with the syntax `"A"` and the syntax `A` - the latter is normalized, the former is not. This makes case sensitivity opt-in for client applications. Unfortunately, prior to this patch, most SQL statements also used a case-insensitive *lookup* of database/table/view/column names from storage, preventing the aforementioned benefits. This patch completes the earlier change by making name lookups case-sensitive. An exhaustive test is modified/introduced to confirm that the change is invisible to most common use cases -- i.e. as long as client apps were not double quoting their identifiers. Fixes cockroachdb#8862. Fixes cockroachdb#16858.
4cfcde8
to
9926f25
Compare
TFYRs! |
There was a time in the past where CockroachDB was (or attempted to be) case-insensitive about identifiers, and this was a source of incompatibility with PostgreSQL. This incompatibility was corrected for object (table/view/database/index) names and column names in cockroachdb#16884, but somehow I forgot about function names in that patch. As a result, CockroachDB continued to consider `upper()` and `"UPPER"()` the same thing, whereas most definitely only the former is valid. This patch corrects the issue and simplifies the code accordingly. Release note (sql change): CockroachDB now properly rejects incorrectly cased SQL function names with an error.
There was a time in the past where CockroachDB was (or attempted to be) case-insensitive about identifiers, and this was a source of incompatibility with PostgreSQL. This incompatibility was corrected for object (table/view/database/index) names and column names in #16884, but somehow I forgot about function names in that patch. As a result, CockroachDB continued to consider `upper()` and `"UPPER"()` the same thing, whereas most definitely only the former is valid. This patch corrects the issue and simplifies the code accordingly. Release note (sql change): CockroachDB now properly rejects incorrectly cased SQL function names with an error.
There was a time in the past where CockroachDB was (or attempted to be) case-insensitive about identifiers, and this was a source of incompatibility with PostgreSQL. This incompatibility was corrected for object (table/view/database/index) names and column names in cockroachdb#16884, but somehow I forgot about function names in that patch. As a result, CockroachDB continued to consider `upper()` and `"UPPER"()` the same thing, whereas most definitely only the former is valid. This patch corrects the issue and simplifies the code accordingly. Release note (sql change): CockroachDB now properly rejects incorrectly cased SQL function names with an error.
sql: sanitize the production of error message for tables/views
use the same word "relation" for tables and views for permission
errors and "descriptor does not exist" errors, for consistency with
the existing "already exists" message that already uses the word
"relation".
ensure that names containing special characters are not
doubly quoted in the error message.
sql: make table and view lookups properly case-sensitive
An earlier change introduced pre-normalization of descriptor names
upon descriptor creation, thereby aiming for two goals:
normalize descriptor names upon creation of the descriptor, so as to
avoid the time overhead of re-normalizing the name on every access;
creating a distinction, like one exists in postgres, between
descriptors created with the syntax
"A"
and the syntaxA
- thelatter is normalized, the former is not. This makes case sensitivity
opt-in for client applications.
Unfortunately, prior to this patch, most SQL statements also used a
case-insensitive lookup of database/table/view/column names from
storage, preventing the aforementioned benefits.
This patch completes the earlier change by making name lookups
case-sensitive. An exhaustive set of tests is modified/introduced to confirm
that the change is invisible to most common use cases -- i.e. as long
as client apps were not double quoting their identifiers.
Fixes #8862.
Fixes #16858.