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

Timestamp conversion performance can be improved

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Reopened
    • Major
    • Resolution: Unresolved
    • 1.19.0
    • None
    • core

    Description

      RexSimplify.simplifyCast() is slow when converting a string to SQL Timestamp value. The slowness is caused by this line:

      executor.reduce(rexBuilder, ImmutableList.of(e), reducedValues);
      

      Debugging this code line with my team showed that for timestamp conversion it loads a pre-compiled conversion code, which makes it slow. My team proposes to replace this line with the following code that greately improves performance:

      if (typeName == SqlTypeName.CHAR && e.getType().getSqlTypeName() == SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE) {
          if (literal.getValue() instanceof NlsString) {
              String timestampStr = ((NlsString) literal.getValue()).getValue();
              Long timestampLong = SqlFunctions.toTimestampWithLocalTimeZone(timestampStr);
              reducedValues.add(rexBuilder.makeLiteral(timestampLong, e.getType(), true));
          }
      }
      
      if (reducedValues.isEmpty()) {
          executor.reduce(rexBuilder, ImmutableList.of(e), reducedValues);
      }
      

      Let us know if we can submit a pull request with this code change or if we've missed anything. Do you know the reason behind using a pre-compiled code for timestamp conversion?

      Attachments

        1. Current.txt
          32 kB
          Valeriy Trofimov
        2. Proposed.txt
          25 kB
          Valeriy Trofimov

        Issue Links

          Activity

            People

              Unassigned Unassigned
              ValTrofFuture Valeriy Trofimov
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - 24h
                  24h
                  Remaining:
                  Remaining Estimate - 24h
                  24h
                  Logged:
                  Time Spent - Not Specified
                  Not Specified