Tech Tip: How to speed up large exports and imports.
PRODUCT: 4D | VERSION: 12 | PLATFORM: Mac & Win
Published On: March 1, 2012
4D v12 introduced an important feature for use when performing demanding data operations like importing or exporting large amounts of data. The SQL command SQL ALTER DATABASE can be used to programatically disable both all database constraints as well as indexes.
Database "constraints" means, quite literally, all database constraints, for example:
- Uniqueness
- Triggers
- Auto UUID and Autoincrement
"Indexes" refers to to any indexing operations, be it adding keys, updating jeys, or removing keys. Keep in mind the indexes will still need to be updated when indexing is again enabled.
Also note that these settings apply to the entire database; even in client-server, if one user disables constraints or indexes it is disabled for all other users.
Disabling constraints and/or indexes can significantly improve the performance of large data operations by removing the overhead involved with maintaining database integrity. On the otherhand it is important to use this feature carefully and only when appropriate, only in a development or maintenance context.
Here is an example using this feature and performing an importnig using the SQL EXECUTE SCRIPT command:
Begin SQL ALTER DATABASE DISABLE INDEXES; ALTER DATABASE DISABLE CONSTRAINTS; End SQL SQL EXECUTE SCRIPT("C:\Exported_data\Export.sql";SQL On error continue) Begin SQL ALTER DATABASE ENABLE INDEXES; ALTER DATABASE ENABLE CONSTRAINTS; End SQL |