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

bug: Server crashed, when execute select val, val >= '2010-02-22 18:35:23' from (select * from timetest) as A; #981

Closed
2 of 3 tasks
davidshiz opened this issue Nov 22, 2022 · 7 comments · Fixed by #1321
Closed
2 of 3 tasks
Assignees
Labels
A-bug Something isn't working B-SQL SQL layer B-stability Improve stonedb stabilization on different platform or arch prio: low Low priority

Comments

@davidshiz
Copy link
Collaborator

Have you read the Contributing Guidelines on issues?

Please confirm if bug report does NOT exists already ?

  • I confirm there is no existing issue for this

Describe the problem

mysql> select * from timetest;
+---------------------+
| val                 |
+---------------------+
| 2010-02-22 18:35:23 |
+---------------------+
1 row in set (0.00 sec)

mysql> select val, val >= '2010-02-22 18:35:23' from (select * from timetest) as A;
ERROR 2013 (HY000): Lost connection to MySQL server during query

Expected behavior

mysql> select val, val >= '2010-02-22 18:35:23' from (select * from timetest) as A;
+---------------------+------------------------------+
| val                 | val >= '2010-02-22 18:35:23' |
+---------------------+------------------------------+
| 2010-02-22 18:35:23 |                            1 |
+---------------------+------------------------------+
1 row in set (0.00 sec)

How To Reproduce

create table timetest (val timestamp) ENGINE=TIANMU;
insert into timetest values ('2010-02-22 18:35:23');
select val not between '2010-02-22 18:35:23' and '2015-11-23 08:02:45' from (select * from timetest) as A;
select val, val >= '2010-02-22 18:35:23' from (select * from timetest) as A;

Environment

root@ub01:/stonedb57/install/mysql-test# /stonedb57/install/bin/mysqld --version
/stonedb57/install/bin/mysqld  Ver 5.7.36-StoneDB-debug 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: 48afa0e19
        Last commit time: Date:   Fri Nov 18 03:22:27 2022 +0000
        Build time: Date: Mon Nov 21 20:13:41 CST 2022
root@ub01:~# cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.5 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.5 LTS"
VERSION_ID="20.04"

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

  • Yes, I will!
@davidshiz davidshiz added the A-bug Something isn't working label Nov 22, 2022
@davidshiz davidshiz changed the title bug: ERROR 2013 (HY000): Lost connection to MySQL server during query bug: Server crashed, when execute select val, val >= '2010-02-22 18:35:23' from (select * from timetest) as A; Nov 22, 2022
@davidshiz
Copy link
Collaborator Author

Only the debug version has this problem, the release version is correct

@RingsC
Copy link
Contributor

RingsC commented Nov 23, 2022

Maybe, assert failed.

@isredstar
Copy link
Collaborator

ACK

@isredstar
Copy link
Collaborator

stack info:

