Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(stonedb): parent_lex->result in Engine::GetFilename is nullptr leads StoneDB to crash. #557

Closed
andyli029 opened this issue Sep 23, 2022 · 9 comments · Fixed by #572
Closed
Assignees
Labels
A-feature feature with good idea C-stonedb-8.0 associated with stonedb 8.0

Comments

@andyli029
Copy link
Contributor

Is your feature request related to a problem? Please describe.

From Engine::GetFilename
selects_list->parent_lex->exchange is deleted by MySQL 8.0

Describe the solution you'd like

Describe alternatives you've considered

Additional context

@andyli029 andyli029 added the A-feature feature with good idea label Sep 23, 2022
@andyli029 andyli029 added the C-stonedb-8.0 associated with stonedb 8.0 label Sep 23, 2022
@andyli029 andyli029 added this to the stonedb_8.0_v1.0.0 milestone Sep 23, 2022
@andyli029
Copy link
Contributor Author

(gdb) bt
#0  0x000055555b525328 in Query_result_to_file::get_sql_exchange (this=0x0)
    at /data/mysql-server-mysql-8.0.30/sql/query_result.h:217
#1  0x000055555b51cc46 in Tianmu::core::Engine::GetFilename (selects_list=0x7ffaac00d010,
    is_dumpfile=@0x7fffc83be37c: -308578081) at /data/mysql-server-mysql-8.0.30/storage/tianmu/core/engine.cpp:1614
#2  0x000055555b51c813 in Tianmu::core::Engine::IsTIANMURoute (thd=0x7ffaac001040, table_list=0x7ffaac00def8,
    selects_list=0x7ffaac00d010, in_case_of_failure_can_go_to_mysql=@0x7fffc83be4c8: 1, with_insert=0)
    at /data/mysql-server-mysql-8.0.30/storage/tianmu/core/engine.cpp:1572
#3  0x000055555b55d786 in Tianmu::core::Engine::HandleSelect (this=0x555560f93ba0, thd=0x7ffaac001040, lex=0x7ffaac0043c0,
    result=@0x7ffaac0a6078: 0x7ffaac0a7048, setup_tables_done_option=0, res=@0x7fffc83be620: -935598512,
    optimize_after_tianmu=@0x7fffc83be690: 0, tianmu_free_join=@0x7fffc83be624: 0, with_insert=0)
    at /data/mysql-server-mysql-8.0.30/storage/tianmu/core/engine_execute.cpp:93
#4  0x000055555b4a865d in Tianmu::dbhandler::TIANMU_HandleSelect (thd=0x7ffaac001040, lex=0x7ffaac0043c0,
    result=@0x7ffaac0a6078: 0x7ffaac0a7048, setup_tables_done_option=0, res=@0x7fffc83be620: -935598512,
    optimize_after_tianmu=@0x7fffc83be690: 0, tianmu_free_join=@0x7fffc83be624: 0, with_insert=0)
    at /data/mysql-server-mysql-8.0.30/storage/tianmu/handler/ha_rcengine.cpp:81
#5  0x00005555592e7b4c in Sql_cmd_dml::execute (this=0x7ffaac0a6050, thd=0x7ffaac001040)
    at /data/mysql-server-mysql-8.0.30/sql/sql_select.cc:589
#6  0x000055555925ea47 in mysql_execute_command (thd=0x7ffaac001040, first_level=true)
    at /data/mysql-server-mysql-8.0.30/sql/sql_parse.cc:4604
#7  0x0000555559260d32 in dispatch_sql_command (thd=0x7ffaac001040, parser_state=0x7fffc83bfb90)
    at /data/mysql-server-mysql-8.0.30/sql/sql_parse.cc:5239
#8  0x00005555592567b1 in dispatch_command (thd=0x7ffaac001040, com_data=0x7fffc83c04e0, command=COM_QUERY)
    at /data/mysql-server-mysql-8.0.30/sql/sql_parse.cc:1959
#9  0x0000555559254828 in do_command (thd=0x7ffaac001040) at /data/mysql-server-mysql-8.0.30/sql/sql_parse.cc:1362
#10 0x0000555559491135 in handle_connection (arg=0x5555638a9c60)
    at /data/mysql-server-mysql-8.0.30/sql/conn_handler/connection_handler_per_thread.cc:302
#11 0x000055555b3b451a in pfs_spawn_thread (arg=0x55556389e610) at /data/mysql-server-mysql-8.0.30/storage/perfschema/pfs.cc:2942
#12 0x00007ffff7f97609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#13 0x00007ffff6e6f133 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
(gdb) p exchange
Cannot access memory at address 0x20
(gdb) f 1
#1  0x000055555b51cc46 in Tianmu::core::Engine::GetFilename (selects_list=0x7ffaac00d010,
    is_dumpfile=@0x7fffc83be37c: -308578081) at /data/mysql-server-mysql-8.0.30/storage/tianmu/core/engine.cpp:1614
