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

feature: Implement the bit data type #919

Closed
lylth opened this issue Nov 10, 2022 · 7 comments
Closed

feature: Implement the bit data type #919

lylth opened this issue Nov 10, 2022 · 7 comments
Assignees
Labels
A-feature feature with good idea prio: high High priority

Comments

@lylth
Copy link
Contributor

lylth commented Nov 10, 2022

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

  1. The bit data type is used in the CUSG user business
  2. StnoeDB needs to be 100% compatible with MySQl

Describe the solution you'd like

Describe alternatives you've considered

Additional context

@lylth lylth added the A-feature feature with good idea label Nov 10, 2022
@lylth
Copy link
Contributor Author

lylth commented Nov 11, 2022

BIT data type of innodb

The BIT data type is used to store bit values. A type of BIT(M) enables storage of M-bit values. M can
range from 1 to 64.
To specify bit values, b'value' notation can be used. value is a binary value written using zeros and
ones. For example, b'111' and b'10000000' represent 7 and 128, respectively. 
If you assign a value to a BIT(M) column that is less than M bits long, the value is padded on the left
with zeros. For example, assigning a value of b'101' to a BIT(6) column is, in effect, the same as
assigning b'000101'.

@lylth
Copy link
Contributor Author

lylth commented Nov 15, 2022

Overview

To implement the BIT data type, we need to implement related functions in three processes: create table process, insert data process, and query process.

1. Create table processing flow

Increase the processing of BIT field attributes when creating a table

Tianmu::core::Engine::GetAttrTypeInfo(const Field & field) (\opt\litaihong\stonedb\storage\tianmu\core\engine.cpp:759)
Tianmu::core::Engine::GetTableOption(Tianmu::core::Engine * const this, const std::string & table, TABLE * form) (\opt\litaihong\stonedb\storage\tianmu\core\engine.cpp:628)
Tianmu::core::Engine::CreateTable(Tianmu::core::Engine * const this, const std::string & table, TABLE * form) (\opt\litaihong\stonedb\storage\tianmu\core\engine.cpp:636)
Tianmu::dbhandler::TianmuHandler::create(Tianmu::dbhandler::TianmuHandler * const this, const char * name, TABLE * table_arg, HA_CREATE_INFO * create_info) (\opt\litaihong\stonedb\storage\tianmu\handler\tianmu_handler.cpp:1223)
handler::ha_create(handler * const this, const char * name, TABLE * form, HA_CREATE_INFO * info) (\opt\litaihong\stonedb\sql\handler.cc:5020)
ha_create_table(THD * thd, const char * path, const char * db, const char * table_name, HA_CREATE_INFO * create_info, bool update_create_info, bool is_temp_table) (\opt\litaihong\stonedb\sql\handler.cc:5179)
rea_create_table(THD * thd, const char * path, const char * db, const char * table_name, HA_CREATE_INFO * create_info, List<Create_field> & create_fields, uint keys, KEY * key_info, handler * file, bool no_ha_table) (\opt\litaihong\stonedb\sql\unireg.cc:563)
create_table_impl(THD * thd, const char * db, const char * table_name, const char * error_table_name, const char * path, HA_CREATE_INFO * create_info, Alter_info * alter_info, bool internal_tmp_table, uint select_field_count, bool no_ha_table, bool * is_trans, KEY ** key_info, uint * key_count) (\opt\litaihong\stonedb\sql\sql_table.cc:5353)
mysql_create_table_no_lock(THD * thd, const char * db, const char * table_name, HA_CREATE_INFO * create_info, Alter_info * alter_info, uint select_field_count, bool * is_trans) (\opt\litaihong\stonedb\sql\sql_table.cc:5483)
mysql_create_table(THD * thd, TABLE_LIST * create_table, HA_CREATE_INFO * create_info, Alter_info * alter_info) (\opt\litaihong\stonedb\sql\sql_table.cc:5527)
mysql_execute_command(THD * thd, bool first_level) (\opt\litaihong\stonedb\sql\sql_parse.cc:3299)
mysql_parse(THD * thd, Parser_state * parser_state) (\opt\litaihong\stonedb\sql\sql_parse.cc:5621)
dispatch_command(THD * thd, const COM_DATA * com_data, enum_server_command command) (\opt\litaihong\stonedb\sql\sql_parse.cc:1495)
do_command(THD * thd) (\opt\litaihong\stonedb\sql\sql_parse.cc:1034)
handle_connection(void * arg) (\opt\litaihong\stonedb\sql\conn_handler\connection_handler_per_thread.cc:313)
pfs_spawn_thread(void * arg) (\opt\litaihong\stonedb\storage\perfschema\pfs.cc:2197)

Add BIT data type:

