Skip to content

Commit e97560e

Browse files
committed
MDEV-28958 Crash when checking whether condition can be pushed into view
Do not set any flags in the items for constant subformulas TRUE/FALSE when checking pushability of a formula into a view. Occurrences of these subformulas can be ignored when checking pushability of the formula. At the same time the items used for these constants became immutable starting from version 10.7. Approved by Oleksandr Byelkin <sanja@mariadb.com>
1 parent 20d2c90 commit e97560e

File tree

3 files changed

+54
-7
lines changed

3 files changed

+54
-7
lines changed

mysql-test/main/derived_cond_pushdown.result

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20697,3 +20697,20 @@ id select_type table type possible_keys key key_len ref rows Extra
2069720697
drop view v1;
2069820698
drop table t1;
2069920699
# End of 10.4 tests
20700+
#
20701+
# MDEV-28958: condition pushable into view after simplification
20702+
# contains constant TRUE/FALSE as subformula
20703+
#
20704+
create table t1 (c1 int);
20705+
insert into t1 values (3), (7), (1), (3), (1), (3);
20706+
create table t2 (c2 int);
20707+
insert into t2 values (3), (5), (7), (3);
20708+
create view v1 as select * from t1 group by c1;
20709+
create view v2 as select c1 as a, c2 as b from v1,t2 where c1=c2;
20710+
select * from v2 group by a,b having a=b or b > a+10;
20711+
a b
20712+
3 3
20713+
7 7
20714+
drop view v1,v2;
20715+
drop table t1,t2;
20716+
# End of 10.7 tests

mysql-test/main/derived_cond_pushdown.test

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3944,3 +3944,24 @@ drop view v1;
39443944
drop table t1;
39453945

39463946
--echo # End of 10.4 tests
3947+
3948+
--echo #
3949+
--echo # MDEV-28958: condition pushable into view after simplification
3950+
--echo # contains constant TRUE/FALSE as subformula
3951+
--echo #
3952+
3953+
create table t1 (c1 int);
3954+
insert into t1 values (3), (7), (1), (3), (1), (3);
3955+
3956+
create table t2 (c2 int);
3957+
insert into t2 values (3), (5), (7), (3);
3958+
3959+
create view v1 as select * from t1 group by c1;
3960+
create view v2 as select c1 as a, c2 as b from v1,t2 where c1=c2;
3961+
3962+
select * from v2 group by a,b having a=b or b > a+10;
3963+
3964+
drop view v1,v2;
3965+
drop table t1,t2;
3966+
3967+
--echo # End of 10.7 tests

sql/item.h

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2687,18 +2687,27 @@ class Item :public Value_source,
26872687
void register_in(THD *thd);
26882688

26892689
bool depends_only_on(table_map view_map)
2690-
{ return marker & MARKER_FULL_EXTRACTION; }
2691-
int get_extraction_flag() const
2692-
{ return marker & MARKER_EXTRACTION_MASK; }
2690+
{ return get_extraction_flag() & MARKER_FULL_EXTRACTION; }
2691+
int get_extraction_flag() const
2692+
{
2693+
if (basic_const_item())
2694+
return MARKER_FULL_EXTRACTION;
2695+
else
2696+
return marker & MARKER_EXTRACTION_MASK;
2697+
}
26932698
void set_extraction_flag(int16 flags)
26942699
{
2695-
marker &= ~MARKER_EXTRACTION_MASK;
2696-
marker|= flags;
2700+
if (!basic_const_item())
2701+
{
2702+
marker= marker & ~MARKER_EXTRACTION_MASK;
2703+
marker|= flags;
2704+
}
26972705
}
26982706
void clear_extraction_flag()
26992707
{
2700-
marker &= ~MARKER_EXTRACTION_MASK;
2701-
}
2708+
if (!basic_const_item())
2709+
marker= marker & ~MARKER_EXTRACTION_MASK;
2710+
}
27022711
void check_pushable_cond(Pushdown_checker excl_dep_func, uchar *arg);
27032712
bool pushable_cond_checker_for_derived(uchar *arg)
27042713
{

0 commit comments

Comments
 (0)