Bug #104435 print() func output nothing for class Item_func_get_system_var
Submitted: 28 Jul 2021 6:08 Modified: 29 Jul 2021 12:39
Reporter: hao lu (OCA) Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:8.0.25 OS:Any
Assigned to: CPU Architecture:Any
Tags: debug, item, print, system_var

[28 Jul 2021 6:08] hao lu
Description:
The "print()" function in class "Item_func_get_system_var" and "Item_func_get_user_var" seems print the name of releated variable. But the "print()" in "Item_func_get_system_var" just use member "item_name" which is a null pointer. Is this behaviour expected?

Gdb output as Following :

(gdb) p this
$37 = (Item_func_get_system_var * const) 0x7f77f4abdc78
(gdb) p this->item_name
$38 = {<Name_string> = {<Simple_cstring> = {m_str = 0x7f77f4abddd8 "@@auto_increment_increment", m_length = 26}, <No data fields>}, m_is_autogenerated = true}
(gdb) p this->var
$39 = (warning: RTTI symbol not found for class 'Sys_var_integer<unsigned long, 6ul, (enum_mysql_show_type)3, false>'
warning: RTTI symbol not found for class 'Sys_var_integer<unsigned long, 6ul, (enum_mysql_show_type)3, false>'
sys_var *) 0x56327c23b560 <Sys_auto_increment_increment>

How to repeat:
1. connect to mysql
2. gdb attach and break at the first line of "Item_func_get_system_var::val_int()"
3. execute "select @@auto_increment_increment"
4. print vars using gdb()
[28 Jul 2021 12:28] MySQL Verification Team
Hi Mr. sephiroth,

Thank you for your bug report.

However, this is not a bug.

First of all, you report that member `item_name` is a NULL pointer, which your own output clearly shows that it is not.

Next, there is a small RTTI warning for the member `var`, which is expected, because on some systems this member is optimised and stored in the register, for the faster processing of the `switch` statement.

Not a bug.
[29 Jul 2021 2:57] hao lu
Sorry for supply misleading messages. I incorrectly set break point at the function name using gdb, and output the nullptr at previous output. It's just an incorrect way of how to repeat.

Actually, I was trying to achieve "load data in parallel" which split input files into small chunks and create sub-sessions loading file chunks(in memory). There has a issue that I have to collect all user_vars and session_vars appeared in load data statement. So I add an processor function for "Item->walk()" to iterater all items, collect them and set those vars in sub-session, making sure that the sub-sessions have the same value of vars with main-session. However, when printing system_var's name, the "Item_func_get_system_var::print" output nothing but "Item_func_get_system_var::val_str()" works well.

As a result, the error log of sub-session as following(load data infile 'xxx.txt' into table t1 (c1, @@default_storage_engine):
2021-07-28T06:24:21.991735Z 0 [Warning] [MY-011071] [Server] execute_sql error sql [SET /*parallel load worker(init_session)*/ @@ = 'InnoDB']

3146	    auto value_str = var_item->val_str(&str);
(gdb) p var_item
$10 = (Item_func_get_system_var *) 0x7f9820111270
(gdb) p var_item->item_name
$11 = {<Name_string> = {<Simple_cstring> = {m_str = 0x0, m_length = 0}, <No data fields>}, m_is_autogenerated = true}
(gdb) n
3147	    auto type = var_item->result_type();
(gdb) p *value_str
$12 = {m_ptr = 0x7f982000b660 "InnoDB", m_length = 6, m_charset = 0x5585cf5937c0 <my_charset_utf8_general_ci>, m_alloced_length = 8, m_is_alloced = true}
[29 Jul 2021 12:11] MySQL Verification Team
Thank you for your last comment.

If we are correctly understanding your last comment, you would like to use this forum to get a help from us on developing your own software. Are we correct or totally wrong ???

If we are correct, you should look at all the features already provided by our mysqldump and mysqlpump. 

Some of them could make a better bases for multi-threaded LOAD FILE .......
[29 Jul 2021 12:39] hao lu
Thanks for your reply. I have got the correct var_name of "Item_func_get_system_var" through other way and the parallel loading now seems to work well. Just wondering whether "item->item_name->m_str == 0x0" is expected in my situation.

I will read source code again and checkout why "m_str" is nullptr by myself. Thanks again.
[29 Jul 2021 13:01] MySQL Verification Team
Thank you, very much, for your kind words .....

Please, let us know if you require any further help from us !!!!!

Either for this project or for any other !!!!