Tianmu::core::Engine::GetCorrespondingType(const enum_field_types & eft) (\opt\litaihong\stonedb\storage\tianmu\core\engine_convert.cpp:568)
Tianmu::core::Engine::GetCorrespondingType(const Field & field) (\opt\litaihong\stonedb\storage\tianmu\core\engine_convert.cpp:575)
Tianmu::core::Engine::GetAttrTypeInfo(const Field & field) (\opt\litaihong\stonedb\storage\tianmu\core\engine.cpp:760)
Tianmu::core::Engine::GetTableOption(Tianmu::core::Engine * const this, const std::string & table, TABLE * form) (\opt\litaihong\stonedb\storage\tianmu\core\engine.cpp:628)
Tianmu::core::Engine::CreateTable(Tianmu::core::Engine * const this, const std::string & table, TABLE * form) (\opt\litaihong\stonedb\storage\tianmu\core\engine.cpp:636)
Tianmu::dbhandler::TianmuHandler::create(Tianmu::dbhandler::TianmuHandler * const this, const char * name, TABLE * table_arg, HA_CREATE_INFO * create_info) (\opt\litaihong\stonedb\storage\tianmu\handler\tianmu_handler.cpp:1223)
handler::ha_create(handler * const this, const char * name, TABLE * form, HA_CREATE_INFO * info) (\opt\litaihong\stonedb\sql\handler.cc:5020)
ha_create_table(THD * thd, const char * path, const char * db, const char * table_name, HA_CREATE_INFO * create_info, bool update_create_info, bool is_temp_table) (\opt\litaihong\stonedb\sql\handler.cc:5179)
rea_create_table(THD * thd, const char * path, const char * db, const char * table_name, HA_CREATE_INFO * create_info, List<Create_field> & create_fields, uint keys, KEY * key_info, handler * file, bool no_ha_table) (\opt\litaihong\stonedb\sql\unireg.cc:563)
create_table_impl(THD * thd, const char * db, const char * table_name, const char * error_table_name, const char * path, HA_CREATE_INFO * create_info, Alter_info * alter_info, bool internal_tmp_table, uint select_field_count, bool no_ha_table, bool * is_trans, KEY ** key_info, uint * key_count) (\opt\litaihong\stonedb\sql\sql_table.cc:5353)
mysql_create_table_no_lock(THD * thd, const char * db, const char * table_name, HA_CREATE_INFO * create_info, Alter_info * alter_info, uint select_field_count, bool * is_trans) (\opt\litaihong\stonedb\sql\sql_table.cc:5483)
mysql_create_table(THD * thd, TABLE_LIST * create_table, HA_CREATE_INFO * create_info, Alter_info * alter_info) (\opt\litaihong\stonedb\sql\sql_table.cc:5527)
mysql_execute_command(THD * thd, bool first_level) (\opt\litaihong\stonedb\sql\sql_parse.cc:3299)
mysql_parse(THD * thd, Parser_state * parser_state) (\opt\litaihong\stonedb\sql\sql_parse.cc:5621)
dispatch_command(THD * thd, const COM_DATA * com_data, enum_server_command command) (\opt\litaihong\stonedb\sql\sql_parse.cc:1495)
do_command(THD * thd) (\opt\litaihong\stonedb\sql\sql_parse.cc:1034)
handle_connection(void * arg) (\opt\litaihong\stonedb\sql\conn_handler\connection_handler_per_thread.cc:313)
pfs_spawn_thread(void * arg) (\opt\litaihong\stonedb\storage\perfschema\pfs.cc:2197)

2.Insert flow processing

Tianmu::core::Engine::EncodeRecord(Tianmu::core::Engine * const this, const std::string & table_path, int tid, Field ** field, size_t col, size_t blobs, std::unique_ptr<char [], std::default_delete<char []> > & buf, uint32_t & size) (\opt\litaihong\stonedb\storage\tianmu\core\engine.cpp:429)
Tianmu::core::Engine::InsertMemRow(Tianmu::core::Engine * const this, const std::string & table_path, std::shared_ptr<Tianmu::core::TableShare> & share, TABLE * table) (\opt\litaihong\stonedb\storage\tianmu\core\engine.cpp:1457)
Tianmu::core::Engine::InsertRow(Tianmu::core::Engine * const this, const std::string & table_path, Tianmu::core::Transaction * trans_, TABLE * table, std::shared_ptr<Tianmu::core::TableShare> & share) (\opt\litaihong\stonedb\storage\tianmu\core\engine.cpp:1469)
Tianmu::dbhandler::TianmuHandler::write_row(Tianmu::dbhandler::TianmuHandler * const this, uchar * buf) (\opt\litaihong\stonedb\storage\tianmu\handler\tianmu_handler.cpp:424)
handler::ha_write_row(handler * const this, uchar * buf) (\opt\litaihong\stonedb\sql\handler.cc:8188)
write_record(THD * thd, TABLE * table, COPY_INFO * info, COPY_INFO * update) (\opt\litaihong\stonedb\sql\sql_insert.cc:1902)
Sql_cmd_insert::mysql_insert(Sql_cmd_insert * const this, THD * thd, TABLE_LIST * table_list) (\opt\litaihong\stonedb\sql\sql_insert.cc:776)
Sql_cmd_insert::execute(Sql_cmd_insert * const this, THD * thd) (\opt\litaihong\stonedb\sql\sql_insert.cc:3149)
mysql_execute_command(THD * thd, bool first_level) (\opt\litaihong\stonedb\sql\sql_parse.cc:3619)
mysql_parse(THD * thd, Parser_state * parser_state) (\opt\litaihong\stonedb\sql\sql_parse.cc:5621)
dispatch_command(THD * thd, const COM_DATA * com_data, enum_server_command command) (\opt\litaihong\stonedb\sql\sql_parse.cc:1495)
do_command(THD * thd) (\opt\litaihong\stonedb\sql\sql_parse.cc:1034)
handle_connection(void * arg) (\opt\litaihong\stonedb\sql\conn_handler\connection_handler_per_thread.cc:313)
pfs_spawn_thread(void * arg) (\opt\litaihong\stonedb\storage\perfschema\pfs.cc:2197)

