summaryrefslogtreecommitdiff
path: root/sql/item.h
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2020-01-03 11:15:00 -0800
committerIgor Babaev <igor@askmonty.org>2020-01-15 12:57:19 -0800
commit1c97cd339e9513b152727f386573c8c048db0281 (patch)
treea02e0b73942f9764d345066d55babda39957b86d /sql/item.h
parent6a8a4c19e2db22573207f32a714d354f8e870df0 (diff)
downloadmariadb-git-1c97cd339e9513b152727f386573c8c048db0281.tar.gz
MDEV-21184 Assertion `used_tables_cache == 0' failed in Item_func::fix_fields
with condition_pushdown_from_having This bug could manifest itself for queries with GROUP BY and HAVING clauses when the HAVING clause was a conjunctive condition that depended exclusively on grouping fields and at least one conjunct contained an equality of the form fld=sq where fld is a grouping field and sq is a constant subquery. In this case the optimizer tries to perform a pushdown of the HAVING condition into WHERE. To construct the pushable condition the optimizer first transforms all multiple equalities in HAVING into simple equalities. This has to be done for a proper processing of the pushed conditions in WHERE. The multiple equalities at all AND/OR levels must be converted to simple equalities because any multiple equality may refer to a multiple equality at the upper level. Before this patch the conversion was performed like this: multiple_equality(x,f1,...,fn) => x=f1 and ... and x=fn. When an equality item for x=fi was constructed both the items for x and fi were cloned. If x happened to be a constant subquery that could not be cloned the conversion failed. If the conversions of multiple equalities previously performed had succeeded then the whole condition became in an inconsistent state that could cause different failures. The solution provided by the patch is: 1. to use a different conversion rule if x is a constant multiple_equality(x,f1,...,fn) => f1=x and f2=f1 and ... and fn=f1 2. not to clone x if it's a constant. Such conversions cannot fail and besides the result of the conversion preserves the equivalence of f1,...,fn that can be used for other optimizations. This patch also made sure that expensive predicates are not pushed from HAVING to WHERE.
Diffstat (limited to 'sql/item.h')
-rw-r--r--sql/item.h7
1 files changed, 5 insertions, 2 deletions
diff --git a/sql/item.h b/sql/item.h
index 42ad6ba35fe..990ca0ec887 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -152,8 +152,10 @@ bool mark_unsupported_function(const char *w1, const char *w2,
#define NO_EXTRACTION_FL (1 << 6)
#define FULL_EXTRACTION_FL (1 << 7)
#define DELETION_FL (1 << 8)
-#define SUBSTITUTION_FL (1 << 9)
-#define EXTRACTION_MASK (NO_EXTRACTION_FL | FULL_EXTRACTION_FL | DELETION_FL)
+#define IMMUTABLE_FL (1 << 9)
+#define SUBSTITUTION_FL (1 << 10)
+#define EXTRACTION_MASK \
+ (NO_EXTRACTION_FL | FULL_EXTRACTION_FL | DELETION_FL | IMMUTABLE_FL)
extern const char *item_empty_name;
@@ -1867,6 +1869,7 @@ public:
virtual bool cleanup_processor(void *arg);
virtual bool cleanup_excluding_fields_processor (void *arg)
{ return cleanup_processor(arg); }
+ bool cleanup_excluding_immutables_processor (void *arg);
virtual bool cleanup_excluding_const_fields_processor (void *arg)
{ return cleanup_processor(arg); }
virtual bool collect_item_field_processor(void *arg) { return 0; }