stoneatom / stonedb

StoneDB is an Open-Source MySQL HTAP and MySQL-Native DataBase for OLTP, Real-Time Analytics, a counterpart of MySQLHeatWave. (https://stonedb.io)
https://stonedb.io/
GNU General Public License v2.0
861 stars 139 forks source link

bug: debug version, mysqld crash when processing timestamp type #1480

Open davidshiz opened 1 year ago

davidshiz commented 1 year ago

Have you read the Contributing Guidelines on issues?

Please confirm if bug report does NOT exists already ?

Describe the problem

Thread 152 "mysqld" received signal SIGABRT, Aborted.
[Switching to Thread 0x7f4e2e8ac700 (LWP 84216)]
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
50      ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0x00007f4e35153859 in __GI_abort () at abort.c:79
#2  0x00007f4e35153729 in __assert_fail_base (fmt=0x7f4e352e9588 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n",
    assertion=0x5575c30e0188 "NULL != dynamic_cast<Target>(arg)", file=0x5575c30e0160 "/stonedb/include/template_utils.h", line=85, function=<optimized out>)
    at assert.c:92
#3  0x00007f4e35164fd6 in __GI___assert_fail (assertion=0x5575c30e0188 "NULL != dynamic_cast<Target>(arg)", file=0x5575c30e0160 "/stonedb/include/template_utils.h",
    line=85, function=0x5575c30e0210 "Target down_cast(Source) [with Target = const Item_func_in*; Source = const Item*]") at assert.c:101
#4  0x00005575c28ad002 in down_cast<Item_func_in const*, Item const*> (arg=0x7f3d80007918) at /stonedb/include/template_utils.h:85
#5  0x00005575c28ab2ea in Tianmu::core::operator== (left=..., right=...) at /stonedb/storage/tianmu/core/mysql_expression.cpp:635
#6  0x00005575c28ab77a in Tianmu::core::MysqlExpression::operator== (this=0x7f3d808fa630, other=...) at /stonedb/storage/tianmu/core/mysql_expression.cpp:686
#7  0x00005575c24dc616 in Tianmu::core::Query::VirtualColumnAlreadyExists (this=0x7f4e2e8a8000, tmp_table=..., expression=0x7f3d808f9ec0)
    at /stonedb/storage/tianmu/core/query.cpp:140
#8  0x00005575c2509bb8 in Tianmu::core::Query::AddColumnForMysqlExpression (this=0x7f4e2e8a8000, mysql_expression=0x7f3d808f9ec0, tmp_table=...,
    alias=0x7f3d80007b10 "TO_DAYS(a)", oper=Tianmu::common::ColOperation::LISTING, distinct=false, group_by=false)
    at /stonedb/storage/tianmu/core/query_compile.cpp:933
#9  0x00005575c2506c6a in Tianmu::core::Query::AddFields (this=0x7f4e2e8a8000, fields=..., tmp_table=..., base_table=..., group_by_clause=false,
    num_of_added_fields=@0x7f4e2e8a7c80: 0, ignore_minmax=false, aggregation_used=@0x7f4e2e8a7c76: false) at /stonedb/storage/tianmu/core/query_compile.cpp:507
#10 0x00005575c250ab0a in Tianmu::core::Query::Compile (this=0x7f4e2e8a8000, compiled_query=0x7f4e2e8a7f30, selects_list=0x7f3d80005c00, last_distinct=0x0,
    res_tab=0x0, ignore_limit=false, left_expr_for_subselect=0x0, oper_for_subselect=0x0, ignore_minmax=false, for_subq_in_where=false)
    at /stonedb/storage/tianmu/core/query_compile.cpp:1206
#11 0x00005575c24c081c in Tianmu::core::Engine::Execute (this=0x5575c6f15640, thd=0x7f3d80000e10, lex=0x7f3d80003138, result_output=0x7f3d8001b760,
    unit_for_union=0x0) at /stonedb/storage/tianmu/core/engine_execute.cpp:443
