-
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: disable ordering by array columns #16540
Conversation
In accordance with cockroachdb#16172, we will need to disallow ordering by arrays columns to keep open the door to decide on how we should order them later on. I debated making the check a method on the Type interface, but I decided that was overkill for this single check on a single Type. Regardless, the check is isolated into a single function so it can be changed easily. This approach doesn't play well with wrapped Oid types like INT2VECTOR and INT4VECTOR, but I'm not too concerned about those because users can't construct them, and since they only exist for pg_catalog compatibility anyway we might as well allow ordering by them as in Postgres. We currently don't support `IN` or `MAX`/`MIN` on arrays, so that's not something we need to be concerned about. As far as I'm aware there are no other situations where the ordering of arrays is exposed to users. I tried adding a panic to TArray's Compare method and the only test failure was a test calling Compare explicitly as an assertion. This is technically a breaking change which should be announced to users once it is released, though I doubt anyone is making use of this.
Review status: 0 of 3 files reviewed at latest revision, 1 unresolved discussion, all commit checks successful. pkg/sql/sort.go, line 172 at r1 (raw file):
I'm not too familiar with column ordinals, but it seems like you need to check that they're all comparable too, right? Comments from Reviewable |
Review status: 0 of 3 files reviewed at latest revision, 1 unresolved discussion, all commit checks successful. pkg/sql/sort.go, line 172 at r1 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
Both this case and the one above are handled by the block on L185, they both just set
The check on L185 handles both cases 1 and 2, the check on L219 handles case 3. The reason the two checks are different is that cases 1 and 2 use an existing column while case 3 uses a new one. This function could maybe do with some function extraction to make the above structure more obvious. Comments from Reviewable |
once you're satisfied with the test coverage Reviewed 3 of 3 files at r1. pkg/sql/sort.go, line 172 at r1 (raw file): Previously, justinj (Justin Jaffray) wrote…
Gotcha. Do your tests exercise both of these cases? Comments from Reviewable |
Review status: all files reviewed at latest revision, 1 unresolved discussion, all commit checks successful. pkg/sql/sort.go, line 172 at r1 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
Yup, the query error cases I added handle the four main cases (new expression, same expression, column ordinal, aliased expression). Comments from Reviewable |
Reviewed 1 of 3 files at r1. Comments from Reviewable |
Reviewed 2 of 3 files at r1. Comments from Reviewable |
In accordance with #16172, we will need to disallow ordering by arrays
columns to keep open the door to decide on how we should order them
later on.
I debated making the check a method on the Type interface, but I decided
that was overkill for this single check on a single Type. Regardless,
the check is isolated into a single function so it can be changed
easily. This approach doesn't play well with wrapped Oid types like
INT2VECTOR and INT4VECTOR, but I'm not too concerned about those because
users can't construct them, and since they only exist for pg_catalog
compatibility anyway we might as well allow ordering by them as in
Postgres.
We currently don't support
IN
orMAX
/MIN
on arrays, so that's notsomething we need to be concerned about.
As far as I'm aware there are no other situations where the ordering of
arrays is exposed to users. I tried adding a panic to TArray's Compare
method and the only test failure was a test calling Compare explicitly
as an assertion.
This is technically a breaking change which should be announced to users
once it is released (though I doubt anyone is making use of this).
Also updated the array rfc to be in-progress.