[Commits] fabdfa991d6: MDEV-16057: Using optimization Splitting with Group BY we see an unnecessary attached condition

Varun varunraiko1803 at gmail.com
Mon Apr 30 10:48:32 EEST 2018


revision-id: fabdfa991d6d36a97bd7f7f6606dad4a4dbe1372 (mariadb-10.3.0-860-gfabdfa991d6)
parent(s): 9b1313e8493909cdb7953607cfe1e85d3276937f
author: Varun Gupta
committer: Varun Gupta
timestamp: 2018-04-30 13:05:01 +0530
message:

MDEV-16057: Using optimization Splitting with Group BY we see an unnecessary attached condition
            t1.pk IS NOT NULL where pk is a PRIMARY KEY

For equalites in the WHERE clause we create a keyuse array that contains the set of all equalities.
For each KEYUSE inside the keyuse array we have a field "null_rejecting"
which tells that the equality will not hold if either the left or right
hand side of the equality is NULL.
If the equality is NULL rejecting then we accordingly add a NOT NULL condition for the field present in
the item val(present in the KEYUSE struct) when we are doing ref access.

For the optimization of splitting with GROUP BY we always set the null_rejecting to TRUE and we are doing ref access on
the GROUP by field. This does create a problem when the equality is NOT NULL rejecting. This happens in this case as
in the equality we have the right hand side as t1.pk where pk is a PRIMARY KEY , hence it is NOT NULLABLE. So we should have
null rejecting set to FALSE for such a case.

---
 mysql-test/main/derived_cond_pushdown.result | 1 -
 sql/opt_split.cc                             | 9 ++++++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/mysql-test/main/derived_cond_pushdown.result b/mysql-test/main/derived_cond_pushdown.result
index 82f621c73a2..5a496d2bd4e 100644
--- a/mysql-test/main/derived_cond_pushdown.result
+++ b/mysql-test/main/derived_cond_pushdown.result
@@ -15071,7 +15071,6 @@ EXPLAIN
       "materialized": {
         "query_block": {
           "select_id": 2,
-          "outer_ref_condition": "t1.pk1 is not null",
           "table": {
             "table_name": "t2",
             "access_type": "eq_ref",
diff --git a/sql/opt_split.cc b/sql/opt_split.cc
index b81556e56a2..37853bdbbe9 100644
--- a/sql/opt_split.cc
+++ b/sql/opt_split.cc
@@ -544,7 +544,14 @@ void TABLE::add_splitting_info_for_key_field(KEY_FIELD *key_field)
   added_key_field->level= 0;
   added_key_field->optimize= KEY_OPTIMIZE_EQ;
   added_key_field->eq_func= true;
-  added_key_field->null_rejecting= true;
+
+  Item *real= key_field->val->real_item();
+  if ((real->type() == Item::FIELD_ITEM) &&
+        ((Item_field*)real)->field->maybe_null())
+    added_key_field->null_rejecting= true;
+  else
+    added_key_field->null_rejecting= false;
+
   added_key_field->cond_guard= NULL;
   added_key_field->sj_pred_no= UINT_MAX;
   return;


More information about the commits mailing list