Skip to content
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: use internal executor for FK validation checks #37339

Closed

Conversation

RaduBerinde
Copy link
Member

Switching to the internal executor instead of delegateQuery for FK
validation queries.

Release note: None

Switching to the internal executor instead of `delegateQuery` for FK
validation queries.

Release note: None
@RaduBerinde RaduBerinde requested review from andreimatei and a team May 6, 2019 21:30
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@RaduBerinde
Copy link
Member Author

Hm, it looks like sometimes logic tests time out because the internal query deadlocks (I see a MaybeWaitForPush). I can only assume it's waiting on the parent transaction. Any idea why that would be the case (we are providing the same txn to the internal executor)?

@jordanlewis
Copy link
Member

I think this might be because delegate can use the executor's current table descriptor, but the internal executor looks up the real, persisted state of the table descriptor. Are there modifications happening to table scheams or constraints in transactions? I think @lucy-zhang might be familiar with this class of problem.

@RaduBerinde
Copy link
Member Author

Indeed, schema_change_in_txn has this test:

statement ok
BEGIN

statement ok
ALTER TABLE orders2 ADD FOREIGN KEY (product) REFERENCES products

statement ok
ALTER TABLE orders2 VALIDATE CONSTRAINT fk_product_ref_products

statement ok
COMMIT

VALIDATE runs this internal query:

SELECT s.product FROM (SELECT * FROM test.public.orders2@orders2_product_idx WHERE product IS NOT NULL) AS s LEFT OUTER JOIN test.public.products@\"primary\" AS t ON s.product = t.sku WHERE t.sku IS NULL LIMIT 1

The lease code deadlocks inside sqlbase.GetTableDescFromID, waiting on our transaction.

@RaduBerinde
Copy link
Member Author

Talked to Andrei, we probably want to pass more of the executor state (not just the txn) to the internal executor. Not quite sure where that state (mutated descriptors) is exactly, hoping someone can point me in the right direction.

Copy link
Contributor

@vivekmenezes vivekmenezes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code is suffering from #34304

i don't think you want to take on fixing that issue. @lucy-zhang is working presently on moving validation out of the user transaction to another transaction. Perhaps the best course of action here is to not move forward with this PR or at least wait for that PR to land.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @andreimatei)

@thoszhang
Copy link
Contributor

The PR that Vivek mentioned, to move the validation out of the user transaction (and do it as part of ADD CONSTRAINT), is #37433.

@RaduBerinde
Copy link
Member Author

Great! Does that PR also move the checking to a separate transaction when we do VALIDATE, or just for ADD CONSTRAINT?

@thoszhang
Copy link
Contributor

It does not change the behavior of VALIDATE CONSTRAINT, but that's planned for some point.

@RaduBerinde
Copy link
Member Author

To move forward here, we'd need to move up the work to run the VALIDATE checks in a separate txns, or do the work to allow the internal executor to "see" in-progress descriptors. The latter might be useful in other cases as well, the internal executor is used by quite a few statements.

To give more context for this PR: I am trying to retire all code paths that rely on the heuristic planner and can't use the optimizer. One of these is delegateQuery; I was able to get rid of all users of delegateQuery except FK and scrub checks.

@thoszhang
Copy link
Contributor

#37433 replaces delegateQuery for FK validation with the internal executor. We do currently have a means of adding table descriptors that the internal executor can see, by adding the table descriptor as an uncommitted table to the TableCollection: https://github.com/cockroachdb/cockroach/blob/master/pkg/sql/backfill.go#L960-L993 is the original use of it, and it also gets used in #37433 for the constraint validation queries. (There's a TODO to improve the interface, which might be more important as it gets used in an increasing number of places.)

Is this what you had in mind? (I took a closer look at this issue today, and realized I also had the same VALIDATE CONSTRAINT deadlock on my branch, so I fixed it.)

@RaduBerinde
Copy link
Member Author

Thank you Lucy! Yeah, it looks like your change contains what I tried to do here, and for that I salute you!

@RaduBerinde RaduBerinde deleted the check-no-delegate branch June 11, 2019 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants