-
Notifications
You must be signed in to change notification settings - Fork 41
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
[nexus-db-queries] remove uses of filter_target #5052
[nexus-db-queries] remove uses of filter_target #5052
Conversation
Created using spr 1.3.6-beta.1
Created using spr 1.3.6-beta.1
Thanks, looking through the comments now. |
clippy.toml
Outdated
# Instead, import diesel::query_dsl::methods::FilterDsl, then use | ||
# `do_update().set(...).filter(...)`. (This is not part of the | ||
# documentation as of Diesel 2.1.4, but it works.) | ||
"diesel::upsert::DecoratableTarget::filter_target", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it's possible to write a simple test which would break if, when updating to a new Diesel version, FilterDsl
changed to no longer generate SQL that works correctly with crdb? Is that worth the effort?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think existing tests would catch this, right?
Created using spr 1.3.6-beta.1
As discussed today, we do actually need I've verified via CockroachDB I'm happy to write extensive comments explaining this, but would love to get a thumbs up on the approach. |
I spent the evening thinking about this. For reference, the approaches we've discussed so far are:
1, 2 and 3 were discussed in the meeting today. 4 came later. 3 would be amazing if it worked, but it sadly does not. Out of the valid approaches discussed in the meeting today (1 and 2), there seemed to be general consensus about 1. The best argument I can come up with for this is that it is the closest we can get to achieving 3. While we can't name the index itself, we can name the columns constrained by it. Then One argument against it is that basically that we're relying on a 2000-year old bug in classical logic, as Eliza put it. I verified that crdb 23.2.0 has the same behavior, but it is possible that Cockroach errors on this in the future. Though in that case:
|
fn as_partial_index(self) -> Self::AsPartialIndexOutput { | ||
#[allow(clippy::disallowed_methods)] | ||
{ | ||
self.filter_target(sql::<Bool>("false")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I do understand (somewhat) based on the discussion yesterday that "contradiction implies YOLO", so false
implies all partial indexes.
Is there ever a valid reason to select a subset of partial indices? Would this be desirable where someone wants conflict on one index, but not another?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I do understand (somewhat) based on the discussion yesterday that "contradiction implies YOLO", so false implies all partial indexes.
Specifically, false
implies all the constraints on the partial indexes for the given columns. For example, in this case we have a partial index:
CREATE UNIQUE INDEX IF NOT EXISTS lookup_silo_user_by_silo ON omicron.public.silo_user (
silo_id,
external_id
) WHERE
time_deleted IS NULL;
If you specify silo_id
and external_id
, and pass in WHERE false
, the database will be able to infer that you mean the constraint time_deleted IS NULL
. If you specify a set of columns that doesn't have any kind of unique constraint on it, the query will error out.
Is there ever a valid reason to select a subset of partial indices? Would this be desirable where someone wants conflict on one index, but not another?
From my testing against crdb, the set of columns has to match one or more UNIQUE INDEX
es exactly. If there are multiple UNIQUE INDEX
instances on a set of columns, then WHERE false
will match all of them.
I think there are theoretical cases where it's possible that being able to specify some narrower constraint is useful, but I can't imagine we'll be needing it in omicron any time soon.
Created using spr 1.3.6-beta.1
Created using spr 1.3.6-beta.1
filter_target
is required for partial indexes but is easy to misuse for full indexes. To work around that, define anas_partial_index
method, switch to it, and ban general uses offilter_target
via clippy.as_partial_index
adds aWHERE false
clause. See the comments included in the PR for why that works.The rest of the PR:
disallowed_
lints are active.-A clippy::style
disables them.RunnableQuery
that often did not return anything, replacing it withRunnableQueryNoReturn
.