#12 0x00005575c24bf9f1 in Tianmu::core::Engine::HandleSelect (this=0x5575c6f15640, thd=0x7f3d80000e10, lex=0x7f3d80003138, result=@0x7f4e2e8a8498: 0x7f3d8001b760,
    setup_tables_done_option=0, res=@0x7f4e2e8a848c: 32573, is_optimize_after_tianmu=@0x7f4e2e8a8494: 1, tianmu_free_join=@0x7f4e2e8a8490: 1, with_insert=0)
    at /stonedb/storage/tianmu/core/engine_execute.cpp:238
#13 0x00005575c25ea178 in Tianmu::DBHandler::ha_my_tianmu_query (thd=0x7f3d80000e10, lex=0x7f3d80003138, result_output=@0x7f4e2e8a8498: 0x7f3d8001b760,
    setup_tables_done_option=0, res=@0x7f4e2e8a848c: 32573, is_optimize_after_tianmu=@0x7f4e2e8a8494: 1, tianmu_free_join=@0x7f4e2e8a8490: 1, with_insert=0)
    at /stonedb/storage/tianmu/handler/ha_my_tianmu.cpp:89
#14 0x00005575c1b589b2 in execute_sqlcom_select (thd=0x7f3d80000e10, all_tables=0x7f3d8001b110) at /stonedb/sql/sql_parse.cc:5204
#15 0x00005575c1b51a21 in mysql_execute_command (thd=0x7f3d80000e10, first_level=true) at /stonedb/sql/sql_parse.cc:2847
#16 0x00005575c1b59a40 in mysql_parse (thd=0x7f3d80000e10, parser_state=0x7f4e2e8a9630) at /stonedb/sql/sql_parse.cc:5642
#17 0x00005575c1b4e5e1 in dispatch_command (thd=0x7f3d80000e10, com_data=0x7f4e2e8a9ee0, command=COM_QUERY) at /stonedb/sql/sql_parse.cc:1495
#18 0x00005575c1b4d458 in do_command (thd=0x7f3d80000e10) at /stonedb/sql/sql_parse.cc:1034
#19 0x00005575c1c96b1e in handle_connection (arg=0x5575cf7cb0d0) at /stonedb/sql/conn_handler/connection_handler_per_thread.cc:313
#20 0x00005575c23e29cf in pfs_spawn_thread (arg=0x5575cf6ae1c0) at /stonedb/storage/perfschema/pfs.cc:2197
#21 0x00007f4e3547c609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#22 0x00007f4e35250133 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Expected behavior

No response

How To Reproduce

CREATE TABLE ctimestamp (a timestamp);
INSERT INTO ctimestamp VALUES ('2019-01-02 00:02:03'),
('2019-01-02 01:02:03'), ('2019-01-02 10:11:12');
INSERT INTO ctimestamp VALUES ('2020-01-03 12:12:12'),
('2020-05-06 12:12:12'), ('2020-10-28 12:12:12');
SELECT TRUNCATE(a, -2), a IN ('2019-01-02 01:02:03', a), TO_DAYS(a), DAY(a) from ctimestamp;

Environment

root@ub01:~# /stonedb57/install/bin/mysqld --version
/stonedb57/install/bin/mysqld  Ver 5.7.36-StoneDB-v1.0.3.05db04de4 for Linux on x86_64 (build-)
build information as follow:
        Repository address: https://github.com/stoneatom/stonedb.git:stonedb-5.7-dev
        Branch name: stonedb-5.7-dev
        Last commit ID: 05db04de4
        Last commit time: Date:   Wed Mar 22 21:09:55 2023 +0800
        Build time: Date: Mon Mar 27 14:06:28 CST 2023

Are you interested in submitting a PR to solve the problem?

hustjieke commented 1 year ago

Simplify sql:

mysql> SELECT a IN ('2019-01-02 01:02:03', a), TO_DAYS(a) from ctimestamp;

Crashed happened in function down_cast-->assert():

/**
  Casts from one pointer type to another in a type hierarchy.
  In debug mode, we verify the cast is indeed legal.
 */
