zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

2022-12-01 mysql列存储引擎-主键在exists子句时候查询错误-记录

mysql错误引擎存储 查询 记录 2022 12
2023-09-27 14:25:42 时间

摘要:

mysql列存储引擎-主键在exists子句时候查询错误-记录

关联ISSUE: 

https://github.com/stoneatom/stonedb/issues/971

https://github.com/stoneatom/stonedb/issues/944

DDL:

表结构:

create table tt1(id int primary key,name varchar(5),copy_id int) engine=tianmu;
create table tt2(id int primary key,name varchar(5),copy_id int) engine=tianmu;

插入数据:

insert into tt1 values(1,'AAA',1),(2,'AAA',2),(3,'BBB',3),(4,'BBB',4),(5,'CCC',5);
insert into tt2 values(1,'BBB',1),(2,'BBB',2),(3,'CCC',3),(4,'CCC',4),(5,'DDD',5);

查询SQL:

 select tt1.name
   from tt1
  where exists (select 1
           from tt2
          where tt1.id = tt2.id and name='BBB');

追踪:

mysql列存储引擎的查询树:

T:-1 = TABLE_ALIAS(T:0,"tt1")
T:-2 = TMP_TABLE(T:4294967295)
VC:-2.0 = CREATE_VC(T:-2,PHYS_COL(T:-1,A:1))
A:-1 = T:-2.ADD_COLUMN(VC:-2.0,LIST,"name","ALL")
T:-3 = TABLE_ALIAS(T:1,"tt2")
T:-4 = TMP_TABLE(T:4294967293)
VC:-4.0 = CREATE_VC(T:-4,EXPR("1"))
A:-1 = T:-4.ADD_COLUMN(VC:-4.0,LIST,"1","ALL")
VC:-4.1 = CREATE_VC(T:-4,EXPR("TIANMU_FIELD(T:-1,A:0)"))
VC:-4.2 = CREATE_VC(T:-4,PHYS_COL(T:-3,A:0))
C:0 = CREATE_CONDS(T:-4,VC:-4.1,=,VC:-4.2,<null>)
VC:-4.3 = CREATE_VC(T:-4,PHYS_COL(T:-3,A:1))
VC:-4.4 = CREATE_VC(T:-4,EXPR("BBB"))
C:0.AND(VC:-4.3,=,VC:-4.4,<null>)
T:-4.ADD_CONDS(C:0,HAVING)
T:-4.APPLY_CONDS()
T:-4.MODE(LIMIT,0,1)
VC:-2.1 = CREATE_VC(T:-2,SUBQUERY(T:-4))
C:1 = CREATE_CONDS(T:-2,VC:-2.1,EXISTS,<null>,<null>)
T:-2.ADD_CONDS(C:1,HAVING)
T:-2.APPLY_CONDS()
RESULT(T:-2)

使用主键的代码堆栈:

(gdb) bt
#0  Tianmu::core::Descriptor::IsleftIndexSearch (this=0x7f8784020c90) at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/core/descriptor.cpp:1922
#1  0x0000000002fa7178 in Tianmu::core::Descriptor::EvaluateOnIndex (this=0x7f8784020c90, mit=..., limit=1)
    at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/core/descriptor.cpp:1930
#2  0x000000000301c7b7 in Tianmu::core::ParameterizedFilter::ApplyDescriptor (this=0x7f878490c1f0, desc_number=0, limit=1)
    at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/core/parameterized_filter.cpp:1384
#3  0x000000000301b2f0 in Tianmu::core::ParameterizedFilter::UpdateMultiIndex (this=0x7f878490c1f0, count_only=false, limit=1)
    at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/core/parameterized_filter.cpp:1167
#4  0x0000000002cde719 in Tianmu::core::TempTable::ProcessParameters (this=0x7f878490c0a0, mit=..., alias=-2)
    at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/core/temp_table.cpp:1753
#5  0x0000000002dfa08a in Tianmu::vcolumn::SubSelectColumn::PrepareSubqResult (this=0x7f8784913b60, mit=..., exists_only=true)
    at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/vc/subselect_column.cpp:388
#6  0x0000000002dfa932 in Tianmu::vcolumn::SubSelectColumn::CheckExists (this=0x7f8784913b60, mit=...)
    at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/vc/subselect_column.cpp:497
#7  0x0000000002fa079e in Tianmu::core::Descriptor::CheckCondition (this=0x7f8784913790, mit=...) at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/core/descriptor.cpp:1079
#8  0x000000000308537a in Tianmu::core::JoinerGeneral::ExecuteInnerJoinLoopSingleThread (this=0x7f8784914860, mit=..., cond=..., new_mind=..., all_dims=..., 
    pack_desc_locked=std::vector<bool> of length 1, capacity 64 = {...}, tuples_in_output=@0x7f892e327498: 0, limit=-1, count_only=false)
    at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/core/joiner_general.cpp:244
