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: Insert a space,SELECT COUNT(DISTINCT col2) FROM t1;Error query result #736

Closed
2 tasks done
shangyanwen opened this issue Oct 17, 2022 · 3 comments · Fixed by #756
Closed
2 tasks done

bug: Insert a space,SELECT COUNT(DISTINCT col2) FROM t1;Error query result #736

shangyanwen opened this issue Oct 17, 2022 · 3 comments · Fixed by #756
Assignees
Labels
A-bug Something isn't working prio: high High priority

Comments

@shangyanwen
Copy link
Contributor

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

CREATE TABLE t1(col1 INT, col2 CHAR(5))ENGINE=tianmu;
INSERT INTO t1 VALUES(NULL,''),(1,'a'),(1,'b'),(1,'c'),(2,'dd'),(3,'eee');
SELECT COUNT(DISTINCT col2) FROM t1;

##The error results are as follows
+----------------------+
| COUNT(DISTINCT col2) |
+----------------------+
|                    1 |
+----------------------+

Expected behavior

##The following is:innodb test result,mariadb-Columnstore test result is 5

mysql> SELECT COUNT(DISTINCT col2) FROM t1;
+----------------------+
| COUNT(DISTINCT col2) |
+----------------------+
|                    6 
+----------------------+

How To Reproduce

CREATE TABLE t1(col1 INT, col2 CHAR(5))ENGINE=tianmu;
INSERT INTO t1 VALUES(NULL,''),(1,'a'),(1,'b'),(1,'c'),(2,'dd'),(3,'eee');
SELECT COUNT(DISTINCT col2) FROM t1;


### Environment

Ver 14.14 Distrib 5.7.36-StoneDB


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

- [ ] Yes, I will!
@shangyanwen shangyanwen added the A-bug Something isn't working label Oct 17, 2022
@shangyanwen
Copy link
Contributor Author

###Insert data without space, the test result is correct
SELECT COUNT(DISTINCT col1) FROM t1;

@RingsC RingsC added the prio: high High priority label Oct 18, 2022
@lylth lylth assigned lylth and unassigned konghaiya Oct 18, 2022
@lylth
Copy link
Contributor

lylth commented Oct 19, 2022

The stack for setting the count value is as follows:

Tianmu::core::AggregatorCount32::PutAggregatedValue(Tianmu::core::AggregatorCount32 * const this, unsigned char * buf, int64_t factor) (\opt\litaihong\stonedb\storage\tianmu\core\aggregator.h:300)
Tianmu::core::AggregatorCount32::PutAggregatedValue(Tianmu::core::AggregatorCount32 * const this, unsigned char * buf, const Tianmu::types::BString & v, int64_t factor) (\opt\litaihong\stonedb\storage\tianmu\core\aggregator.h:313)
Tianmu::core::GroupTable::PutAggregatedValue(Tianmu::core::GroupTable * const this, int col, int64_t row, Tianmu::core::MIIterator & mit, int64_t factor, bool as_string) (\opt\litaihong\stonedb\storage\tianmu\core\group_table.cpp:556)
Tianmu::core::GroupByWrapper::PutAggregatedValue(Tianmu::core::GroupByWrapper * const this, int gr_a, int64_t pos, Tianmu::core::MIIterator & mit, int64_t factor) (\opt\litaihong\stonedb\storage\tianmu\core\groupby_wrapper.cpp:509)
Tianmu::core::AggregationAlgorithm::AggregatePackrow(Tianmu::core::AggregationAlgorithm * const this, Tianmu::core::GroupByWrapper & gbw, Tianmu::core::MIIterator * mit, int64_t cur_tuple) (\opt\litaihong\stonedb\storage\tianmu\core\aggregation_algorithm.cpp:591)
Tianmu::core::AggregationAlgorithm::MultiDimensionalGroupByScan(Tianmu::core::AggregationAlgorithm * const this, Tianmu::core::GroupByWrapper & gbw, int64_t & limit, int64_t & offset, Tianmu::core::ResultSender * sender, bool limit_less_than_no_groups, bool force_parall) (\opt\litaihong\stonedb\storage\tianmu\core\aggregation_algorithm.cpp:292)
Tianmu::core::AggregationAlgorithm::Aggregate(Tianmu::core::AggregationAlgorithm * const this, bool just_distinct, int64_t & limit, int64_t & offset, Tianmu::core::ResultSender * sender) (\opt\litaihong\stonedb\storage\tianmu\core\aggregation_algorithm.cpp:197)
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:1972)
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)
libpthread.so.0!start_thread (未知源:0)
libc.so.6!clone (未知源:0)

