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: mysqld crash when HAVING 1 > 2; #1613

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 SIGSEGV, Segmentation fault.
[Switching to Thread 0x7f8475de0700 (LWP 2369048)]
0x000055e3dc2dd824 in Tianmu::core::Query::Compile (this=0x7f8475ddbff0, compiled_query=0x7f8475ddbf20, selects_list=0x7f7404004b60,
    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:1116
1116          if (Item::Type::SUBSELECT_ITEM == (conds->type())) {
(gdb) bt
#0  0x000055e3dc2dd824 in Tianmu::core::Query::Compile (this=0x7f8475ddbff0, compiled_query=0x7f8475ddbf20, selects_list=0x7f7404004b60,
    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:1116
#1  0x000055e3dc29e8ec in Tianmu::core::Engine::Execute (this=0x55e3de96bf70, thd=0x7f7404000e10, lex=0x7f7404003138,
    result_output=0x7f74040062a8, unit_for_union=0x0) at /stonedb/storage/tianmu/core/engine_execute.cpp:448
#2  0x000055e3dc29dabe in Tianmu::core::Engine::HandleSelect (this=0x55e3de96bf70, thd=0x7f7404000e10, lex=0x7f7404003138,
    result=@0x7f8475ddc498: 0x7f74040062a8, setup_tables_done_option=0, res=@0x7f8475ddc48c: 32628,
    is_optimize_after_tianmu=@0x7f8475ddc494: 1, tianmu_free_join=@0x7f8475ddc490: 1, with_insert=0)
    at /stonedb/storage/tianmu/core/engine_execute.cpp:243
#3  0x000055e3dc691667 in Tianmu::DBHandler::ha_my_tianmu_query (thd=0x7f7404000e10, lex=0x7f7404003138,
    result_output=@0x7f8475ddc498: 0x7f74040062a8, setup_tables_done_option=0, res=@0x7f8475ddc48c: 32628,
    is_optimize_after_tianmu=@0x7f8475ddc494: 1, tianmu_free_join=@0x7f8475ddc490: 1, with_insert=0)
    at /stonedb/storage/tianmu/sql/ha_my_tianmu.cpp:95
#4  0x000055e3db9369b2 in execute_sqlcom_select (thd=0x7f7404000e10, all_tables=0x7f7404005ac0) at /stonedb/sql/sql_parse.cc:5204
#5  0x000055e3db92fa21 in mysql_execute_command (thd=0x7f7404000e10, first_level=true) at /stonedb/sql/sql_parse.cc:2847
#6  0x000055e3db937a40 in mysql_parse (thd=0x7f7404000e10, parser_state=0x7f8475ddd630) at /stonedb/sql/sql_parse.cc:5642
#7  0x000055e3db92c5e1 in dispatch_command (thd=0x7f7404000e10, com_data=0x7f8475dddee0, command=COM_QUERY)
    at /stonedb/sql/sql_parse.cc:1495
#8  0x000055e3db92b458 in do_command (thd=0x7f7404000e10) at /stonedb/sql/sql_parse.cc:1034
#9  0x000055e3dba74b1e in handle_connection (arg=0x55e3e9300b90) at /stonedb/sql/conn_handler/connection_handler_per_thread.cc:313
#10 0x000055e3dc1c09cf in pfs_spawn_thread (arg=0x55e3e91fca00) at /stonedb/storage/perfschema/pfs.cc:2197
#11 0x00007f84c231d609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#12 0x00007f84c20f1133 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Expected behavior

No response

How To Reproduce

CREATE TABLE test_having (a int, b int, c char(8), d char);
INSERT INTO test_having VALUES (0, 1, 'XXXX', 'A');
SELECT 1 AS one FROM test_having HAVING 1 > 2;

Environment

root@ub01:/stonedb57/install/bin# ./mysqld --version
./mysqld  Ver 5.7.36-StoneDB-v1.0.3.31919be01 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: 31919be01
        Last commit time: Date:   Thu Apr 20 10:19:54 2023 +0800
        Build time: Date: Sun Apr 23 17:43:35 CST 2023

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

hustjieke commented 1 year ago

In StoneDB 8.0, return syntax not supported:

mysql> CREATE TABLE test_having (a int, b int, c char(8), d char);
Query OK, 0 rows affected (0.04 sec)

mysql> INSERT INTO test_having VALUES (0, 1, 'XXXX', 'A');
Query OK, 1 row affected (0.06 sec)

mysql> SELECT 1 AS one FROM test_having HAVING 1 > 2;
ERROR 6 (HY000): The query includes syntax that is not supported by the storage engine. Either restructure the query with supported syntax, or enable the MySQL core::Query Path in config file to execute the query with reduced performance.
mysql> SELECT 1 FROM test_having HAVING 1 > 2;
hustjieke commented 1 year ago