#9  0x0000000003084696 in Tianmu::core::JoinerGeneral::ExecuteJoinConditions (this=0x7f8784914860, cond=...)
    at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/core/joiner_general.cpp:81
#10 0x0000000003018399 in Tianmu::core::ParameterizedFilter::UpdateJoinCondition (this=0x7f878490b9d0, cond=..., tips=...)
    at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/core/parameterized_filter.cpp:651
#11 0x000000000301c1be in Tianmu::core::ParameterizedFilter::UpdateMultiIndex (this=0x7f878490b9d0, count_only=false, limit=-1)
    at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/core/parameterized_filter.cpp:1304
#12 0x0000000002c99ae0 in Tianmu::core::Query::Preexecute (this=0x7f892e328810, qu=..., sender=0x7f8784913f40, display_now=true)
    at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/core/query.cpp:795
#13 0x0000000002c6bbb3 in Tianmu::core::Engine::Execute (this=0x5c5f7a0, thd=0x7f8784003400, lex=0x7f8784005728, result_output=0x7f8784008b40, unit_for_union=0x0)
    at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/core/engine_execute.cpp:477
#14 0x0000000002c6aa54 in Tianmu::core::Engine::HandleSelect (this=0x5c5f7a0, thd=0x7f8784003400, lex=0x7f8784005728, result=@0x7f892e328dd8: 0x7f8784008b40, setup_tables_done_option=0, 
    res=@0x7f892e328dd4: 0, optimize_after_tianmu=@0x7f892e328dcc: 1, tianmu_free_join=@0x7f892e328dd0: 1, with_insert=0)
    at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/core/engine_execute.cpp:238
#15 0x0000000002d6cd17 in Tianmu::handler::ha_my_tianmu_query (thd=0x7f8784003400, lex=0x7f8784005728, result_output=@0x7f892e328dd8: 0x7f8784008b40, setup_tables_done_option=0, res=@0x7f892e328dd4: 0, 
    optimize_after_tianmu=@0x7f892e328dcc: 1, tianmu_free_join=@0x7f892e328dd0: 1, with_insert=0) at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/handler/ha_my_tianmu.cpp:88
#16 0x00000000023af443 in execute_sqlcom_select (thd=0x7f8784003400, all_tables=0x7f8784008510) at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/sql/sql_parse.cc:5184
#17 0x00000000023a87d9 in mysql_execute_command (thd=0x7f8784003400, first_level=true) at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/sql/sql_parse.cc:2831
#18 0x00000000023b04a9 in mysql_parse (thd=0x7f8784003400, parser_state=0x7f892e329f90) at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/sql/sql_parse.cc:5622
#19 0x00000000023a55b4 in dispatch_command (thd=0x7f8784003400, com_data=0x7f892e32a730, command=COM_QUERY) at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/sql/sql_parse.cc:1495
#20 0x00000000023a43f5 in do_command (thd=0x7f8784003400) at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/sql/sql_parse.cc:1034
#21 0x00000000024d5a89 in handle_connection (arg=0x903a400) at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/sql/conn_handler/connection_handler_per_thread.cc:313
#22 0x0000000002ba2dd2 in pfs_spawn_thread (arg=0x8edb170) at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/perfschema/pfs.cc:2197
#23 0x00007f897e63e1ca in start_thread () from /lib64/libpthread.so.0
#24 0x00007f897b990e73 in clone () from /lib64/libc.so.6

TianmuAttr::EvaluateOnIndex

(gdb) bt
#0  Tianmu::core::TianmuAttr::EvaluateOnIndex (this=0x7f878400fe00, mit=..., dim=0, d=..., limit=1) at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/core/tianmu_attr_exqp.cpp:97
#1  0x0000000002df61fe in Tianmu::vcolumn::SingleColumn::EvaluateOnIndexImpl (this=0x7f87849d20f0, mit=..., desc=..., limit=1)
    at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/vc/single_column.h:131
#2  0x0000000002e08498 in Tianmu::vcolumn::VirtualColumnBase::EvaluateOnIndex (this=0x7f87849d20f0, mit=..., desc=..., limit=1)
    at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/vc/virtual_column_base.h:355
#3  0x0000000002fa719b in Tianmu::core::Descriptor::EvaluateOnIndex (this=0x7f8784018700, mit=..., limit=1)
    at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/core/descriptor.cpp:1931
#4  0x000000000301c7b7 in Tianmu::core::ParameterizedFilter::ApplyDescriptor (this=0x7f878490c1f0, desc_number=0, limit=1)
    at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/core/parameterized_filter.cpp:1384
#5  0x000000000301b2f0 in Tianmu::core::ParameterizedFilter::UpdateMultiIndex (this=0x7f878490c1f0, count_only=false, limit=1)
    at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/core/parameterized_filter.cpp:1167
