patternsqlMinor
mysql insert into indexed table taking long time after few million records
Viewed 0 times
aftermillioninsertintorecordslongtimeindexedmysqlfew
Problem
I have a table like this
i have to insert 300 million records. i am inserting 10 million records each time using
To insert 10 million records taking nearly 5 min first time. Time is increasing each time gradually. after 30 million records it stops inserting and memory using 100% server not responding.
below my
i am using cpu with 2 G memory.
details for 30 million records
with out index it is inserting fine 10 million in 50 sec.
Please tell me what kind of setting need to change.
Edit based on user answers
I have changed my.cnf setting to below
no use. issue is not resolved.
I have tried below mentioned methods to load data
No luck..
CREATE TABLE IF NOT EXISTS `dnddata` (
`numbers` varchar(10) NOT NULL,
`opstype` char(1) NOT NULL,
PRIMARY KEY (`numbers`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
/*!50100 PARTITION BY KEY (numbers)
PARTITIONS 25 */;i have to insert 300 million records. i am inserting 10 million records each time using
load data in file from csv file.To insert 10 million records taking nearly 5 min first time. Time is increasing each time gradually. after 30 million records it stops inserting and memory using 100% server not responding.
below my
my.cnf file settingbulk_insert_buffer_size = 100M
key_buffer = 100M
sort_buffer_size = 50M
read_buffer = 50Mi am using cpu with 2 G memory.
details for 30 million records
Space usage
Type Usage
Data 545.3 MiB
Index 694.8 MiB
Total 1,240.1 MiB
MySQL client version: 5.5.14with out index it is inserting fine 10 million in 50 sec.
Please tell me what kind of setting need to change.
Edit based on user answers
I have changed my.cnf setting to below
key_buffer_size = 1G
sort_buffer_size = 4M
read_buffer_size = 1M
read_rnd_buffer_size = 1M
join_buffer_size = 2M
bulk_insert_buffer_size = 32M
myisam_sort_buffer_size = 256Mno use. issue is not resolved.
I have tried below mentioned methods to load data
set autocommit = 0; //for innodb
load data infile into …
COMMIT;
START TRANSACTION;
load data infile into …
COMMIT;
ALTER TABLE dnddata DISABLE KEYS;
load data infile into …
ALTER TABLE dnddata ENABLE KEYS;No luck..
Solution
You should load such a huge file in chunk for faster loading of data,
Here it is mentioned problems loading huge
http://www.mysqlperformanceblog.com/2008/07/03/how-to-load-large-files-safely-into-innodb-with-load-data-infile/
With some extra work, it is possible to make
-
Execute a FLUSH TABLES statement or a mysqladmin flush-tables command.
-
Use myisamchk --keys-used=0 -rq /path/to/db/tbl_name to remove all use of indexes for the table.
-
Insert data into the table with LOAD DATA INFILE. This does not update any indexes and therefore is very fast.
-
Re-create the indexes with
-
Execute a FLUSH TABLES statement or a mysqladmin flush-tables command.
LOAD DATA INFILE performs the preceding optimization automatically if the MyISAM table into which you insert data is empty. The main difference between automatic optimization and using the procedure explicitly is that you can let myisamchk allocate much more temporary memory for the index creation than you might want the server to allocate for index re-creation when it executes the LOAD DATA INFILE statement.
You can also disable or enable the nonunique indexes for a MyISAM table by using the following statements rather than myisamchk. If you use these statements, you can skip the FLUSH TABLE operations:
For more information refer these:
http://dev.mysql.com/doc/refman/5.5/en/optimizing-myisam-bulk-data-loading.html
https://wiki.rice.edu/confluence/display/~as43/Make+LOAD+DATA+INFILE+run+even+faster+for+a+MyISAM+table
Here it is mentioned problems loading huge
Load local data file and solution how to solve it and make it faster.http://www.mysqlperformanceblog.com/2008/07/03/how-to-load-large-files-safely-into-innodb-with-load-data-infile/
- MyISAM tables you should follow this steps to fasten loading data:
With some extra work, it is possible to make
LOAD DATA INFILE run even faster for a MyISAM table when the table has many indexes. -
Execute a FLUSH TABLES statement or a mysqladmin flush-tables command.
-
Use myisamchk --keys-used=0 -rq /path/to/db/tbl_name to remove all use of indexes for the table.
-
Insert data into the table with LOAD DATA INFILE. This does not update any indexes and therefore is very fast.
-
Re-create the indexes with
myisamchk -rq /path/to/db/tbl_name. This creates the index tree in memory before writing it to disk, which is much faster that updating the index during LOAD DATA INFILE because it avoids lots of disk seeks. The resulting index tree is also perfectly balanced.-
Execute a FLUSH TABLES statement or a mysqladmin flush-tables command.
LOAD DATA INFILE performs the preceding optimization automatically if the MyISAM table into which you insert data is empty. The main difference between automatic optimization and using the procedure explicitly is that you can let myisamchk allocate much more temporary memory for the index creation than you might want the server to allocate for index re-creation when it executes the LOAD DATA INFILE statement.
You can also disable or enable the nonunique indexes for a MyISAM table by using the following statements rather than myisamchk. If you use these statements, you can skip the FLUSH TABLE operations:
ALTER TABLE tbl_name DISABLE KEYS;
ALTER TABLE tbl_name ENABLE KEYS;For more information refer these:
http://dev.mysql.com/doc/refman/5.5/en/optimizing-myisam-bulk-data-loading.html
https://wiki.rice.edu/confluence/display/~as43/Make+LOAD+DATA+INFILE+run+even+faster+for+a+MyISAM+table
Code Snippets
ALTER TABLE tbl_name DISABLE KEYS;
ALTER TABLE tbl_name ENABLE KEYS;Context
StackExchange Database Administrators Q#21371, answer score: 6
Revisions (0)
No revisions yet.