Protocol_text::store(Protocol_text * const this, MYSQL_TIME * tm, uint decimals) (\home\src\stonedb\sql\protocol_classic.cc:1439)
Item::send(Item * const this, Protocol * protocol, String * buffer) (\home\src\stonedb\sql\item.cc:7606)
THD::send_result_set_row(THD * const this, List<Item> * row_items) (\home\src\stonedb\sql\sql_class.cc:4757)
Query_result_send::send_data(Query_result_send * const this, List<Item> & items) (\home\src\stonedb\sql\sql_class.cc:2742)
Tianmu::core::ResultSender::SendRecord(Tianmu::core::ResultSender * const this, const std::vector<std::unique_ptr<Tianmu::types::TianmuDataType, std::default_delete<Tianmu::types::TianmuDataType> >, std::allocator<std::unique_ptr<Tianmu::types::TianmuDataType, std::default_delete<Tianmu::types::TianmuDataType> > > > & r) (\home\src\stonedb\storage\tianmu\core\engine_results.cpp:366)
Tianmu::core::ResultSender::SendRow(Tianmu::core::ResultSender * const this, const std::vector<std::unique_ptr<Tianmu::types::TianmuDataType, std::default_delete<Tianmu::types::TianmuDataType> >, std::allocator<std::unique_ptr<Tianmu::types::TianmuDataType, std::default_delete<Tianmu::types::TianmuDataType> > > > & record, Tianmu::core::TempTable * owner) (\home\src\stonedb\storage\tianmu\core\engine_results.cpp:269)
Tianmu::core::TempTable::SendResult(Tianmu::core::TempTable * const this, int64_t limit, int64_t offset, Tianmu::core::ResultSender & sender, bool pagewise) (\home\src\stonedb\storage\tianmu\core\temp_table_low.cpp:500)
Tianmu::core::TempTable::FillMaterializedBuffers(Tianmu::core::TempTable * const this, int64_t local_limit, int64_t local_offset, Tianmu::core::ResultSender * sender, bool pagewise) (\home\src\stonedb\storage\tianmu\core\temp_table_low.cpp:315)
Tianmu::core::TempTable::Materialize(Tianmu::core::TempTable * const this, bool in_subq, Tianmu::core::ResultSender * sender, bool lazy) (\home\src\stonedb\storage\tianmu\core\temp_table.cpp:2042)
Tianmu::core::Engine::Execute(Tianmu::core::Engine * const this, THD * thd, LEX * lex, Query_result * result_output, SELECT_LEX_UNIT * unit_for_union) (\home\src\stonedb\storage\tianmu\core\engine_execute.cpp:482)
Tianmu::core::Engine::HandleSelect(Tianmu::core::Engine * const this, THD * thd, LEX * lex, Query_result *& result, ulong setup_tables_done_option, int & res, int & optimize_after_tianmu, int & tianmu_free_join, int with_insert) (\home\src\stonedb\storage\tianmu\core\engine_execute.cpp:238)
Tianmu::handler::ha_my_tianmu_query(THD * thd, LEX * lex, Query_result *& result_output, ulong setup_tables_done_option, int & res, int & optimize_after_tianmu, int & tianmu_free_join, int with_insert) (\home\src\stonedb\storage\tianmu\handler\ha_my_tianmu.cpp:88)
execute_sqlcom_select(THD * thd, TABLE_LIST * all_tables) (\home\src\stonedb\sql\sql_parse.cc:5217)
mysql_execute_command(THD * thd, bool first_level) (\home\src\stonedb\sql\sql_parse.cc:2856)
mysql_parse(THD * thd, Parser_state * parser_state) (\home\src\stonedb\sql\sql_parse.cc:5655)
dispatch_command(THD * thd, const COM_DATA * com_data, enum_server_command command) (\home\src\stonedb\sql\sql_parse.cc:1495)
do_command(THD * thd) (\home\src\stonedb\sql\sql_parse.cc:1034)
handle_connection(void * arg) (\home\src\stonedb\sql\conn_handler\connection_handler_per_thread.cc:313)
pfs_spawn_thread(void * arg) (\home\src\stonedb\storage\perfschema\pfs.cc:2197)
libpthread.so.0!start_thread =

@isredstar
Copy link
Collaborator

assert(send_metadata || field_types == 0 ||
         is_temporal_type_with_date_and_time(field_types[field_pos]));

It's easy to see why occurs the problem.
The reason: error of assert code

@isredstar
Copy link
Collaborator

ResultSender::SendRecord function should call Item_field, but call Item_sum
item->type()==Item::FIELD_ITEM should be true

