Finding the tables nobody uses

·

Every data warehouse collects tables nobody needs anymore. A table built to answer one question, an import from a tool the company stopped using, a feature table for a model that never shipped. Each one costs disk space, and if a scheduled job still rebuilds it, compute every day. Nobody deletes them, because nobody is sure they’re safe to delete.

This year we started finding them automatically. The idea is simple, and most of what made it work was the process around it.

Defining “unused”

A table counts as unused if both of these are true:

  1. No scheduled transformation reads it. Our transformations are defined in one framework, so the inputs of every job are known.
  2. Almost nobody queried it. Fewer than ten SELECT queries in Trino over the last six months. Trino serves our dashboards in Looker and Superset as well as ad hoc analysis, so its query log covers those too.

The first version used zero queries as the threshold; we later raised it to fewer than ten.

It’s a heuristic. A table that’s read only by a quarterly script outside the framework, or kept for an audit, looks unused. So the check never deletes anything itself. It runs with our other data validations and produces a list, and people decide.

The first run

The first run found 530 tables. Asking people to review 530 tables at once gets you nowhere, so we started with the 25 larger than a gigabyte. The two biggest were 341 GB and 250 GB.

For each table, we needed an owner. Most of our tables are created by a transformation, and every transformation arrived in a pull request, so the pull request that added a table names the person or team who asked for it. Where that person had moved on, the table went to their team.

Each owner got the list of their tables, with one of two outcomes for each:

  • Delete it, together with the transformation or import that builds it. Dropping only the table doesn’t help, because the job recreates it the next day.
  • Keep it, by adding it to an exclusion list in the check’s code, through a pull request, so the decision is recorded and reviewable.

Within a week, most of the large tables were deleted or excluded. Some teams went further than the list: one turned off the third-party syncs feeding tables nobody read, and removed the reporting view built on one of them.

Making it routine

After the large tables, we worked through the rest the same way, grouped by owner, with a task list per team. Tables that were loaded once and never change, like reference data, were marked as done without a review, since “not rebuilt and rarely queried” is normal for them. By the end of November the remaining teams had removed the code behind their unused tables, including one entire database, and we dropped them.

The plan from here is a new review every month. A monthly list of a few tables is a five-minute job for the people who own them; a list of hundreds, years later, isn’t anyone’s job.

What made it work

  • A definition people can check. “No job reads it and fewer than ten queries in six months” is easy to verify and hard to argue with.
  • An owner for every table. Version control already had this information. Without an owner, every table is someone else’s problem.
  • Keeping a table is a decision too. The exclusion list turns “I’m not sure” into an explicit choice with a name on it.
  • Start with what’s large. A short list of big tables showed results quickly and got people used to the process before the long tail.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *