After MySQL unexpected finding data, to know the truth is stunning

REVIEW
just imported tens of millions of data, but the accident of finding out, this is why?

The total number of statistics to perform COUNT (*)

[[email protected]]> select count(*) from t1;
+----------+
| count(*) |
+----------+
| 0 |
+----------+
1 row in set (1 min 25.85 sec)

SQL is running a little slow, the result is indeed empty.

And then look at a record of any query:

[[email protected]]> select * from t1 limit 1;
Empty set (13.63 sec)

Just check a record of it, this SQL running Intuit slow point, the result is still empty.

Well, look at the state of the table:

[[email protected]]> show table status G
*************************** 1. row ***************************
 Name: t1
 Engine: InnoDB
 Version: 10
 Row_format: Dynamic
 Rows: 28159173
 Avg_row_length: 45
 Data_length: 1269825536
Max_data_length: 0
 Index_length: 1308606464
 Data_free: 1063256064
 Auto_increment: 12851381
 Create_time: 2019-06-04 10:49:44
 Update_time: NULL
 Check_time: NULL
 Collation: utf8mb4_general_ci
 Checksum: NULL
 Create_options: 
 Comment: 
1 row in set (0.00 sec)
 
[[email protected]]# ll
-rw-r----- 1 mysql mysql 67 Jun 4 10:34 db.opt
-rw-r----- 1 mysql mysql 8732 Jun 4 10:49 t1.frm
-rw-r----- 1 mysql mysql 2931818496 Jun 4 13:09 t1.ibd

There are obviously looking at the data Yeah, really special What scary, chin almost lost.

Look at the thread state when performing SELECT, I found to be normal Sending data, nothing special.

Well, if you really want to enlarge the move, and then look at the state of affairs InnoDB:

------------
TRANSACTIONS
------------
Trx id counter 41220
Purge done for trx's n:o < 40288 undo n:o < 0 state: running but idle
History list length 44
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 422164356356832, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 40199, ACTIVE 1361 sec recovered trx
ROLLING BACK 1 lock struct(s), heap size 1136,
 0 row lock(s), undo log entries 3637207

It notes that the state of affairs 40199 is being rollback "ROLLING BACK", the impact of undo log There are as many as 3,637,207.

After confirmation, the cause is determined, 40199 Affairs in the process of importing data, what problems occurred during the import process, the import of cheap cheap thread press CTRL + C.

I asked you agree not unexpected, surprise surprise it is not. . .

The results on the tragedy, import thread transaction is rolled back, so just to see so many undo log entries, a total of tens of millions of data ah, but when we saw left more than 300 million.

Later, he did it again to import, this time a tragedy, because the company off the net, and import another thread is rolled back (voice-over, when on the importance screen with remote operation).

In the above example, some students may be wondering why the import is not over, but it can see the table space file has been getting bigger, and it show table status can also see rows value is relatively large.

  • First, in this case, the data import process, due to the limited buffer pool, no way to put all the new data on the buffer pool, the first part of the data will be written to the disk file table space, so to see the table space file size is not zero.
  • Secondly, show table status to see the statistics themselves are not exact, in this case, with the increase in import data (although not yet submitted import transactions), but the statistics will be updated.

And in this case there is a similar scene, is a large table full table delete the (not directly truncate), this transaction generated undo log has not been completed purge, or the transaction is rolled back also, in the process, execution the results COUNT (*) may not the same and expected.

This article ends, like a friend to help and look forward article, thanks!

Programmers still find a way to try to be ahead of career planning and preparation, what do not say: "step, step count," the words. In this era of open eyes is the competition, you can relax, but others will continue to move forward, we will not wait for you.

Finally, send Bo Fuli

Java learning, interviews; documentation, free access to video resources

Guess you like

Origin blog.csdn.net/qwe123147369/article/details/91894605