Concurrent LOAD DATA INFILE
on MyISAM tables are limited by mutex congestion due a global Key Cache. To alleviate lock congestion, MyISAM tables can be set to have their own Key Cache.
SET GLOBAL isam_cache.key_buffer_size=8*1024;
SET GLOBAL isam_cache_two.key_buffer_size=8*1024;
CACHE INDEX log_isam IN isam_cache;
CACHE INDEX log_isam2 IN isam_cache_two;
According to the documentation, you can use SET
statements to transform the data on the way in.
[SET col_name = expr,...]
The expr expression can include the column name, which will be interpreted as the data being read from the file and destined for that column... so, for example, at the end of your LOAD DATA INFILE
statement you might use:
SET latitude = IF(latitude + 0 = 0,NULL,latitude),
area_code = IF(area_code = '',NULL,area_code)
This example transforms 2 columns. If latitude + 0 is 0, latitude gets set to NULL
, and otherwise it gets set to the value from the file as the data is inserted; if area_code contains an empty string, it gets set to NULL
, otherwise to the data from the file. The more appropriate choice will depend on how MySQL handles casting the data, but I suspect either of these constructs would work in your situation.
You do not have to reference columns you don't intend to transform. They'll be inserted as-is.
Best Answer
Check this example:
If you want to specify certain columns:
And you can even set them with your own expressions:
However, please understand that a primary key cannot be null nor duplicated, so you cannot set it to NULL unless it gets a default value, for example, because it is an auto_increment column.