warning: Source file is more recent than executable.
1614	      static_cast<Query_result_to_file *>(selects_list->parent_lex->result)->get_sql_exchange();
(gdb) p selects_list->parent_lex->result
$1 = (Query_result *) 0x0

@DandreChen
Copy link
Collaborator

cause of crash :“selects_list->parent_lex->result” :the “result” pointer is null

@andyli029
Copy link
Contributor Author

cause of crash :“selects_list->parent_lex->result” :the “result” pointer is null

p selects_list->parent_lex->result
$1 = (Query_result *) 0x0

Yes, pls fix it.

@RingsC
Copy link
Contributor

RingsC commented Sep 23, 2022

SELECT_LEX -> Query_block
SELECT_LEX_UNIT -> Query_expression

@RingsC RingsC changed the title StoneDB 8.0: fix Engine::GetFilename StoneDB 8.0: parent_lex->result in Engine::GetFilename is nullptr leads StoneDB to crash. Sep 24, 2022
@lujiashun
Copy link

lujiashun commented Sep 26, 2022

in mysql8.0 execute flow is as below,lex->query_block->parent_lex->result->exchange value is correct.
note:exexute select into outfile....clause.

#0  Sql_cmd_dml::execute (this=0x7f87bc0f6d80, thd=0x7f87bc18c840) at /data/codebase/stonedb80/stonedb/sql/sql_select.cc:500
#1  0x0000561d9d0842c7 in mysql_execute_command (thd=0x7f87bc18c840, first_level=true) at /data/codebase/stonedb80/stonedb/sql/sql_parse.cc:4604
#2  0x0000561d9d0865b2 in dispatch_sql_command (thd=0x7f87bc18c840, parser_state=0x7f8cfc4b1b90)
    at /data/codebase/stonedb80/stonedb/sql/sql_parse.cc:5239
#3  0x0000561d9d07c031 in dispatch_command (thd=0x7f87bc18c840, com_data=0x7f8cfc4b24e0, command=COM_QUERY)
    at /data/codebase/stonedb80/stonedb/sql/sql_parse.cc:1959
#4  0x0000561d9d07a0a8 in do_command (thd=0x7f87bc18c840) at /data/codebase/stonedb80/stonedb/sql/sql_parse.cc:1362
#5  0x0000561d9d2b694f in handle_connection (arg=0x561da53755c0)
    at /data/codebase/stonedb80/stonedb/sql/conn_handler/connection_handler_per_thread.cc:302
#6  0x0000561d9f1d86aa in pfs_spawn_thread (arg=0x561da7ab65f0) at /data/codebase/stonedb80/stonedb/storage/perfschema/pfs.cc:2942
#7  0x00007f8d277c9609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#8  0x00007f8d266d4133 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

(gdb) p ((Query_result_to_file*)lex->query_block->parent_lex)
$29 = (Query_result_to_file *) 0x7f87bc23a980
(gdb) p ((Query_result_to_file*)lex)
$30 = (Query_result_to_file *) 0x7f87bc23a980
(gdb) p *((Query_result_to_file*)lex->query_block->parent_lex->result)->exchange
$31 = {
  field = {
    field_term = 0x561da2ae3260 <default_field_term>,
    escaped = 0x561da2ae3240 <default_escaped>,
    enclosed = 0x561da2ae32a0 <my_empty_string>,
    opt_enclosed = false
  },
  line = {
    line_term = 0x561da2ae3220 <default_line_term>,
    line_start = 0x561da2ae32a0 <my_empty_string>
  },
  filetype = FILETYPE_CSV,
  file_name = 0x7f87bc0f5a98 "tmp_loaddata_file2",
  dumpfile = false,
  skip_lines = 0,
  cs = 0x0
}
(gdb)

@lujiashun
Copy link

lujiashun commented Sep 26, 2022

note:exexute select into outfile....clause.

(gdb) bt
#0  sql_exchange::sql_exchange (this=0x7f87bc20d660, name=0x7f8cfc4afba0 "\240\303 \274\207\177", flag=29,
    filetype_arg=(FILETYPE_MEM | unknown: 2637292324)) at /data/codebase/stonedb80/stonedb/sql/query_result.cc:126
#1  0x0000561d9d31e42f in PT_into_destination_outfile::PT_into_destination_outfile (this=0x7f87bc20d660, pos=..., file_name_arg=..., charset_arg=0x0,
    field_term_arg=..., line_term_arg=...) at /data/codebase/stonedb80/stonedb/sql/parse_tree_nodes.h:1169