3、query process

Added BIT data type and handling of correction values.

Tianmu::core::DataType::DataType(Tianmu::core::DataType * const this, Tianmu::common::CT atype, int prec, int scale, DTCollation collation) (\opt\litaihong\stonedb\storage\tianmu\core\data_type.cpp:90)
Tianmu::core::DataType::operator=(Tianmu::core::DataType * const this, const Tianmu::core::ColumnType & ct) (\opt\litaihong\stonedb\storage\tianmu\core\data_type.cpp:108)
Tianmu::vcolumn::ExpressionColumn::ExpressionColumn(Tianmu::vcolumn::ExpressionColumn * const this, Tianmu::core::MysqlExpression * expr, Tianmu::core::TempTable * temp_table, int temp_table_alias, Tianmu::core::MultiIndex * mind) (\opt\litaihong\stonedb\storage\tianmu\vc\expr_column.cpp:48)
Tianmu::core::Query::CreateColumnFromExpression(Tianmu::core::Query * const this, const std::vector<Tianmu::core::MysqlExpression*, std::allocator<Tianmu::core::MysqlExpression*> > & exprs, Tianmu::core::TempTable * temp_table, int temp_table_alias, Tianmu::core::MultiIndex * mind) (\opt\litaihong\stonedb\storage\tianmu\core\query.cpp:489)
Tianmu::core::Query::Preexecute(Tianmu::core::Query * const this, Tianmu::core::CompiledQuery & qu, Tianmu::core::ResultSender * sender, bool display_now) (\opt\litaihong\stonedb\storage\tianmu\core\query.cpp:802)
Tianmu::core::Engine::Execute(Tianmu::core::Engine * const this, THD * thd, LEX * lex, Query_result * result_output, SELECT_LEX_UNIT * unit_for_union) (\opt\litaihong\stonedb\storage\tianmu\core\engine_execute.cpp:421)
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) (\opt\litaihong\stonedb\storage\tianmu\core\engine_execute.cpp:232)
Tianmu::dbhandler::TIANMU_HandleSelect(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) (\opt\litaihong\stonedb\storage\tianmu\handler\ha_rcengine.cpp:82)
execute_sqlcom_select(THD * thd, TABLE_LIST * all_tables) (\opt\litaihong\stonedb\sql\sql_parse.cc:5182)
mysql_execute_command(THD * thd, bool first_level) (\opt\litaihong\stonedb\sql\sql_parse.cc:2831)
mysql_parse(THD * thd, Parser_state * parser_state) (\opt\litaihong\stonedb\sql\sql_parse.cc:5621)
dispatch_command(THD * thd, const COM_DATA * com_data, enum_server_command command) (\opt\litaihong\stonedb\sql\sql_parse.cc:1495)
do_command(THD * thd) (\opt\litaihong\stonedb\sql\sql_parse.cc:1034)
handle_connection(void * arg) (\opt\litaihong\stonedb\sql\conn_handler\connection_handler_per_thread.cc:313)
pfs_spawn_thread(void * arg) (\opt\litaihong\stonedb\storage\perfschema\pfs.cc:2197)

Get the value of the bit data type

