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

Add a limitation involving cascade deletions on a circular dependency #19 #21

Merged

Conversation

shuto-facengineer
Copy link
Contributor

This PR serves as a temporary measure for issue #19 by adding a note of the limitation to the README.
I'm not very confident in my English writing, so I would appreciate it if you could proofread my text.

README.md Outdated
@@ -34,6 +34,7 @@ To solve the preceding issues, this tool works as follows.

* This tool does not guarantee the atomicity of deletion. If you access the rows that are being deleted, you will get the inconsistent view of the database.
* This tool does not delete rows which were inserted while the tool was running.
* This tool does not support scenarios involving foreign key constraints with 'ON DELETE CASCADE' in cases where there is a circular dependency among the tables. As a result, it may not be able to truncate the tables.
Copy link
Collaborator

Choose a reason for hiding this comment

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

If I understand correctly, we have at least two scenarios that don't fully work.

  1. If there is a circular dependency among the tables, truncation will be failed.
  2. If user uses --exclude-tables only for the referencing table that has ON DELETE CASCADE, that table will be (surprisingly) truncated by cascade-deletion of the referenced table.

If it's correct, we can say something like...

  • This tool does not support truncating tables that use foreign key constraints in some scenarios:
    • If there is a circular dependency among the tables, truncation will be failed.
    • If --exclude-tables is used only for the referencing table that has ON DELETE CASCADE, that table will be truncated by cascade-deletion of the referenced table.

Copy link
Contributor Author

@shuto-facengineer shuto-facengineer Feb 16, 2024

Choose a reason for hiding this comment

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

If --exclude-tables is used only for the referencing table that has ON DELETE CASCADE, that table will be truncated by cascade-deletion of the referenced table.

If we need to present detailed scenarios, we may be able to add the following scenario as well.

  • If --tables is used for a table referenced with ON DELETE CASCADE, the table will be truncated with the referrer tables.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds good! Let's use the consistent wording referencing table and referenced table as they are used in the public documentation: https://cloud.google.com/spanner/docs/foreign-keys/overview#how-to-define-foreign-keys

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the consistent wording referencing table and referenced table

This sounds easy to understand. I adopt this.

README.md Outdated
@@ -34,6 +34,10 @@ To solve the preceding issues, this tool works as follows.

* This tool does not guarantee the atomicity of deletion. If you access the rows that are being deleted, you will get the inconsistent view of the database.
* This tool does not delete rows which were inserted while the tool was running.
* This tool does not support truncating tables that use foreign key constraints in some scenarios:
* If there is a circular dependency among the tables, truncation will be failed.
* If `--tables` is used for a referenced table with ON DELETE CASCADE, the table will be truncated with the referencing tables.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry for different feedback, but referenced table with ON DELETE CASCADE would be somewhat confusing.

Let's say, we have two tables, Customers and ShoppingCarts (borrowed from doc), and ShoppingCarts table is referencing Customers table with ON DELETE CASCADE.

In this example, ShoppingCarts is the referencing table and Customers is the referenced table.

If user specifies --tables=Customers (referenced table), then ShoppingCarts (referencing table) is also truncated as a effect of ON DELETE CASCADE.

So maybe the following might be clearer? If --tables is used for a table that is referenced by other tables with ON DELETE CASCADE, such tables will also be truncated.

Copy link
Contributor Author

@shuto-facengineer shuto-facengineer Feb 19, 2024

Choose a reason for hiding this comment

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

If --tables is used for a table that is referenced by other tables with ON DELETE CASCADE, such tables will also be truncated.

This sounds clearer! Thank you.

referenced table with ON DELETE CASCADE would be somewhat confusing.

If I understand correctly, your point is that the foreign key constraint is placed on the referencing table, not on the referenced table, right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

If I understand correctly, your point is that the foreign key constraint is placed on the referencing table, not on the referenced table, right?

Yes, that's right.

Copy link
Collaborator

@yfuruyama yfuruyama left a comment

Choose a reason for hiding this comment

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

@shuto-facengineer LGTM. Thank you for compiling the information and updating the doc!

@yfuruyama yfuruyama merged commit 3ee90ea into cloudspannerecosystem:main Feb 19, 2024
1 check passed
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.

2 participants