
说明:本文中的MySQL,如果不做特殊说明,指的是开源社区版MySQL。
Bug描述
selectsubq_0.c2 as c0from(selectref_6.C_STATE asc0,case whenref_6.C_PHONE is not NULL then ref_5.C_ID else ref_5.C_ID endasc1,floor(ref_3.c_id)as c2fromsqltester.t0_hash_partition_p1_view as ref_0right join sqltester.t4 as ref_1on (EXISTS (selectref_1.c_middle as c0fromsqltester.t1 as ref_2where ((false)and ((true)or (true)))or (false)))innerjoin sqltester.t0_range_key_subpartition_sub_view as ref_3on(EXISTS (selectref_0.c_credit as c0,ref_1.c_street_1 as c1,ref_4.c_credit_lim as c2,ref_3.c_credit as c3fromsqltester.t0_hash_partition_p1 as ref_4where true))left joinsqltester.t10 as ref_5innerjoin sqltester.t11 as ref_6on(true)on (((pi() isnot NULL))and (false))where (((ref_5.C_D_ID isnot NULL)or(ref_3.c_middle is not NULL)))) as subq_0where (EXISTS (selectsubq_0.c0 as c0,pi() as c1,ref_11.c_street_1 as c2,ref_11.c_discount as c3,pi() as c4fromsqltester.t0_partition_sub_view_mixed_001 as ref_11))group by 1order by 1;


Bug分析
使用相对成熟的版本MySQL 5.6进行验证,返回结果与GaussDB(for MySQL)相同,但与MySQL 8.0不同。 使用PostgreSQL进行验证,执行结果与MySQL 5.6、GaussDB(for MySQL)相同,但与MySQL 8.0及更高版本不同。
SELECT count(*)FROM(SELECT 1FROM sqltester.t4 AS ref_1INNER JOIN sqltester.t4 AS ref_3 ON (EXISTS(SELECT 1FROMsqltester.t4 AS ref_4WHERE TRUE ))LEFT JOIN sqltester.t10 AS ref_5 ON (FALSE)WHERE (((ref_5.C_D_ID IS NOT NULL)OR (ref_3.c_middle IS NOT NULL))))AS subq_0执行计划如下:-> Aggregate: count(0) (cost=2.75 rows=0)-> Filter: ((ref_5.C_D_ID is not null) or(ref_3.c_middle is null)) (cost=2.75 rows=0)-> Inner hash join(no condition) (cost=2.75 rows=0)-> Index scan on ref_3 using ndx_c_middle (cost=0.13 rows=50)-> Hash-> Inner hash join (no condition) (cost=1.50 rows=0)-> Index scan on ref_1 using ndx_c_id (cost=6.25 rows=50)-> Hash-> Left hash join (no condition) (cost=0.25 rows=0)-> Limit: 1 row(s) (cost=312.50 rows=1)->Index scan on ref_4 using ndx_c_id (cost=312.50 rows=50)-> Hash-> Zero rows (Impossible filter) (cost=0.00..0.00 rows=0)
SELECT count(*)FROM(SELECT 1FROM sqltester.t4 AS ref_1INNER JOIN sqltester.t4 AS ref_3 ON (EXISTS(SELECT 1FROM sqltester.t4 AS ref_4WHERE TRUE ))LEFT JOIN sqltester.t10 AS ref_5 ON (FALSE)WHERE (((ref_5.C_D_ID IS NOT NULL) or(ref_3.c_middle IS NOT NULL))))AS subq_0;++| count(*) |++| 2500 |++1 row in set (0.00 sec)
SELECT count(*)FROM(SELECT 1FROM sqltester.t4 AS ref_1INNER JOIN sqltester.t4 AS ref_3 ON (EXISTS(SELECT 1FROM sqltester.t4 AS ref_4WHERE TRUE ))LEFT JOIN sqltester.t10 AS ref_5 ON (FALSE)WHERE (((ref_5.C_D_ID IS NOT NULL))))assubq_0;++| count(*) |++| 2500 |++1 row in set (0.01 sec)
Breakpoint 1, ZeroRowsIterator::SetNullRowFlag(this=0x7f92a413d510, is_null_row=false)at mywork/mysql-sql/sql/basic_row_iterators.h:398398 assert(m_child_iterator != nullptr);(gdb) n399 m_child_iterator->SetNullRowFlag(is_null_row);(gdb) sstd::unique_ptr<RowIterator,Destroy_only<RowIterator> >::operator-> (this=0x7f92a413d520)at/opt/simon/taurus/mysql-root/src/tools/gcc-9.3.0/include/c++/9.3.0/bits/unique_ptr.h:355355 returnget();(gdb) finRun till exit from #0 std::unique_ptr<RowIterator,Destroy_only<RowIterator> >::operator-> (this=0x7f92a413d520)at/opt/simon/taurus/mysql-root/src/tools/gcc-9.3.0/include/c++/9.3.0/bits/unique_ptr.h:355ZeroRowsIterator::SetNullRowFlag (this=0x7f92a413d510,is_null_row=false)at/home/simon/mywork/mysql-sql/sql/basic_row_iterators.h:399399 m_child_iterator->SetNullRowFlag(is_null_row);Value returned is $1 = (RowIterator *) 0x7f92a413d4d0(gdb) sTableRowIterator::SetNullRowFlag (this=0x7f92a413d4d0,is_null_row=false)at/home/simon/mywork/mysql-sql/sql/records.cc:229229 if(is_null_row) {(gdb) n232 m_table->reset_null_row();(gdb)234 }
如何解决

华为云数据库团队荟聚了业内50%以上的数据库内核专家,以专业技术实时保障客户业务安全,助力企业业务安全上云!


华为云开年采购季盛大开幕!点击“阅读原文”,0门槛抽奖
文章转载自GaussDB数据库,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