Tianmu::core::Item_tianmufield::SetType(Tianmu::core::Item_tianmufield * const this, Tianmu::core::DataType t) (\opt\litaihong\stonedb\storage\tianmu\core\item_tianmu_field.cpp:67)
Tianmu::core::MysqlExpression::EvalType(Tianmu::core::MysqlExpression * const this, Tianmu::core::MysqlExpression::TypOfVars * tv) (\opt\litaihong\stonedb\storage\tianmu\core\mysql_expression.cpp:377)
Tianmu::vcolumn::ExpressionColumn::ExpressionColumn(Tianmu::vcolumn::ExpressionColumn * const this, Tianmu::core::MysqlExpression * expr, Tianmu::core::TempTable * temp_table, int temp_table_alias, Tianmu::core::MultiIndex * mind) (\opt\litaihong\stonedb\storage\tianmu\vc\expr_column.cpp:70)
Tianmu::core::Query::CreateColumnFromExpression(Tianmu::core::Query * const this, const std::vector<Tianmu::core::MysqlExpression*, std::allocator<Tianmu::core::MysqlExpression*> > & exprs, Tianmu::core::TempTable * temp_table, int temp_table_alias, Tianmu::core::MultiIndex * mind) (\opt\litaihong\stonedb\storage\tianmu\core\query.cpp:489)
Tianmu::core::Query::Preexecute(Tianmu::core::Query * const this, Tianmu::core::CompiledQuery & qu, Tianmu::core::ResultSender * sender, bool display_now) (\opt\litaihong\stonedb\storage\tianmu\core\query.cpp:802)
Tianmu::core::Engine::Execute(Tianmu::core::Engine * const this, THD * thd, LEX * lex, Query_result * result_output, SELECT_LEX_UNIT * unit_for_union) (\opt\litaihong\stonedb\storage\tianmu\core\engine_execute.cpp:421)
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) (\opt\litaihong\stonedb\storage\tianmu\core\engine_execute.cpp:232)
Tianmu::dbhandler::TIANMU_HandleSelect(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) (\opt\litaihong\stonedb\storage\tianmu\handler\ha_rcengine.cpp:82)
execute_sqlcom_select(THD * thd, TABLE_LIST * all_tables) (\opt\litaihong\stonedb\sql\sql_parse.cc:5182)
mysql_execute_command(THD * thd, bool first_level) (\opt\litaihong\stonedb\sql\sql_parse.cc:2831)
mysql_parse(THD * thd, Parser_state * parser_state) (\opt\litaihong\stonedb\sql\sql_parse.cc:5621)
dispatch_command(THD * thd, const COM_DATA * com_data, enum_server_command command) (\opt\litaihong\stonedb\sql\sql_parse.cc:1495)
do_command(THD * thd) (\opt\litaihong\stonedb\sql\sql_parse.cc:1034)
handle_connection(void * arg) (\opt\litaihong\stonedb\sql\conn_handler\connection_handler_per_thread.cc:313)
pfs_spawn_thread(void * arg) (\opt\litaihong\stonedb\storage\perfschema\pfs.cc:2197)
Tianmu::core::ColumnType::ColumnType(Tianmu::core::ColumnType * const this, const Tianmu::core::DataType & dt) (\opt\litaihong\stonedb\storage\tianmu\core\column_type.cpp:26)
Tianmu::vcolumn::ExpressionColumn::ExpressionColumn(Tianmu::vcolumn::ExpressionColumn * const this, Tianmu::core::MysqlExpression * expr, Tianmu::core::TempTable * temp_table, int temp_table_alias, Tianmu::core::MultiIndex * mind) (\opt\litaihong\stonedb\storage\tianmu\vc\expr_column.cpp:70)
Tianmu::core::Query::CreateColumnFromExpression(Tianmu::core::Query * const this, const std::vector<Tianmu::core::MysqlExpression*, std::allocator<Tianmu::core::MysqlExpression*> > & exprs, Tianmu::core::TempTable * temp_table, int temp_table_alias, Tianmu::core::MultiIndex * mind) (\opt\litaihong\stonedb\storage\tianmu\core\query.cpp:489)
Tianmu::core::Query::Preexecute(Tianmu::core::Query * const this, Tianmu::core::CompiledQuery & qu, Tianmu::core::ResultSender * sender, bool display_now) (\opt\litaihong\stonedb\storage\tianmu\core\query.cpp:802)
Tianmu::core::Engine::Execute(Tianmu::core::Engine * const this, THD * thd, LEX * lex, Query_result * result_output, SELECT_LEX_UNIT * unit_for_union) (\opt\litaihong\stonedb\storage\tianmu\core\engine_execute.cpp:421)
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) (\opt\litaihong\stonedb\storage\tianmu\core\engine_execute.cpp:232)
Tianmu::dbhandler::TIANMU_HandleSelect(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) (\opt\litaihong\stonedb\storage\tianmu\handler\ha_rcengine.cpp:82)
execute_sqlcom_select(THD * thd, TABLE_LIST * all_tables) (\opt\litaihong\stonedb\sql\sql_parse.cc:5182)
mysql_execute_command(THD * thd, bool first_level) (\opt\litaihong\stonedb\sql\sql_parse.cc:2831)
mysql_parse(THD * thd, Parser_state * parser_state) (\opt\litaihong\stonedb\sql\sql_parse.cc:5621)
dispatch_command(THD * thd, const COM_DATA * com_data, enum_server_command command) (\opt\litaihong\stonedb\sql\sql_parse.cc:1495)
do_command(THD * thd) (\opt\litaihong\stonedb\sql\sql_parse.cc:1034)
handle_connection(void * arg) (\opt\litaihong\stonedb\sql\conn_handler\connection_handler_per_thread.cc:313)
pfs_spawn_thread(void * arg) (\opt\litaihong\stonedb\storage\perfschema\pfs.cc:2197)

Result set processing

