Skip to content

Instantly share code, notes, and snippets.

@dip00dip
Created October 13, 2017 14:20
Show Gist options
  • Save dip00dip/680f4c384ba0a4ed120c1bd036b20391 to your computer and use it in GitHub Desktop.
Save dip00dip/680f4c384ba0a4ed120c1bd036b20391 to your computer and use it in GitHub Desktop.
delete_mass_records
SET temp_buffers = 1000MB -- or whatever you can spare temporarily
CREATE TEMP TABLE tmp AS
SELECT t.*
FROM tbl t
LEFT JOIN del_list d USING (id)
WHERE d.id IS NULL; -- copy surviving rows into temporary table
TRUNCATE tbl; -- empty table - truncate is very fast for big tables
INSERT INTO tbl
SELECT * FROM tmp; -- insert back surviving rows.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment