mysql - INSERT ... ON DUPLICATE KEY UPDATE vs TRUNCATE/INSERT -
i'm rewriting data push script pulls data out of mssql database on server , inserts data mysql database. process cron'ed run nightly , handled via php.
the original script truncates tables , reinserts data nightly. of tables have primary, unique keys come mssql database. of tables not.
i considering adding generic primary keys mysql tables not have them may insert ... on duplicate key update instead of emptying tables , reinserting data each night. primary keys used no other reason process.
would process faster/less resource intensive if did insert ... on duplicate key update versus truncate , insert script does? worth hassle of creating generic primary keys on tables not have them insert ... on duplicate key update? looking best possible performance out of script.
it hard give general answer without knowing specifics of data. want know size of tables in rows, , if using innodb. however, if tables small <1000 rows, and/or not using innodb, leave as-is. however, if have large tables, have seen dramatic improvements in speed using insert..on duplicate method.
a process may switch on 1 or 2 of larger tables , measure speed improvements. if worthwhile, proceed rest.
Comments
Post a Comment