Tianmu::core::TempTable::SendResult(Tianmu::core::TempTable * const this, int64_t limit, int64_t offset, Tianmu::core::ResultSender & sender, bool pagewise) (\opt\litaihong\stonedb\storage\tianmu\core\temp_table_low.cpp:452)
Tianmu::core::TempTable::FillMaterializedBuffers(Tianmu::core::TempTable * const this, int64_t local_limit, int64_t local_offset, Tianmu::core::ResultSender * sender, bool pagewise) (\opt\litaihong\stonedb\storage\tianmu\core\temp_table_low.cpp:310)
Tianmu::core::TempTable::Materialize(Tianmu::core::TempTable * const this, bool in_subq, Tianmu::core::ResultSender * sender, bool lazy) (\opt\litaihong\stonedb\storage\tianmu\core\temp_table.cpp:1956)
Tianmu::core::Engine::Execute(Tianmu::core::Engine * const this, THD * thd, LEX * lex, Query_result * result_output, SELECT_LEX_UNIT * unit_for_union) (\opt\litaihong\stonedb\storage\tianmu\core\engine_execute.cpp:426)
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) (\opt\litaihong\stonedb\storage\tianmu\core\engine_execute.cpp:232)
Tianmu::dbhandler::TIANMU_HandleSelect(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) (\opt\litaihong\stonedb\storage\tianmu\handler\ha_rcengine.cpp:82)
execute_sqlcom_select(THD * thd, TABLE_LIST * all_tables) (\opt\litaihong\stonedb\sql\sql_parse.cc:5182)
mysql_execute_command(THD * thd, bool first_level) (\opt\litaihong\stonedb\sql\sql_parse.cc:2831)
mysql_parse(THD * thd, Parser_state * parser_state) (\opt\litaihong\stonedb\sql\sql_parse.cc:5621)
dispatch_command(THD * thd, const COM_DATA * com_data, enum_server_command command) (\opt\litaihong\stonedb\sql\sql_parse.cc:1495)
do_command(THD * thd) (\opt\litaihong\stonedb\sql\sql_parse.cc:1034)
handle_connection(void * arg) (\opt\litaihong\stonedb\sql\conn_handler\connection_handler_per_thread.cc:313)
pfs_spawn_thread(void * arg) (\opt\litaihong\stonedb\storage\perfschema\pfs.cc:2197)
Tianmu::core::Item_tianmufield::FeedValue(Tianmu::core::Item_tianmufield * const this) (\opt\litaihong\stonedb\storage\tianmu\core\item_tianmu_field.cpp:126)
Tianmu::core::Item_tianmufield::val_str(Tianmu::core::Item_tianmufield * const this, String * str) (\opt\litaihong\stonedb\storage\tianmu\core\item_tianmu_field.cpp:183)
Item_func_conv::val_str(Item_func_conv * const this, String * str) (\opt\litaihong\stonedb\sql\item_strfunc.cc:3746)
Tianmu::core::MysqlExpression::ItemString2ValueOrNull(Item * item, int maxstrlen, Tianmu::common::CT a_type) (\opt\litaihong\stonedb\storage\tianmu\core\mysql_expression.cpp:517)
Tianmu::core::MysqlExpression::Evaluate(Tianmu::core::MysqlExpression * const this) (\opt\litaihong\stonedb\storage\tianmu\core\mysql_expression.cpp:459)
Tianmu::vcolumn::ExpressionColumn::IsNullImpl(Tianmu::vcolumn::ExpressionColumn * const this, const Tianmu::core::MIIterator & mit) (\opt\litaihong\stonedb\storage\tianmu\vc\expr_column.cpp:122)
Tianmu::vcolumn::VirtualColumnBase::IsNull(Tianmu::vcolumn::VirtualColumnBase * const this, const Tianmu::core::MIIterator & mit) (\opt\litaihong\stonedb\storage\tianmu\vc\virtual_column_base.h:104)
Tianmu::core::TempTable::SendResult(Tianmu::core::TempTable * const this, int64_t limit, int64_t offset, Tianmu::core::ResultSender & sender, bool pagewise) (\opt\litaihong\stonedb\storage\tianmu\core\temp_table_low.cpp:477)
Tianmu::core::TempTable::FillMaterializedBuffers(Tianmu::core::TempTable * const this, int64_t local_limit, int64_t local_offset, Tianmu::core::ResultSender * sender, bool pagewise) (\opt\litaihong\stonedb\storage\tianmu\core\temp_table_low.cpp:310)
Tianmu::core::TempTable::Materialize(Tianmu::core::TempTable * const this, bool in_subq, Tianmu::core::ResultSender * sender, bool lazy) (\opt\litaihong\stonedb\storage\tianmu\core\temp_table.cpp:1956)
Tianmu::core::Engine::Execute(Tianmu::core::Engine * const this, THD * thd, LEX * lex, Query_result * result_output, SELECT_LEX_UNIT * unit_for_union) (\opt\litaihong\stonedb\storage\tianmu\core\engine_execute.cpp:426)
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) (\opt\litaihong\stonedb\storage\tianmu\core\engine_execute.cpp:232)
Tianmu::dbhandler::TIANMU_HandleSelect(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) (\opt\litaihong\stonedb\storage\tianmu\handler\ha_rcengine.cpp:82)
execute_sqlcom_select(THD * thd, TABLE_LIST * all_tables) (\opt\litaihong\stonedb\sql\sql_parse.cc:5182)
mysql_execute_command(THD * thd, bool first_level) (\opt\litaihong\stonedb\sql\sql_parse.cc:2831)
mysql_parse(THD * thd, Parser_state * parser_state) (\opt\litaihong\stonedb\sql\sql_parse.cc:5621)
dispatch_command(THD * thd, const COM_DATA * com_data, enum_server_command command) (\opt\litaihong\stonedb\sql\sql_parse.cc:1495)
do_command(THD * thd) (\opt\litaihong\stonedb\sql\sql_parse.cc:1034)
handle_connection(void * arg) (\opt\litaihong\stonedb\sql\conn_handler\connection_handler_per_thread.cc:313)
pfs_spawn_thread(void * arg) (\opt\litaihong\stonedb\storage\perfschema\pfs.cc:2197)
Tianmu::core::TempTable::SendResult(Tianmu::core::TempTable * const this, int64_t limit, int64_t offset, Tianmu::core::ResultSender & sender, bool pagewise) (\opt\litaihong\stonedb\storage\tianmu\core\temp_table_low.cpp:452)
Tianmu::core::TempTable::FillMaterializedBuffers(Tianmu::core::TempTable * const this, int64_t local_limit, int64_t local_offset, Tianmu::core::ResultSender * sender, bool pagewise) (\opt\litaihong\stonedb\storage\tianmu\core\temp_table_low.cpp:310)
Tianmu::core::TempTable::Materialize(Tianmu::core::TempTable * const this, bool in_subq, Tianmu::core::ResultSender * sender, bool lazy) (\opt\litaihong\stonedb\storage\tianmu\core\temp_table.cpp:1956)
Tianmu::core::Engine::Execute(Tianmu::core::Engine * const this, THD * thd, LEX * lex, Query_result * result_output, SELECT_LEX_UNIT * unit_for_union) (\opt\litaihong\stonedb\storage\tianmu\core\engine_execute.cpp:426)
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) (\opt\litaihong\stonedb\storage\tianmu\core\engine_execute.cpp:232)
Tianmu::dbhandler::TIANMU_HandleSelect(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) (\opt\litaihong\stonedb\storage\tianmu\handler\ha_rcengine.cpp:82)
execute_sqlcom_select(THD * thd, TABLE_LIST * all_tables) (\opt\litaihong\stonedb\sql\sql_parse.cc:5182)
mysql_execute_command(THD * thd, bool first_level) (\opt\litaihong\stonedb\sql\sql_parse.cc:2831)
mysql_parse(THD * thd, Parser_state * parser_state) (\opt\litaihong\stonedb\sql\sql_parse.cc:5621)
dispatch_command(THD * thd, const COM_DATA * com_data, enum_server_command command) (\opt\litaihong\stonedb\sql\sql_parse.cc:1495)
do_command(THD * thd) (\opt\litaihong\stonedb\sql\sql_parse.cc:1034)
handle_connection(void * arg) (\opt\litaihong\stonedb\sql\conn_handler\connection_handler_per_thread.cc:313)
pfs_spawn_thread(void * arg) (\opt\litaihong\stonedb\storage\perfschema\pfs.cc:2197)

