Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-4392

The operation of checking types equal ignoring null can be more efficient

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.27.0
    • Component/s: core

      Description

      Method {{SqlTypeUtil#equalSansNullability(RelDataTypeFactory, RelDataType, RelDataType) is on the hot path for many scenarios, as it compare types with nullability ignored.

      In the implementation, the expensive operations are RelDataType#equals(Object) and RelDataTypeFactory#createTypeWithNullability, especially for types with multiple sub-fields.

      For the current implementation, the RelDataType#equals(Object) is called at least once, and RelDataTypeFactory#createTypeWithNullability is called whenever the nullability values are different.

      We can improve the implementation so that RelDataType#equals(Object) is called exactly once, and the call to RelDataTypeFactory#createTypeWithNullability can be avoided if the types are totally different (with different type names, and nullability values)

      if (type1.isNullable() == type2.isNullable()) {
        return type1.equals(type2);
      } else {
        return type1.equals(
              factory.createTypeWithNullability(type2, type1.isNullable()));
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                fan_li_ya Liya Fan
                Reporter:
                fan_li_ya Liya Fan
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 2h 20m
                  2h 20m