Request a demo

Glossary · Cost and FinOps

What is unused table?

An unused table is a table that no query has read within a reference window, such as the last 90 days. It still costs storage, and often a pipeline still refreshes it, so it is a first candidate for an expiration, archiving or deletion.

Also called: stale table, orphaned table, unqueried table, cold table, BigQuery unused tables

Why unused tables matter

Each unused table costs storage every month. In the US multi-region, logical storage lists at $0.02 per GiB-month active and $0.01 long-term; physical storage at $0.04 and $0.02, and under the physical model time travel and fail-safe bytes are billed at the active physical rate (BigQuery pricing). Long-term pricing softens the cost, but a table nobody reads is still pure overhead. For the tables you keep, the pricing calculator compares logical and physical storage billing.

The bigger cost is often next to the table: a scheduled job that keeps rebuilding something nobody reads. That case has its own name, a dead-end table, and its compute usually dwarfs the storage. Unused copies of personal data are also a governance liability.

How to find unused tables on BigQuery

Query jobs record every base table they read in referenced_tables, and TABLE_STORAGE lists every table with its size. An anti-join of the two gives tables with no reads in the window:

WITH reads AS (
  SELECT DISTINCT t.project_id, t.dataset_id, t.table_id
  FROM `region-us`.INFORMATION_SCHEMA.JOBS_BY_ORGANIZATION AS j,
    UNNEST(j.referenced_tables) AS t
  WHERE j.creation_time >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 90 DAY)
)
SELECT
  s.table_schema AS dataset_id,
  s.table_name AS table_id,
  DATE(s.storage_last_modified_time) AS last_written,
  ROUND(s.total_logical_bytes / POW(1024, 3)) AS logical_gib,
  ROUND(s.active_logical_bytes / POW(1024, 3) * 0.02
    + s.long_term_logical_bytes / POW(1024, 3) * 0.01, 2) AS usd_per_month_logical
FROM `region-us`.INFORMATION_SCHEMA.TABLE_STORAGE AS s
LEFT JOIN reads AS r
  ON r.project_id = s.project_id
  AND r.dataset_id = s.table_schema
  AND r.table_id = s.table_name
WHERE r.table_id IS NULL
  AND NOT s.deleted
  AND s.creation_time < TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 90 DAY)
ORDER BY s.total_logical_bytes DESC
LIMIT 100;

Run it from the project whose tables you want to check; JOBS_BY_ORGANIZATION supplies reads from every project in the organization. A recent last_written on an unread table points to a dead end. If TABLE_STORAGE returns an error that it hasn't been enabled, set enable_info_schema_storage on the project or organization and allow about a day for history to fill in.

Blind spots to check before deleting

  • Reads that aren't query jobs. Storage Read API sessions (Spark and Dataflow connectors, for example), table previews and export jobs don't appear in referenced_tables. Data Access audit logs record them.
  • Cache hits. referenced_tables is empty for cached results. A table that is read only from cache was still read uncached at least once, but possibly before your window.
  • Readers outside the organization. Projects in other organizations that read your shared datasets don't appear in JOBS_BY_ORGANIZATION.
  • Rare consumers. JOBS keeps 180 days, which misses yearly audits and annual reports.
  • Views. A query through a view records the view's base tables, so tables read only through views are not flagged. The views themselves don't appear in referenced_tables.

Clean up safely

Tell the owner, then set an expiration instead of deleting right away, so a missed consumer has time to complain:

ALTER TABLE `analytics-prod.archive.events_2023`
SET OPTIONS (expiration_timestamp = TIMESTAMP_ADD(CURRENT_TIMESTAMP(), INTERVAL 30 DAY));

Export data you must keep to Cloud Storage first. Deleted tables stay recoverable for the time travel window plus seven days of fail-safe, so a deletion mistake is fixable for a short while, not forever.

Masthead finds unused and dead-end tables across projects from logs and metadata, together with the storage and compute each one costs (details).

FAQ

How do I find unused tables in BigQuery?

Collect every table that appears in referenced_tables in INFORMATION_SCHEMA.JOBS_BY_ORGANIZATION over your window, then anti-join INFORMATION_SCHEMA.TABLE_STORAGE against that list. Check Data Access audit logs as well, because reads through the Storage Read API, table previews and exports are not query jobs.

Does BigQuery remove unused data automatically?

No. A table or partition that hasn't been modified for 90 consecutive days moves to the long-term storage rate, about half the active rate, but the data stays until someone deletes it or a table, partition or dataset default expiration removes it.

Can I get a table back after deleting it?

Within the time travel window (two to seven days, seven by default) you can restore it yourself. After that, BigQuery keeps the data for another seven days of fail-safe, which only Cloud Customer Care can recover.

Read next

Browse the full glossary

Cut BigQuery spend without guessing

Masthead attributes compute and storage cost to every project, user, pipeline and table, finds unused and dead-end tables, and shows where editions or on-demand pricing is cheaper. Mnemonic cut its BigQuery compute cost by 20% within 24 hours of onboarding.