@lylth
Copy link
Contributor Author

lylth commented Nov 15, 2022

The tianmu engine does not support unsigned data types, but BIT data is unsigned. To implement the BIT data type, we need to implement the unsigned data type first.

@hustjieke hustjieke assigned hustjieke and unassigned lylth Nov 17, 2022
@hustjieke hustjieke added this to the stonedb_5.7_v1.0.2 milestone Nov 18, 2022
@hustjieke hustjieke moved this to In Progress in StoneDB for MySQL 5.7 Nov 18, 2022
hustjieke added a commit to hustjieke/stonedb-8.0.30-upgrade that referenced this issue Dec 15, 2022
…t type stoneatom#919

[summary]
1. add support to create table with bit type
2. add support to desc/show fields with bit type table
3. currently we design bit(M) with (1 <= M <= 63), in the future we'll expand prec to 64.
hustjieke added a commit to hustjieke/stonedb-8.0.30-upgrade that referenced this issue Dec 16, 2022
[summary]
1. impl insert with mode delayed=0/1
2. impl simple select bit data from table
hustjieke added a commit to hustjieke/stonedb-8.0.30-upgrade that referenced this issue Dec 20, 2022
hustjieke added a commit to hustjieke/stonedb-8.0.30-upgrade that referenced this issue Dec 20, 2022
hustjieke added a commit to hustjieke/stonedb-8.0.30-upgrade that referenced this issue Dec 20, 2022
…t type stoneatom#919