template<typename Target, typename Source>
inline Target down_cast(Source arg)
{
  assert(NULL != dynamic_cast<Target>(arg));
  return static_cast<Target>(arg);
}
libc.so.6!__GI_raise(int sig) (/build/glibc-SzIz7B/glibc-2.31/sysdeps/unix/sysv/linux/raise.c:50)
libc.so.6!__GI_abort() (/build/glibc-SzIz7B/glibc-2.31/stdlib/abort.c:79)
libc.so.6!__assert_fail_base(const char * fmt, const char * assertion, const char * file, unsigned int line, const char * function) (/build/glibc-SzIz7B/glibc-2.31/assert/assert.c:92)
libc.so.6!__GI___assert_fail(const char * assertion, const char * file, unsigned int line, const char * function) (/build/glibc-SzIz7B/glibc-2.31/assert/assert.c:101)
down_cast<Item_func_in const*, Item const*>(const Item * arg) (/github/stonedb/include/template_utils.h:85)
Tianmu::core::operator==(const Item & left, const Item & right) (/github/stonedb/storage/tianmu/core/mysql_expression.cpp:635)
Tianmu::core::MysqlExpression::operator==(const Tianmu::core::MysqlExpression * const this, const Tianmu::core::MysqlExpression & other) (/github/stonedb/storage/tianmu/core/mysql_expression.cpp:686)
Tianmu::core::Query::VirtualColumnAlreadyExists(Tianmu::core::Query * const this, const Tianmu::core::TabID & tmp_table, Tianmu::core::MysqlExpression * expression) (/github/stonedb/storage/tianmu/core/query.cpp:140)
Tianmu::core::Query::AddColumnForMysqlExpression(Tianmu::core::Query * const this, Tianmu::core::MysqlExpression * mysql_expression, const Tianmu::core::TabID & tmp_table, const char * alias, const Tianmu::common::ColOperation oper, const bool distinct, bool group_by) (/github/stonedb/storage/tianmu/core/query_compile.cpp:933)
Tianmu::core::Query::AddFields(Tianmu::core::Query * const this, List<Item> & fields, const Tianmu::core::TabID & tmp_table, const Tianmu::core::TabID & base_table, const bool group_by_clause, int & num_of_added_fields, bool ignore_minmax, bool & aggregation_used) (/github/stonedb/storage/tianmu/core/query_compile.cpp:507)
Tianmu::core::Query::Compile(Tianmu::core::Query * const this, Tianmu::core::CompiledQuery * compiled_query, SELECT_LEX * selects_list, SELECT_LEX * last_distinct, Tianmu::core::TabID * res_tab, bool ignore_limit, Item * left_expr_for_subselect, Tianmu::common::Operator * oper_for_subselect, bool ignore_minmax, bool for_subq_in_where) (/github/stonedb/storage/tianmu/core/query_compile.cpp:1210)
Tianmu::core::Engine::Execute(Tianmu::core::Engine * const this, THD * thd, LEX * lex, Query_result * result_output, SELECT_LEX_UNIT * unit_for_union) (/github/stonedb/storage/tianmu/core/engine_execute.cpp:472)
Tianmu::core::Engine::HandleSelect(Tianmu::core::Engine * const this, THD * thd, LEX * lex, Query_result *& result, ulong setup_tables_done_option, int & res, int & is_optimize_after_tianmu, int & tianmu_free_join, int with_insert) (/github/stonedb/storage/tianmu/core/engine_execute.cpp:243)
Tianmu::DBHandler::ha_my_tianmu_query(THD * thd, LEX * lex, Query_result *& result_output, ulong setup_tables_done_option, int & res, int & is_optimize_after_tianmu, int & tianmu_free_join, int with_insert) (/github/stonedb/storage/tianmu/sql/ha_my_tianmu.cpp:95)
execute_sqlcom_select(THD * thd, TABLE_LIST * all_tables) (/github/stonedb/sql/sql_parse.cc:5204)
mysql_execute_command(THD * thd, bool first_level) (/github/stonedb/sql/sql_parse.cc:2847)
mysql_parse(THD * thd, Parser_state * parser_state) (/github/stonedb/sql/sql_parse.cc:5642)
dispatch_command(THD * thd, const COM_DATA * com_data, enum_server_command command) (/github/stonedb/sql/sql_parse.cc:1495)
do_command(THD * thd) (/github/stonedb/sql/sql_parse.cc:1034)
handle_connection(void * arg) (/github/stonedb/sql/conn_handler/connection_handler_per_thread.cc:313)