HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

LOAD DATA stuck at Null State MySQL

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
stucknullmysqlstateloaddata

Problem

I'm stuck trying to move one table to another, due to columns now no longer having proper references/meaning to their column titles. In doing this, I've created a new table with the same number of columns as the original, simply with the column names changed to better reflect the data coming in.

My problem is, the data is over 50 million rows, so I'm unable to simply alter the columns in place, so I've made a new table that I wish to use moving forward anyway. I've made the necessary column changes, but now when I try to load the data in, it looks like the process is simply stick.

+-----+------+-----------+------+---------+------+-------+----------------------------------

--------------------------------------------------------------------+
| Id  | User | Host      | db       | Command | Time | State | Info                                                                                                 |
+-----+------+-----------+------+---------+------+-------+------------------------------------------------------------------------------------------------------+
| 481 | root | localhost | database | Query   | 8617 | NULL  | LOAD DATA  LOCAL INFILE '/home/SQLBackUps/file.csv' INTO TABLE `tablename` FIELDS   |
| 483 | root | localhost | database | Sleep   | 7174 |       | NULL                                                                                                 |
| 485 | root | localhost | database | Query   |    0 | NULL  | show processlist                                                                                     |
+-----+------+-----------+------+---------+------+-------+------------------------------------------------------------------------------------------------------+


I ran the talk using mysqlimport with the necessary flags, so it should in theory at least be running, but as the state says null, I'm not sure what that really means as NULL, according to the documentation, only appears for show processlist. The file's permissions

Solution

Here is one thing that caught my eye when you replied to my comment: The target table is InnoDB and you are using LOAD DATA INFILE. I see two issues
ISSUE #1 : LOAD DATA INFILE

While LOAD DATA INFILE can load InnoDB tables, that command can be tuned for loading MyYSAM tables. There is only one option to do this: bulk_insert_buffer_size. either setting to very large or setting it to zero to disable it.

There is no synonymous provision for InnoDB.
ISSUE #2 : InnoDB Storage Engine

Let's take a look at the InnoDB Architecture

Now, picture yourself pushing 50 millions rows into one InnoDB table as a single transaction giving all the plumbing depicted in this elaborate illustration.

To ensure data consistency in the event of a crash, your data has to be written in three places:

  • There are 128 rollback segments in the System Tablespace (Physical File ibdata1). Your incoming table data must pile up on one Rollback Segment like defensive tackles on a quarterback.



  • You have an active Double Write Buffer in the System Tablespace. As the name implies, data is being written twice. InnoDB will write to the Double Write Buffer first before writing back to the .ibd files. Those data are used as source data for crash recovery.



  • The data are also being written in the Transaction Logs (Redo Logs in the Bottom Right Corner) via the Log Buffer. The physical files are ib_logfile0 and ib_logfile1.



My Perspective

InnoDB can handle 1024 current transactions but there are only 128 rollback segments. If there are other transactions going on, you got a New York City traffic jam on your hands. With all the InnoDB Internals to manage through your bulk insert, seeing NULL in the processlist should not be a surprise. You should look at four(4) things to make sure they are up-to-date:

  • filesize of ibdata1



  • timestamp on ibdata1



  • timestamp on ib_logfile0



  • timestamp on ib_logfile1



SUGGESTIONS

You could set one or more of the following

  • Disable the Double Write Buffer (set innodb_doublewrite to 0). please set it back to 1 afterwards.



  • Increase the InnoDB Buffer Pool (increase innodb_buffer_pool_size)



  • Increase the InnoDB Log File Size (set inndo_log_file_size to 2G)



  • Increase the InnoDB Log Buffer Size (set inndo_log_buffer_size to 512M)



  • Change Transaction Flush Behavior (set innodb_flush_log_at_trx_commit to 0). This will disables ACID Compliance (could lost 1 second of transactions upon a crash) but will increase InnoDB Write Performance.



  • Increase Write IO Thread (set innodb_write_io_threads to 64. You may as well set innodb_write_io_threads to 64)



GIVE IT A TRY !!!

Context

StackExchange Database Administrators Q#65227, answer score: 2

Revisions (0)

No revisions yet.