#2  0x0000561d9d2fbc16 in MYSQLparse (YYTHD=0x7f87bc18c840, parse_tree=0x7f8cfc4b18c0) at sql_yacc.yy:12739
#3  0x0000561d9cf9dd34 in THD::sql_parser (this=0x7f87bc18c840) at /data/codebase/stonedb80/stonedb/sql/sql_class.cc:3037
#4  0x0000561d9d08b37e in parse_sql (thd=0x7f87bc18c840, parser_state=0x7f8cfc4b1b90, creation_ctx=0x0)
    at /data/codebase/stonedb80/stonedb/sql/sql_parse.cc:7056
#5  0x0000561d9d085fcd in dispatch_sql_command (thd=0x7f87bc18c840, parser_state=0x7f8cfc4b1b90)
    at /data/codebase/stonedb80/stonedb/sql/sql_parse.cc:5135
#6  0x0000561d9d07c031 in dispatch_command (thd=0x7f87bc18c840, com_data=0x7f8cfc4b24e0, command=COM_QUERY)
    at /data/codebase/stonedb80/stonedb/sql/sql_parse.cc:1959
#7  0x0000561d9d07a0a8 in do_command (thd=0x7f87bc18c840) at /data/codebase/stonedb80/stonedb/sql/sql_parse.cc:1362
#8  0x0000561d9d2b694f in handle_connection (arg=0x561da53755c0)
    at /data/codebase/stonedb80/stonedb/sql/conn_handler/connection_handler_per_thread.cc:302
#9  0x0000561d9f1d86aa in pfs_spawn_thread (arg=0x561da7ab65f0) at /data/codebase/stonedb80/stonedb/storage/perfschema/pfs.cc:2942
#10 0x00007f8d277c9609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#11 0x00007f8d266d4133 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
(gdb) n
128         : file_name(name), dumpfile(flag), skip_lines(0) {
(gdb) n
129       field.opt_enclosed = false;
(gdb) n
130       filetype = filetype_arg;
(gdb) n
131       field.field_term = &default_field_term;
(gdb) n
132       field.enclosed = line.line_start = &my_empty_string;
(gdb) n
134           filetype == FILETYPE_CSV ? &default_line_term : &default_xml_row_term;
(gdb) n
133       line.line_term =
(gdb) n
135       field.escaped = &default_escaped;
(gdb) p this
$32 = (sql_exchange * const) 0x7f87bc20d690
(gdb) p *this
$33 = {
  field = {
    field_term = 0x561da2ae3260 <default_field_term>,
    escaped = 0x8f8f8f8f8f8f8f8f,
    enclosed = 0x561da2ae32a0 <my_empty_string>,
    opt_enclosed = false
  },
  line = {
    line_term = 0x561da2ae3220 <default_line_term>,
    line_start = 0x561da2ae32a0 <my_empty_string>
  },
  filetype = FILETYPE_CSV,
  file_name = 0x7f87bc20d648 "tmp_loaddata_file3",
  dumpfile = false,
  skip_lines = 0,
  cs = 0x8f8f8f8f8f8f8f8f
}
(gdb)

@RingsC RingsC changed the title StoneDB 8.0: parent_lex->result in Engine::GetFilename is nullptr leads StoneDB to crash. feat(stonedb): parent_lex->result in Engine::GetFilename is nullptr leads StoneDB to crash. Sep 26, 2022
@lujiashun
Copy link

conclusiton:
in normal select clause: parent_lex->result is nullptr
in "select into outfile/dumpfile" clause: parent_lex->result is not nullptr

@lujiashun
Copy link

ACK

lujiashun pushed a commit to lujiashun/stonedb that referenced this issue Sep 26, 2022
…tr. (stoneatom#557)

[summary]
1 "SELECT ... INTO OUTFILE/DUMPFILE",parent_lex->result is not nullptr;
2 "SELECT ... FORM ",normal clause,parent_lex->result is nullptr;
3 parent_lex->result can be used to check the dumpfile,just to check null value;
@RingsC
Copy link
Contributor

RingsC commented Sep 26, 2022

the definition of parent_lex is listed below.
/// Reference to LEX that this query block belongs to
LEX *parent_lex{nullptr};

lujiashun pushed a commit to lujiashun/stonedb that referenced this issue Sep 27, 2022
…tr. (stoneatom#557)

[summary]
1 "SELECT ... INTO OUTFILE/DUMPFILE",parent_lex->result is not nullptr;
2 "SELECT ... FORM ",normal clause,parent_lex->result is nullptr;
3 parent_lex->result can be used to check the dumpfile,just to check null value;
mergify bot pushed a commit that referenced this issue Sep 27, 2022
…tr. (#557)

[summary]
1 "SELECT ... INTO OUTFILE/DUMPFILE",parent_lex->result is not nullptr;
2 "SELECT ... FORM ",normal clause,parent_lex->result is nullptr;
3 parent_lex->result can be used to check the dumpfile,just to check null value;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-feature feature with good idea C-stonedb-8.0 associated with stonedb 8.0
Projects
4 participants