[summary]
1. add support to create table with bit type
2. add support to desc/show fields with bit type table
3. currently we design bit(M) with (1 <= M <= 63), in the future we'll expand prec to 64.
hustjieke added a commit to hustjieke/stonedb-8.0.30-upgrade that referenced this issue Dec 20, 2022
[summary]
1. impl insert with mode delayed=0/1
2. impl simple select bit data from table
hustjieke added a commit to hustjieke/stonedb-8.0.30-upgrade that referenced this issue Dec 20, 2022
hustjieke added a commit to hustjieke/stonedb-8.0.30-upgrade that referenced this issue Dec 20, 2022
hustjieke added a commit to hustjieke/stonedb-8.0.30-upgrade that referenced this issue Dec 20, 2022
hustjieke added a commit to hustjieke/stonedb-8.0.30-upgrade that referenced this issue Dec 20, 2022
@hustjieke
Copy link
Collaborator

BIT values cannot be loaded directly using binary notation (for example, b'011010'). To work around this, use the SET clause to strip off the leading b' and trailing ' and perform a base-2 to base-10 conversion so that MySQL loads the values into the BIT column properly:

$> cat /tmp/bit_test.txt
b'10'
b'1111111'
$> mysql test
mysql> LOAD DATA INFILE '/tmp/bit_test.txt'
       INTO TABLE bit_test (@var1)
       SET b = CAST(CONV(MID(@var1, 3, LENGTH(@var1)-3), 2, 10) AS UNSIGNED);
Query OK, 2 rows affected (0.00 sec)
Records: 2  Deleted: 0  Skipped: 0  Warnings: 0

mysql> SELECT BIN(b+0) FROM bit_test;
+----------+
| BIN(b+0) |
+----------+
| 10       |
| 1111111  |
+----------+
2 rows in set (0.00 sec)

For BIT values in 0b binary notation (for example, 0b011010), use this SET clause instead to strip off the leading 0b:

SET b = CAST(CONV(MID(@var1, 3, LENGTH(@var1)-2), 2, 10) AS UNSIGNED)

hustjieke added a commit to hustjieke/stonedb-8.0.30-upgrade that referenced this issue Dec 22, 2022
@hustjieke
Copy link
Collaborator

hustjieke commented Dec 22, 2022

In storage/tianmu/loader/parsing_strategy.cpp
In function ParsingStrategy::GetOneRow( )

476     String *str{nullptr};
477
478     if (!first_row_prepared_) {
479       std::string field_name(field->field_name);
480       str = new (thd_->mem_root) String(MAX_FIELD_WIDTH);
481       index_of_field = map_field_name_to_index_[field_name];
482       vec_field_num_to_index_[field_index_in_field_list] = index_of_field;
483       vec_field_Str_list_[index_of_field] = str;
484     } else {
485       index_of_field = vec_field_num_to_index_[field_index_in_field_list];
486       str = vec_field_Str_list_[index_of_field];
487     }
488     String *res = field->str_result(str);
489     // DEBUG_ASSERT(res);
490     if (res && res != str) {
491       str->copy(*res);
492     }

For line 488, the res may be nullptr when the field has NULL value, so the DEBUG_ASSERT(res) in line 489 should be deleted, otherwise it will cause crashed in debug mode.

String *Item_field::str_result(String *str)
{
  if ((null_value=result_field->is_null()))
    return 0;
  str->set_charset(str_value.charset());
  return result_field->val_str(str,&str_value);
}

@hustjieke
Copy link
Collaborator

In storage/tianmu/loader/parsing_strategy.cpp In function ParsingStrategy::GetOneRow( )

476     String *str{nullptr};
477
478     if (!first_row_prepared_) {
479       std::string field_name(field->field_name);
480       str = new (thd_->mem_root) String(MAX_FIELD_WIDTH);
481       index_of_field = map_field_name_to_index_[field_name];
482       vec_field_num_to_index_[field_index_in_field_list] = index_of_field;
483       vec_field_Str_list_[index_of_field] = str;
484     } else {
485       index_of_field = vec_field_num_to_index_[field_index_in_field_list];
486       str = vec_field_Str_list_[index_of_field];
487     }
488     String *res = field->str_result(str);
489     // DEBUG_ASSERT(res);
490     if (res && res != str) {
491       str->copy(*res);
492     }

For line 488, the res may be nullptr when the field has NULL value, so the DEBUG_ASSERT(res) in line 489 should be deleted, otherwise it will cause crashed in debug mode.

String *Item_field::str_result(String *str)
{
  if ((null_value=result_field->is_null()))
    return 0;
  str->set_charset(str_value.charset());
  return result_field->val_str(str,&str_value);
}

This is related to loader module but founded in load bit test, I'll fix it in load bit pr.
Ping @lujiashun

@hustjieke hustjieke added the prio: high High priority label Dec 22, 2022
hustjieke added a commit to hustjieke/stonedb-8.0.30-upgrade that referenced this issue Dec 23, 2022
…t type stoneatom#919