In StoneDB 8.0, return syntax not supported:

mysql> CREATE TABLE test_having (a int, b int, c char(8), d char);
Query OK, 0 rows affected (0.04 sec)

mysql> INSERT INTO test_having VALUES (0, 1, 'XXXX', 'A');
Query OK, 1 row affected (0.06 sec)

mysql> SELECT 1 AS one FROM test_having HAVING 1 > 2;
ERROR 6 (HY000): The query includes syntax that is not supported by the storage engine. Either restructure the query with supported syntax, or enable the MySQL core::Query Path in config file to execute the query with reduced performance.
mysql> SELECT 1 FROM test_having HAVING 1 > 2;

having 1 > 2 not supported in 8.0, not in 5.7.

davidshiz commented 1 year ago

this scenario also crash

CREATE TABLE t1 (a int);
INSERT INTO t1 VALUES (1), (2), (1), (3), (2), (1);
SELECT a FROM t1 GROUP BY a HAVING 1 != 1 AND a > 1;
davidshiz commented 1 year ago

add crash scenario

CREATE TABLE t1(f1 INT, f2 INT);
INSERT INTO t1 VALUES (10,8);
CREATE TABLE t2 (f1 INT);
INSERT INTO t2 VALUES (5);
SELECT  COUNT(f1) FROM t2
HAVING (7, 9)  IN (SELECT f1, MIN(f2) FROM t1);
#0  0x0000000002d251c2 in Tianmu::core::Query::Compile (this=0x7fc31abd67d0, compiled_query=0x7fc31abd6700, selects_list=0x7fbdd8067f30, 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 /root/work/stonedb-dev-20230506/storage/tianmu/core/query_compile.cpp:1116
#1  0x0000000002ceb42c in Tianmu::core::Engine::Execute (this=0x66bf7a0, thd=0x7fbdd80636d0, lex=0x7fbdd80659f8, result_output=0x7fbdd8d30e30, unit_for_union=0x0)
    at /root/work/stonedb-dev-20230506/storage/tianmu/core/engine_execute.cpp:472
#2  0x0000000002cea5b5 in Tianmu::core::Engine::HandleSelect (this=0x66bf7a0, thd=0x7fbdd80636d0, lex=0x7fbdd80659f8, result=@0x7fc31abd6dc8: 0x7fbdd8d30e30, setup_tables_done_option=0, 
    res=@0x7fc31abd6dc4: 0, is_optimize_after_tianmu=@0x7fc31abd6dbc: 1, tianmu_free_join=@0x7fc31abd6dc0: 1, with_insert=0) at /root/work/stonedb-dev-20230506/storage/tianmu/core/engine_execute.cpp:243
#3  0x0000000003083b76 in Tianmu::DBHandler::ha_my_tianmu_query (thd=0x7fbdd80636d0, lex=0x7fbdd80659f8, result_output=@0x7fc31abd6dc8: 0x7fbdd8d30e30, setup_tables_done_option=0, res=@0x7fc31abd6dc4: 0, 
    is_optimize_after_tianmu=@0x7fc31abd6dbc: 1, tianmu_free_join=@0x7fc31abd6dc0: 1, with_insert=0) at /root/work/stonedb-dev-20230506/storage/tianmu/sql/ha_my_tianmu.cpp:95
#4  0x000000000242789c in execute_sqlcom_select (thd=0x7fbdd80636d0, all_tables=0x7fbdd8d2fb10) at /root/work/stonedb-dev-20230506/sql/sql_parse.cc:5204
#5  0x0000000002420c12 in mysql_execute_command (thd=0x7fbdd80636d0, first_level=true) at /root/work/stonedb-dev-20230506/sql/sql_parse.cc:2847
#6  0x0000000002428901 in mysql_parse (thd=0x7fbdd80636d0, parser_state=0x7fc31abd7f90) at /root/work/stonedb-dev-20230506/sql/sql_parse.cc:5642
#7  0x000000000241d8f8 in dispatch_command (thd=0x7fbdd80636d0, com_data=0x7fc31abd8730, command=COM_QUERY) at /root/work/stonedb-dev-20230506/sql/sql_parse.cc:1495
#8  0x000000000241c739 in do_command (thd=0x7fbdd80636d0) at /root/work/stonedb-dev-20230506/sql/sql_parse.cc:1034
#9  0x000000000254eccf in handle_connection (arg=0xb7bcc50) at /root/work/stonedb-dev-20230506/sql/conn_handler/connection_handler_per_thread.cc:313
#10 0x0000000002c1e50e in pfs_spawn_thread (arg=0xb134420) at /root/work/stonedb-dev-20230506/storage/perfschema/pfs.cc:2197
#11 0x00007fc3250c31ca in start_thread () from /lib64/libpthread.so.0
#12 0x00007fc321d42e73 in clone () from /lib64/libc.so.6