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

Add Digest interface to enable efficient hashCode(equals) for RexNode and RelNode

    XMLWordPrintableJSON

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.21.0
    • Fix Version/s: 1.24.0
    • Component/s: core
    • Labels:
      None

      Description

      Current digests for RexNode, RelNode, RelType, and similar cases use String concatenation.

      It is easy to implement, however, it has drawbacks:
      1) String objects cannot be reused. For instance, RexCall has operands, however, the digest is duplicated. It causes extra memory use and extra CPU for string copying
      2) There's no way to have multiple #toString() methods. RelType might need multiple digests: "including field names", "excluding field names".

      A suggested resolution might be behind the lines of

      class Digest { // immutable
        final int hashCode; // speedup hashCode and equals
        final Object[] contents; // The values are either other Digest objects or Strings
        String toString(); // e.g. for debugging purposes
        int compareTo(Digest); // e.g. for debugging purposes.
      }
      

      Note how fields in Kotlin are aligned much better, and it makes it easier to read:

      class Digest { // immutable
        val hashCode: Int // speedup hashCode and equals
        val contents: Array<Any> // The values are either other Digest objects or Strings
        fun toString(): String // e.g. for debugging purposes
        fun compareTo(other: Digest): Int // e.g. for debugging purposes.
      }
      

      Then the digest for RexCall could be the bits relevant to RexCall itself + digests of the operands (which can be reused as is)

        Attachments

        1. screenshot-1.png
          114 kB
          Haisheng Yuan
        2. screenshot-2.png
          71 kB
          Haisheng Yuan
        3. screenshot-3.png
          99 kB
          Haisheng Yuan
        4. screenshot-4.png
          109 kB
          Haisheng Yuan
        5. screenshot-5.png
          96 kB
          Haisheng Yuan
        6. screenshot-6.png
          142 kB
          Haisheng Yuan
        7. image-2020-06-23-12-47-25-599.png
          142 kB
          Haisheng Yuan

          Activity

            People

            • Assignee:
              danny0405 Danny Chen
              Reporter:
              vladimirsitnikov Vladimir Sitnikov
            • Votes:
              0 Vote for this issue
              Watchers:
              14 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 - 9h 40m
                9h 40m