[summary]
1. add support to create table with bit type
2. add support to desc/show fields with bit type table
3. currently we design bit(M) with (1 <= M <= 63), in the future we'll expand prec to 64.
hustjieke added a commit to hustjieke/stonedb-8.0.30-upgrade that referenced this issue Dec 23, 2022
[summary]
1. impl insert with mode delayed=0/1
2. impl simple select bit data from table
hustjieke added a commit to hustjieke/stonedb-8.0.30-upgrade that referenced this issue Dec 23, 2022
hustjieke added a commit to hustjieke/stonedb-8.0.30-upgrade that referenced this issue Dec 23, 2022
hustjieke added a commit to hustjieke/stonedb-8.0.30-upgrade that referenced this issue Dec 23, 2022
hustjieke added a commit to hustjieke/stonedb-8.0.30-upgrade that referenced this issue Jan 4, 2023
[summary]
1. impl insert with mode delayed=0/1
2. impl simple select bit data from table
hustjieke added a commit to hustjieke/stonedb-8.0.30-upgrade that referenced this issue Jan 4, 2023
hustjieke added a commit to hustjieke/stonedb-8.0.30-upgrade that referenced this issue Jan 4, 2023
hustjieke added a commit to hustjieke/stonedb-8.0.30-upgrade that referenced this issue Jan 4, 2023
hustjieke added a commit to hustjieke/stonedb-8.0.30-upgrade that referenced this issue Jan 4, 2023
hustjieke added a commit to hustjieke/stonedb-8.0.30-upgrade that referenced this issue Jan 4, 2023
[summary]
impl load bit, including empty space and null value, to keep the src code integrity, we add
an bit parse function just like others numeric does.
hustjieke added a commit to hustjieke/stonedb-8.0.30-upgrade that referenced this issue Jan 4, 2023
[summary]
1. revert some vars renaming code to keep old style.
2. fix type cast using reinterpret_cast to avoid c-style casting.
3. add more test cases and fix some errors.
4. format code.
hustjieke added a commit to hustjieke/stonedb-8.0.30-upgrade that referenced this issue Jan 4, 2023
mergify bot pushed a commit that referenced this issue Jan 5, 2023
…t type #919

[summary]
1. add support to create table with bit type
2. add support to desc/show fields with bit type table
3. currently we design bit(M) with (1 <= M <= 63), in the future we'll expand prec to 64.
mergify bot pushed a commit that referenced this issue Jan 5, 2023
[summary]
1. impl insert with mode delayed=0/1
2. impl simple select bit data from table
mergify bot pushed a commit that referenced this issue Jan 5, 2023
mergify bot pushed a commit that referenced this issue Jan 5, 2023
mergify bot pushed a commit that referenced this issue Jan 5, 2023
mergify bot pushed a commit that referenced this issue Jan 5, 2023
[summary]
impl load bit, including empty space and null value, to keep the src code integrity, we add
an bit parse function just like others numeric does.
mergify bot pushed a commit that referenced this issue Jan 5, 2023
[summary]
1. revert some vars renaming code to keep old style.
2. fix type cast using reinterpret_cast to avoid c-style casting.
3. add more test cases and fix some errors.
4. format code.
mergify bot pushed a commit that referenced this issue Jan 5, 2023
@hustjieke
Copy link
Collaborator

Funciton TxtDataFormat::StaticExtrnalSize should be refactor in 8.0.17.
common/txt_data_format.cpp

As of MySQL 8.0.17, the display width attribute is deprecated for integer data types; you should expect support for it to be removed in a future version of MySQL.

For more infos, see:
https://dev.mysql.com/doc/refman/8.0/en/numeric-type-syntax.html

@github-project-automation github-project-automation bot moved this from In Progress to Done in StoneDB for MySQL 5.7 Jan 14, 2023
konghaiya pushed a commit to konghaiya/stonedb that referenced this issue Mar 7, 2023
…t type stoneatom#919

[summary]
1. add support to create table with bit type
2. add support to desc/show fields with bit type table
3. currently we design bit(M) with (1 <= M <= 63), in the future we'll expand prec to 64.
konghaiya pushed a commit to konghaiya/stonedb that referenced this issue Mar 7, 2023
[summary]
1. impl insert with mode delayed=0/1
2. impl simple select bit data from table
konghaiya pushed a commit to konghaiya/stonedb that referenced this issue Mar 7, 2023
konghaiya pushed a commit to konghaiya/stonedb that referenced this issue Mar 7, 2023
konghaiya pushed a commit to konghaiya/stonedb that referenced this issue Mar 7, 2023
konghaiya pushed a commit to konghaiya/stonedb that referenced this issue Mar 7, 2023
konghaiya pushed a commit to konghaiya/stonedb that referenced this issue Mar 7, 2023
[summary]
impl load bit, including empty space and null value, to keep the src code integrity, we add
an bit parse function just like others numeric does.
konghaiya pushed a commit to konghaiya/stonedb that referenced this issue Mar 7, 2023
[summary]
1. revert some vars renaming code to keep old style.
2. fix type cast using reinterpret_cast to avoid c-style casting.
3. add more test cases and fix some errors.
4. format code.
konghaiya pushed a commit to konghaiya/stonedb that referenced this issue Mar 7, 2023
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 prio: high High priority
Projects
Development

No branches or pull requests

2 participants