-
Notifications
You must be signed in to change notification settings - Fork 25
Open
Labels
Description
We can add an additional safety measure against the custom SQL destroying all or most of someone's table. Simply compare the results from SELECT reltuples FROM pg_class WHERE relname = <old table>
against the same query for the new table after the ANALYZE has been run, but before the tables are swapped. Since this is an estimate, we should probably use a comparison that looks something like >= 0.95 * old_tuples
. We should also add a flag like --copy_percentage
that lets you set a lower threshold for that comparison for use cases where the user is purposely deleting much of the table data.
This would help guard against a user not understanding the documentation and using something unfortunate like:
-- file: /src/query.sql
INSERT INTO %{shadow_table}(foo, bar, baz, rental_id, tenant_id)
SELECT 1,1,1,1,1
shayonjshayonjshayonj