#6  0x0000000002cde719 in Tianmu::core::TempTable::ProcessParameters (this=0x7f878490c0a0, mit=..., alias=-2)
    at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/core/temp_table.cpp:1753
#7  0x0000000002dfa08a in Tianmu::vcolumn::SubSelectColumn::PrepareSubqResult (this=0x7f8784913b60, mit=..., exists_only=true)
    at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/vc/subselect_column.cpp:388
#8  0x0000000002dfa932 in Tianmu::vcolumn::SubSelectColumn::CheckExists (this=0x7f8784913b60, mit=...)
    at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/vc/subselect_column.cpp:497
#9  0x0000000002fa079e in Tianmu::core::Descriptor::CheckCondition (this=0x7f8784918c90, mit=...) at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/core/descriptor.cpp:1079
#10 0x000000000308537a in Tianmu::core::JoinerGeneral::ExecuteInnerJoinLoopSingleThread (this=0x7f8784010770, mit=..., cond=..., new_mind=..., all_dims=..., 
    pack_desc_locked=std::vector<bool> of length 1, capacity 64 = {...}, tuples_in_output=@0x7f892e327498: 0, limit=-1, count_only=false)
    at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/core/joiner_general.cpp:244
#11 0x0000000003084696 in Tianmu::core::JoinerGeneral::ExecuteJoinConditions (this=0x7f8784010770, cond=...)
    at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/core/joiner_general.cpp:81
#12 0x0000000003018399 in Tianmu::core::ParameterizedFilter::UpdateJoinCondition (this=0x7f878490b9d0, cond=..., tips=...)
    at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/core/parameterized_filter.cpp:651
#13 0x000000000301c1be in Tianmu::core::ParameterizedFilter::UpdateMultiIndex (this=0x7f878490b9d0, count_only=false, limit=-1)
    at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/core/parameterized_filter.cpp:1304
#14 0x0000000002c99ae0 in Tianmu::core::Query::Preexecute (this=0x7f892e328810, qu=..., sender=0x7f87849bac70, display_now=true)
    at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/core/query.cpp:795
#15 0x0000000002c6bbb3 in Tianmu::core::Engine::Execute (this=0x5c5f7a0, thd=0x7f8784018bf0, lex=0x7f878401af18, result_output=0x7f87849cf980, unit_for_union=0x0)
    at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/core/engine_execute.cpp:477
#16 0x0000000002c6aa54 in Tianmu::core::Engine::HandleSelect (this=0x5c5f7a0, thd=0x7f8784018bf0, lex=0x7f878401af18, result=@0x7f892e328dd8: 0x7f87849cf980, setup_tables_done_option=0, 
    res=@0x7f892e328dd4: 0, optimize_after_tianmu=@0x7f892e328dcc: 1, tianmu_free_join=@0x7f892e328dd0: 1, with_insert=0)
    at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/core/engine_execute.cpp:238
#17 0x0000000002d6cd17 in Tianmu::handler::ha_my_tianmu_query (thd=0x7f8784018bf0, lex=0x7f878401af18, result_output=@0x7f892e328dd8: 0x7f87849cf980, setup_tables_done_option=0, res=@0x7f892e328dd4: 0, 
    optimize_after_tianmu=@0x7f892e328dcc: 1, tianmu_free_join=@0x7f892e328dd0: 1, with_insert=0) at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/tianmu/handler/ha_my_tianmu.cpp:88
#18 0x00000000023af443 in execute_sqlcom_select (thd=0x7f8784018bf0, all_tables=0x7f87849cf350) at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/sql/sql_parse.cc:5184
#19 0x00000000023a87d9 in mysql_execute_command (thd=0x7f8784018bf0, first_level=true) at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/sql/sql_parse.cc:2831
#20 0x00000000023b04a9 in mysql_parse (thd=0x7f8784018bf0, parser_state=0x7f892e329f90) at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/sql/sql_parse.cc:5622
#21 0x00000000023a55b4 in dispatch_command (thd=0x7f8784018bf0, com_data=0x7f892e32a730, command=COM_QUERY) at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/sql/sql_parse.cc:1495
#22 0x00000000023a43f5 in do_command (thd=0x7f8784018bf0) at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/sql/sql_parse.cc:1034
#23 0x00000000024d5a89 in handle_connection (arg=0x903a400) at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/sql/conn_handler/connection_handler_per_thread.cc:313
#24 0x0000000002ba2dd2 in pfs_spawn_thread (arg=0x8edb170) at /home/jenkins/workspace/stonedb5.7-zsl-centos7.9-75-133/storage/perfschema/pfs.cc:2197
#25 0x00007f897e63e1ca in start_thread () from /lib64/libpthread.so.0
#26 0x00007f897b990e73 in clone () from /lib64/libc.so.6