Bug #101108 | incorrect derived_merge optimization | ||
---|---|---|---|
Submitted: | 9 Oct 2020 18:11 | Modified: | 19 Oct 2021 12:01 |
Reporter: | Александр Ммммммм | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: DML | Severity: | S2 (Serious) |
Version: | 8.0.27 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[9 Oct 2020 18:11]
Александр Ммммммм
[9 Oct 2020 20:15]
MySQL Verification Team
Thank you for the bug report.
[19 Oct 2021 12:01]
Александр Ммммммм
https://github.com/mysql/mysql-server/blob/da7a1870abe131923ed003e0e9747d2de75a41e5/sql/it... bool Item_field::check_column_from_derived_table(uchar *arg) { TABLE_LIST *tl = pointer_cast<TABLE_LIST *>(arg); if (field->table == tl->table) { // If the expression in the derived table for this column has a subquery // or contains parameters or has non-deterministic result, condition is // not pushed down. // Expressions having subqueries need a more complicated replacement // strategy than the one that currently exists when the condition is // moved to derived table. // Expression having parameters when cloned as part of replacement have // problems to locate the original "?" and therefore will not be able to // get the value. TODO: Lift these two limitations. // Any condition with expressions having non-deterministic result in the // underlying derived table should not be pushed. // For ex: // select * from (select rand() as a from t1) where a >0.5; // Here a > 0.5 if pushed down would result in rand() getting evaluated // twice because the query would then be // select * from (select rand() as a from t1 where rand() > 0.5) which // is not correct. See also Item_func::check_column_from_derived_table Item *item = tl->get_derived_expr(field->field_index()); return (item->has_subquery() || (item->used_tables() & (INNER_TABLE_BIT | RAND_TABLE_BIT))); } return true; }