The FindCurrentRow function returns GBIMODE_AS_TEXT to enter the accumulation process, and the FindCurrentRowByVMTable function returns GDT_EXISTS to enter the re-counting process, resulting in the string type of count being always 1.

Tianmu::core::GroupDistinctTable::FindCurrentRow(Tianmu::core::GroupDistinctTable * const this, bool find_only) (\opt\litaihong\stonedb\storage\tianmu\core\group_distinct_table.cpp:282)
Tianmu::core::GroupDistinctTable::Add(Tianmu::core::GroupDistinctTable * const this, int64_t group, Tianmu::core::MIIterator & mit) (\opt\litaihong\stonedb\storage\tianmu\core\group_distinct_table.cpp:179)
Tianmu::core::GroupTable::PutAggregatedValue(Tianmu::core::GroupTable * const this, int col, int64_t row, Tianmu::core::MIIterator & mit, int64_t factor, bool as_string) (\opt\litaihong\stonedb\storage\tianmu\core\group_table.cpp:538)
Tianmu::core::GroupByWrapper::PutAggregatedValue(Tianmu::core::GroupByWrapper * const this, int gr_a, int64_t pos, Tianmu::core::MIIterator & mit, int64_t factor) (\opt\litaihong\stonedb\storage\tianmu\core\groupby_wrapper.cpp:509)
Tianmu::core::AggregationAlgorithm::AggregatePackrow(Tianmu::core::AggregationAlgorithm * const this, Tianmu::core::GroupByWrapper & gbw, Tianmu::core::MIIterator * mit, int64_t cur_tuple) (\opt\litaihong\stonedb\storage\tianmu\core\aggregation_algorithm.cpp:591)
Tianmu::core::AggregationAlgorithm::MultiDimensionalGroupByScan(Tianmu::core::AggregationAlgorithm * const this, Tianmu::core::GroupByWrapper & gbw, int64_t & limit, int64_t & offset, Tianmu::core::ResultSender * sender, bool limit_less_than_no_groups, bool force_parall) (\opt\litaihong\stonedb\storage\tianmu\core\aggregation_algorithm.cpp:292)
Tianmu::core::AggregationAlgorithm::Aggregate(Tianmu::core::AggregationAlgorithm * const this, bool just_distinct, int64_t & limit, int64_t & offset, Tianmu::core::ResultSender * sender) (\opt\litaihong\stonedb\storage\tianmu\core\aggregation_algorithm.cpp:197)
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:1972)
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)
libpthread.so.0!start_thread (未知源:0)
libc.so.6!clone (未知源:0)

@lylth
Copy link
Contributor

lylth commented Oct 19, 2022

The AggregatePackrow function call flow is as follows:

AggregationAlgorithm::AggregatePackrow
--------------------------->AggregateRough--->FindCurrentRow--->GroupTable::FindCurrentRow--->FindCurrentRow
--------------------------------------------------------------------------------------------->GetAggregationRow
--------------------------------------------->AddGroup
--------------------------------------------->InvalidateAggregationStatistics
--------------------------------------------->PackWillNotUpdateAggregation
--------------------------->GroupByWrapper::PutAggregatedValue--->GroupTable::PutAggregatedValue--->GroupDistinctTable::Add--->ColumnBinEncoder::ValEncode--->ColumnBinEncoder::EncoderInt::ValEncode--->GetNotNullValueInt64--->GetNotNullValueInt64
------------------------------------------------------------------------------------------------------------------------------>FindCurrentRowByVMTable
--------------------------------------------------------------------------------------------------->PutAggregatedValue
--------------------------->GroupByWrapper::PutAggregatedValue--->GroupTable::PutAggregatedValue

hustjieke pushed a commit that referenced this issue Oct 21, 2022
… (#756)

Replace the function FindCurrentRowByVMTable that gets the current row to FindCurrentRow.
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 prio: high High priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants