• Oleg Smirnov's avatar
    MDEV-34665 Simplify IN predicate processing for NULL-aware materialization... · 702b6073
    Oleg Smirnov authored
    MDEV-34665 Simplify IN predicate processing for NULL-aware materialization involving only one column
    
    It was found that unnecessary work of building Ordered_key structures
    is being done when processing NULL-aware materialization for IN predicates
    having only one column. In fact, the logic for that simplified case can be
    expressed as follows.
    Say we have predicate left_expr IN (SELECT <subq1>), where left_expr is
    scalar(not a tuple).
    Then
        if (left_expr is NULL) {
          if (subq1 produced any rows) {
            // note that we don't care if subq1 has produced
            // NULLs or not.
            NULL IN (<some values>) -> UNKNOWN, i.e. NULL.
          } else {
            NULL IN ({empty-set}) -> FALSE.
          }
        } else {
          // left_expr is a non-NULL value
          if (subq1 output has a match for left_expr) {
            left_expr IN (..., left_expr ...) -> TRUE
          } else {
            // no "known" matches.
            if (subq1 output has a NULL) {
              left_expr IN ( ... NULL ...) ->
               (NULL could have been a match or not)
               -> NULL.
            } else {
              // subq1 didn't produce any "UNKNOWNs" so
              // we're positive there weren't any matches
              -> FALSE.
            }
          }
        }
    
    This commit introduces subselect_single_column_partial_engine class
    implementing the logic described.
    702b6073
subselect_mat_analyze_json.test 3.25 KB