Skip to content

Commit

Permalink
MDEV-35276 Assertion failure in find_producing_item upon a query from…
Browse files Browse the repository at this point in the history
… a view

Two problem solved:

1) Item_default_value makes a shallow copy so the copy
 should not delete field belong to the Item

2) Item_default_value should not inherit
 derived_field_transformer_for_having and
 derived_field_transformer_for_where (in this variant
 pushing DEFAULT(f) is prohibited (return NULL) but
 if return "this" it will be allowed (should go with
 a lot of tests))
  • Loading branch information
sanja-byelkin committed Oct 29, 2024
1 parent 953f847 commit 6aa47fa
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 5 deletions.
27 changes: 27 additions & 0 deletions mysql-test/main/derived_cond_pushdown.result
Original file line number Diff line number Diff line change
Expand Up @@ -19051,4 +19051,31 @@ EXPLAIN
}
}
drop table t1, t2;
#
# MDEV-35276: Assertion failure in find_producing_item upon a query
# from a view
#
# Note: for all followng queries with DEFAULT(f) hishdown is
# prohibited
CREATE VIEW v AS select 0 AS f;
SELECT * FROM v WHERE f = DEFAULT(f);
f
0
CREATE TABLE t1 (c int DEFAULT 0);
insert into t1 values (0), (1);
SELECT * FROM v,t1 WHERE f = DEFAULT(c);
f c
0 0
0 1
ALTER TABLE t1 ALTER c SET DEFAULT 1;
SELECT * FROM v,t1 WHERE f = DEFAULT(c);
f c
drop table t1;
create table t1 (a int, c int DEFAULT a);
insert into t1 values (0, -1), (1, -2);
SELECT * FROM v,t1 WHERE f = DEFAULT(c);
f a c
0 0 -1
DROP VIEW v;
DROP TABLE t1;
# End of 10.5 tests
30 changes: 30 additions & 0 deletions mysql-test/main/derived_cond_pushdown.test
Original file line number Diff line number Diff line change
Expand Up @@ -4188,4 +4188,34 @@ execute stmt;

drop table t1, t2;

--echo #
--echo # MDEV-35276: Assertion failure in find_producing_item upon a query
--echo # from a view
--echo #
--echo # Note: for all followng queries with DEFAULT(f) hishdown is
--echo # prohibited

CREATE VIEW v AS select 0 AS f;

SELECT * FROM v WHERE f = DEFAULT(f);

CREATE TABLE t1 (c int DEFAULT 0);
insert into t1 values (0), (1);

SELECT * FROM v,t1 WHERE f = DEFAULT(c);

ALTER TABLE t1 ALTER c SET DEFAULT 1;

SELECT * FROM v,t1 WHERE f = DEFAULT(c);

drop table t1;
create table t1 (a int, c int DEFAULT a);
insert into t1 values (0, -1), (1, -2);

SELECT * FROM v,t1 WHERE f = DEFAULT(c);

DROP VIEW v;
DROP TABLE t1;


--echo # End of 10.5 tests
3 changes: 2 additions & 1 deletion sql/item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9659,7 +9659,8 @@ bool Item_default_value::fix_fields(THD *thd, Item **items)

void Item_default_value::cleanup()
{
delete field; // Free cached blob data
if (!m_share_field)
delete field; // Free cached blob data
Item_field::cleanup();
}

Expand Down
23 changes: 19 additions & 4 deletions sql/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -6646,16 +6646,21 @@ class Cached_item_field :public Cached_item

class Item_default_value : public Item_field
{
bool vcol_assignment_ok;
bool m_associated= false;
bool vcol_assignment_ok:1;
bool m_associated:1;
bool m_share_field:1;

void calculate();
public:
Item *arg= nullptr;
Item_default_value(THD *thd, Name_resolution_context *context_arg, Item *a,
bool vcol_assignment_arg)
: Item_field(thd, context_arg),
vcol_assignment_ok(vcol_assignment_arg), arg(a) {}
vcol_assignment_ok(vcol_assignment_arg), arg(a)
{
m_associated= false;
m_share_field= false;
}
Type type() const override { return DEFAULT_VALUE_ITEM; }
bool eq(const Item *item, bool binary_cmp) const override;
bool fix_fields(THD *, Item **) override;
Expand Down Expand Up @@ -6717,6 +6722,10 @@ class Item_default_value : public Item_field

Item *transform(THD *thd, Item_transformer transformer, uchar *args)
override;
Item *derived_field_transformer_for_having(THD *thd, uchar *arg) override
{ return NULL; }
Item *derived_field_transformer_for_where(THD *thd, uchar *arg) override
{ return NULL; }
Field *create_tmp_field_ex(MEM_ROOT *root, TABLE *table, Tmp_field_src *src,
const Tmp_field_param *param) override;

Expand All @@ -6726,7 +6735,13 @@ class Item_default_value : public Item_field
*/
bool associate_with_target_field(THD *thd, Item_field *field) override;
Item *do_get_copy(THD *thd) const override
{ return get_item_copy<Item_default_value>(thd, this); }
{
Item_default_value *new_item=
(Item_default_value *) get_item_copy<Item_default_value>(thd, this);
// This is a copy so do not manage the field and should not delete it
new_item->m_share_field= 1;
return new_item;
}
Item* do_build_clone(THD *thd) const override { return get_copy(thd); }
private:
bool tie_field(THD *thd);
Expand Down

0 comments on commit 6aa47fa

Please sign in to comment.