51ak shows you MYSQL5.7 source code 3: modify the code to implement your first Mysql version, 51akmysql5.7
Have worked as a DBA for many years
MYSQL source code is also the first contact
Try to record the process of viewing the MYSQL5.7 source code by yourself
Directory:
51ak: MYSQL5.7 source code 1: main Entry Function
51ak shows you MYSQL5.7 source code 2: compile existing code
51ak shows you the source code of MYSQL5.7. 3: modify the code to implement your first Mysql version.
Deployed in development and test environments
Now it's time for us to get started. Everything is hard to start with. First, we implement a small function.
Today, we are going to implement this function:Data will never be deleted
When you put this version of MYSQL in the online environment, you never have to worry about someone deleting your data.
The idea is simple: shunteng finds the FUNC in which Delete is located and returns an OK message at the beginning of the function.
The question is, how can I find this function?
There are two types: a very spiritual student may have seen the SQL/SQL _delete.cc file at a Glance. I guess it is this file.
Another method is to lay a solid foundation. We can find it here by following the code layer.
Dispatch_command |-> mysql_parse |-> mysql_execute_command-> mysql_update/mysql_delete
To get started quickly, we use the first method to directly open SQL/SQL _delete.cc
Find this method:
Bool SQL _cmd_delete: execute (THD * thd) {DBUG_ASSERT (thd-> lex-> SQL _command = SQLCOM_DELETE); LEX * const lex = thd-> lex; SELECT_LEX * const select_lex = lex-> select_lex; SELECT_LEX_UNIT * const unit = lex-> unit; TABLE_LIST * const first_table = select_lex-> tables (); TABLE_LIST * const all_tables = first_table; if (delete_precheck (thd, all_tables) return true; DBUG_ASSERT (select_lex-> offset_limit = 0); unit-> set_limit (select_lex ); /* Push ignore/strict error handler */pull ignore_handler; pull strict_handler; if (thd-> lex-> is_ignore () thd-> push_internal_handler (& ignore_handler ); else if (thd-> is_strict_mode () thd-> push_internal_handler (& strict_handler );
/* Note:Here we want to change the value, return a true value directly, and comment out the actually executed part.*/Bool res = true;/* MYSQL_DELETE_START (const_cast <char *> (thd-> query (). str); bool res = mysql_delete (thd, unit-> select_limit_cnt); MYSQL_DELETE_DONE (res, (ulong) thd-> get_row_count_func ());*//* Pop ignore/strict error handler */if (thd-> lex-> is_ignore () | thd-> is_strict_mode () thd-> pop_internal_handler (); return res ;}
Now let's change the code to this small place. Compile and run it now.
Create a test table and write several pieces of data into the table. Then, try various DELETE statements. The next step is to witness the miracle. You will find that the data can never be deleted ..
mysql> select * from t1;+----+| id |+----+| 1 || 2 || 3 || 4 || 5 |+----+5 rows in set (0.00 sec)mysql> delete from t1 where id=2;Query OK, 0 rows affected (0.00 sec)
Mysql> select * from t1;
+ ---- +
| Id |
+ ---- +
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
+ ---- +
5 rows in set (0.00 sec)
What's the matter? A small change makes you no longer worry about data deletion. Is it cool?
Now that you have the first custom version of MYSQL, You can package and release it online !!
Let those RD personnel feel the control from DBA.
Some friends may ask, "This only prevents DELETE, not TRUNCATE and DROP...
I think you are not spiritual enough ..
Okay, so far today