switch (item->type()) {
      case Item::DEFAULT_VALUE_ITEM:
      case Item::FIELD_ITEM:  // regular select
        ifield = (Item_field *)item;
        f = ifield->result_field;
        // if buf_lens[col_id] is 0 means that f->ptr was not assigned
        // because it was assigned for this instance of object
        if (buf_lens[col_id] != 0) {
          bitmap_set_bit(f->table->write_set, f->field_index);
          auto is_null = Engine::ConvertToField(f, tianmu_dt, nullptr);
          SetFieldState(f, is_null);
        }
        break;
      case Item::REF_ITEM:  // select from view
        iref = (Item_ref *)item;
        ifield = (Item_field *)(*iref->ref);
        f = ifield->result_field;
        if (buf_lens[col_id] != 0) {
          bitmap_set_bit(f->table->write_set, f->field_index);
          auto is_null = Engine::ConvertToField(f, tianmu_dt, nullptr);
          SetFieldState(f, is_null);
        }
        break;
      case Item::SUM_FUNC_ITEM:
        is = (Item_sum *)item;
        sum_type = is->sum_func();

        // used only MIN_FUNC
        if (sum_type == Item_sum::MIN_FUNC || sum_type == Item_sum::MAX_FUNC ||
            sum_type == Item_sum::GROUP_CONCAT_FUNC) {
          types::ItemSumHybridTianmuBase *isum_hybrid_rcbase = (types::ItemSumHybridTianmuBase *)is;
          if (isum_hybrid_rcbase->result_type() == DECIMAL_RESULT) {
            Engine::Convert(is_null, isum_hybrid_rcbase->dec_value(), tianmu_dt, item->decimals);
            isum_hybrid_rcbase->null_value = is_null;
          } else if (isum_hybrid_rcbase->result_type() == INT_RESULT) {
            Engine::Convert(is_null, isum_hybrid_rcbase->int64_value(), tianmu_dt,
                            isum_hybrid_rcbase->hybrid_field_type_);
            isum_hybrid_rcbase->null_value = is_null;
          } else if (isum_hybrid_rcbase->result_type() == REAL_RESULT) {
            Engine::Convert(is_null, isum_hybrid_rcbase->real_value(), tianmu_dt);
            isum_hybrid_rcbase->null_value = is_null;
          } else if (isum_hybrid_rcbase->result_type() == STRING_RESULT) {
            Engine::Convert(is_null, isum_hybrid_rcbase->string_value(), tianmu_dt,
                            isum_hybrid_rcbase->hybrid_field_type_);
            isum_hybrid_rcbase->null_value = is_null;
          }
          break;
        }
        // do not check COUNT_DISTINCT_FUNC, we use only this for both types
        if (sum_type == Item_sum::COUNT_FUNC || sum_type == Item_sum::SUM_BIT_FUNC) {
          isum_int_rcbase = (types::ItemSumInTianmuBase *)is;
          Engine::Convert(is_null, value, tianmu_dt, is->field_type());
          if (is_null)
            value = 0;
          isum_int_rcbase->int64_value(value);
          break;
        }
        if (sum_type == Item_sum::SUM_FUNC || sum_type == Item_sum::STD_FUNC || sum_type == Item_sum::VARIANCE_FUNC) {
          isum_sum_rcbase = (types::ItemSumSumTianmuBase *)is;
          if (isum_sum_rcbase->result_type() == DECIMAL_RESULT) {
            Engine::Convert(is_null, isum_sum_rcbase->dec_value(), tianmu_dt);
            isum_sum_rcbase->null_value = is_null;
          } else if (isum_sum_rcbase->result_type() == REAL_RESULT) {
            Engine::Convert(is_null, isum_sum_rcbase->real_value(), tianmu_dt);
            isum_sum_rcbase->null_value = is_null;
          }
          break;
        }
        break;
      default:
        // Const items like item_int etc. do not need any conversion
        break;
    }  // end switch
    col_id++;

@RingsC RingsC added this to the stonedb_5.7_v1.0.2 milestone Jan 6, 2023
@RingsC RingsC added the prio: high High priority label Jan 6, 2023
@wisehead
Copy link
Collaborator

wisehead commented Jan 9, 2023

the assert failure on DEBUG mode is not easy to fix on v1.0.2 on time, I move it to 1.0.3, @isredstar please follow on it.

@wisehead wisehead added B-SQL SQL layer B-stability Improve stonedb stabilization on different platform or arch labels Jan 9, 2023
@isredstar isredstar added prio: low Low priority and removed prio: high High priority labels Jan 13, 2023
@hustjieke hustjieke added B-storage data type, data storage, insert,update,delete, transactions and removed B-storage data type, data storage, insert,update,delete, transactions labels Jan 30, 2023
@wisehead wisehead assigned RingsC and unassigned isredstar Jan 31, 2023
@mergify mergify bot closed this as completed in #1321 Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-bug Something isn't working B-SQL SQL layer B-stability Improve stonedb stabilization on different platform or arch prio: low Low priority
Projects
5 participants