Safely dropping MySQL tables
David Graham
David Graham
7/25/2022
Product4 min read

Safely dropping MySQL tables

Removing an unused table from a database schema can be challenging. Even after triple checking that all of your apps have migrated away from querying the table, there may still be that one rogue script that accesses it.

PlanetScale now checks that tables are truly unused during deploy requests and warns you if the table to be dropped was recently queried.

Deploy request drop table warning in PlanetScale dashboard

Identifying table usage with Insights#

On top of warning you, we also want to help you find when and where the table is being queried. If you run into this warning, you can use Insights, our in-dashboard query monitoring tool, to help identify where the table is being queried.

With Insights, you can narrow down your analysis to individual query performance. We also surface SQL comments on queries, so you can tag your queries with additional information to track down where they came from.

Instrumenting queries with comment tags can help you identify which application is still using the table. Once you remove the query from any remaining applications, you can confidently drop the table.

Insights query tags

Queries against individual tables can always be found by going to your Insights page and using the table:<name> query syntax in the filter input box, as shown below. This reveals how many dependencies there are on the table before attempting to drop it.

Table query syntax

Try it out#

Hopefully this addition will make cleaning up unused tables a little less stressful.

For more information about how to use Insights, check out our documentation.

We love hearing from you! If you have any questions or feedback, don’t hesitate to reach out to us.